Skip to content

Commit

Permalink
Refactored common code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgimeno committed Jan 10, 2012
1 parent 646d0f1 commit be1cc28
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/okasaki/batched_deque.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
[[Quad 0 Nil 0 Nil]] true
:else false)

(defun checkf
(defn- split-and-reverse-bottom
[n l]
(let [ntop (quot n 2)
nbottom (- n ntop)
[top rbottom] (split-at ntop l)
bottom (rev rbottom)]
[ntop top nbottom bottom]))

(defun ^:private checkf
[queue]
[[Quad 0 Nil cr r]] (if (> cr 1)
(let [nnr (quot cr 2)
nnf (- cr nnr)
[nr rnf] (split-at nnr r)
nf (rev rnf)]
(->Quad nnf nf nnr nr))
(let [[cnr nr cnf nf] (split-and-reverse-bottom cr r)]
(->Quad cnf nf cnr nr))
queue)
[[Quad cf f 0 Nil]] (if (> cf 1)
(let [nnf (quot cf 2)
nnr (- cf nnf)
[nf rnr] (split-at nnf f)
nr (rev rnr)]
(->Quad nnf nf nnr nr))
(let [[cnf nf cnr nr] (split-and-reverse-bottom cf f)]
(->Quad cnf nf cnr nr))
queue)
:else queue)

Expand Down

0 comments on commit be1cc28

Please sign in to comment.