datascript
datascript copied to clipboard
Implement ICounted for Iter
An efficient count could allow other optimizations in datascript.
Currently a count on an Iter iterates manually through the sequence which is slow.
A pretty fast one is:
(defn iter-count
"Fast counting of btset Iter (from datoms)"
[iter]
(loop [cnt 0, iter iter]
(if iter
(recur (+ cnt (-count (btset/iter-chunk iter))) (btset/iter-chunked-next iter))
cnt)))
which uses the chunking. A similar and even faster -count should be implemented in btset. This is probably an easy one for outsiders.
Also: Implemented bounded-count for an Iter.