Skip to content

Commit

Permalink
Fixed BTSet implementation of IReduceInit (closes #124)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jan 11, 2016
1 parent fba9493 commit 668c355
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- Lookups with nil value (`[<attr> nil]`) resolve to nil (#140)
- Allow pull-pattern to be specified with a input variable without `?` prefix (#136, #122)
- Retract functions do not fail if lookup ref is pointing nowhere (#131)
- Fixed BTSet implementation of IReduceInit (#124)

# 0.13.3

Expand Down
15 changes: 8 additions & 7 deletions src/datascript/btset.cljc
Expand Up @@ -819,16 +819,17 @@
keys (.-keys iter)
idx (.-idx iter)
acc start]
(cond
(reduced? acc) @acc
(nil? keys) acc
:else
(let [new-acc (f acc (da/aget keys idx))]
(if (< (inc idx) (da/alength keys))
;; can use cached array to move forward
(if (nil? keys)
acc
(let [new-acc (f acc (da/aget keys idx))]
(cond
(reduced? new-acc)
@new-acc
(< (inc idx) (da/alength keys)) ;; can use cached array to move forward
(if (< (inc left) right)
(recur (inc left) keys (inc idx) new-acc)
new-acc)
:else
(let [new-left (next-path set left)]
(if (and (not== -1 new-left) (< new-left right))
(recur new-left (keys-for set new-left) (path-get new-left 0) new-acc)
Expand Down
2 changes: 2 additions & 0 deletions test/datascript/test/btset.cljc
Expand Up @@ -98,5 +98,7 @@
)))))
#_(println "[ OK ] btset slice checked"))

(deftest test-reduced
(is (= [1 2] (into [] (take 2) (btset 1 2)))))

;; (t/test-ns 'datascript.test.btset)

0 comments on commit 668c355

Please sign in to comment.