datascript icon indicating copy to clipboard operation
datascript copied to clipboard

Implement ICounted for Iter

Open rauhs opened this issue 8 years ago • 1 comments

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.

rauhs avatar Jun 07 '17 11:06 rauhs

Also: Implemented bounded-count for an Iter.

rauhs avatar Jun 07 '17 19:06 rauhs