@@ -5330,6 +5330,21 @@ reduces them without incurring seq initialization"
53305330
53315331; ;; PersistentQueue ;;;
53325332
5333+ (deftype PersistentQueueIter [^:mutable fseq riter]
5334+ Object
5335+ (hasNext [_]
5336+ (or (and (some? fseq) (seq fseq)) (and (some? riter) (.hasNext riter))))
5337+ (next [_]
5338+ (cond
5339+ (some? fseq)
5340+ (let [ret (first fseq)]
5341+ (set! fseq (next fseq))
5342+ ret)
5343+ (and (some? riter) ^boolean (.hasNext riter))
5344+ (.next riter)
5345+ :else (throw (js/Error. " No such element" ))))
5346+ (remove [_] (js/Error. " Unsupported operation" )))
5347+
53335348(deftype PersistentQueueSeq [meta front rear ^:mutable __hash]
53345349 Object
53355350 (toString [coll]
@@ -5380,6 +5395,10 @@ reduces them without incurring seq initialization"
53805395 ICloneable
53815396 (-clone [coll] (PersistentQueue. meta count front rear __hash))
53825397
5398+ IIterable
5399+ (-iterator [coll]
5400+ (PersistentQueueIter. front (-iterator rear)))
5401+
53835402 IWithMeta
53845403 (-with-meta [coll meta] (PersistentQueue. meta count front rear __hash))
53855404
@@ -5607,6 +5626,19 @@ reduces them without incurring seq initialization"
56075626
56085627(set! (.-fromObject ObjMap) (fn [ks obj] (ObjMap. nil ks obj 0 nil )))
56095628
5629+ ; ; Record Iterator
5630+ (deftype RecordIter [^:mutable i record base-count fields ext-map-iter]
5631+ Object
5632+ (hasNext [_]
5633+ (or (< i base-count) (.hasNext ext-map-iter)))
5634+ (next [_]
5635+ (if (< i base-count)
5636+ (let [k (nth fields i)]
5637+ (set! i (inc i))
5638+ [k (-lookup record k)])
5639+ (.next ext-map-iter)))
5640+ (remove [_] (js/Error. " Unsupported operation" )))
5641+
56105642; ; EXPERIMENTAL: subject to change
56115643(deftype ES6EntriesIterator [^:mutable s]
56125644 Object
@@ -6109,6 +6141,44 @@ reduces them without incurring seq initialization"
61096141
61106142(declare ArrayNode )
61116143
6144+ (deftype NodeIterator [arr ^:mutable i ^:mutable next-entry ^:mutable next-iter]
6145+ Object
6146+ (advance [this]
6147+ (let [len (alength arr)]
6148+ (loop []
6149+ (if (< i len)
6150+ (let [key (aget arr i)
6151+ node-or-val (aget arr (inc i))
6152+ ^boolean found
6153+ (cond (some? key)
6154+ (set! next-entry [key node-or-val])
6155+ (some? node-or-val)
6156+ (let [new-iter (-iterator node-or-val)]
6157+ (if ^boolean (.hasNext new-iter)
6158+ (set! next-iter new-iter)
6159+ false ))
6160+ :else false )]
6161+ (set! i (+ i 2 ))
6162+ (if found true (recur )))
6163+ false ))))
6164+ (hasNext [this]
6165+ (or (some? next-entry) (some? next-iter) (.advance this)))
6166+ (next [this]
6167+ (cond
6168+ (some? next-entry)
6169+ (let [ret next-entry]
6170+ (set! next-entry nil )
6171+ ret)
6172+ (some? next-iter)
6173+ (let [ret (.next next-iter)]
6174+ (when-not ^boolean (.hasNext next-iter)
6175+ (set! next-iter nil ))
6176+ ret)
6177+ ^boolean (.advance this)
6178+ (.next this)
6179+ :else (throw (js/Error. " No such element" ))))
6180+ (remove [_] (js/Error. " Unsupported operation" )))
6181+
61126182(deftype BitmapIndexedNode [edit ^:mutable bitmap ^:mutable arr]
61136183 Object
61146184 (inode-assoc [inode shift hash key val added-leaf?]
@@ -6303,7 +6373,11 @@ reduces them without incurring seq initialization"
63036373 :else inode)))))
63046374
63056375 (kv-reduce [inode f init]
6306- (inode-kv-reduce arr f init)))
6376+ (inode-kv-reduce arr f init))
6377+
6378+ IIterable
6379+ (-iterator [coll]
6380+ (NodeIterator. arr 0 nil nil )))
63076381
63086382(set! (.-EMPTY BitmapIndexedNode) (BitmapIndexedNode. nil 0 (make-array 0 )))
63096383
@@ -6320,6 +6394,26 @@ reduces them without incurring seq initialization"
63206394 (recur (inc i) j bitmap))
63216395 (BitmapIndexedNode. edit bitmap new-arr)))))
63226396
6397+ (deftype ArrayNodeIterator [arr ^:mutable i ^:mutable next-iter]
6398+ Object
6399+ (hasNext [this]
6400+ (let [len (alength arr)]
6401+ (loop []
6402+ (if-not (and (some? next-iter) ^boolean (.hasNext next-iter))
6403+ (if (< i len)
6404+ (let [node (aget arr i)]
6405+ (set! i (inc i))
6406+ (when (some? node)
6407+ (set! next-iter (-iterator node)))
6408+ (recur ))
6409+ false )
6410+ true ))))
6411+ (next [this]
6412+ (if ^boolean (.hasNext this)
6413+ (.next next-iter)
6414+ (throw (js/Error. " No such element" ))))
6415+ (remove [_] (js/Error. " Unsupported operation" )))
6416+
63236417(deftype ArrayNode [edit ^:mutable cnt ^:mutable arr]
63246418 Object
63256419 (inode-assoc [inode shift hash key val added-leaf?]
@@ -6415,7 +6509,11 @@ reduces them without incurring seq initialization"
64156509 @init
64166510 (recur (inc i) init)))
64176511 (recur (inc i) init)))
6418- init)))))
6512+ init))))
6513+
6514+ IIterable
6515+ (-iterator [coll]
6516+ (ArrayNodeIterator. arr 0 nil )))
64196517
64206518(defn- hash-collision-node-find-index [arr cnt key]
64216519 (let [lim (* 2 cnt)]
@@ -6522,7 +6620,11 @@ reduces them without incurring seq initialization"
65226620 editable))))))
65236621
65246622 (kv-reduce [inode f init]
6525- (inode-kv-reduce arr f init)))
6623+ (inode-kv-reduce arr f init))
6624+
6625+ IIterable
6626+ (-iterator [coll]
6627+ (NodeIterator. arr 0 nil nil )))
65266628
65276629(defn- create-node
65286630 ([shift key1 val1 key2hash key2 val2]
@@ -6660,6 +6762,18 @@ reduces them without incurring seq initialization"
66606762
66616763(declare TransientHashMap )
66626764
6765+ (deftype HashMapIter [nil-val root-iter ^:mutable seen]
6766+ Object
6767+ (hasNext [_]
6768+ (and ^boolean seen ^boolean (.hasNext root-iter)))
6769+ (next [_]
6770+ (if-not ^boolean seen
6771+ (do
6772+ (set! seen true )
6773+ nil-val)
6774+ (.next root-iter)))
6775+ (remove [_] (js/Error. " Unsupported operation" )))
6776+
66636777(deftype PersistentHashMap [meta cnt root ^boolean has-nil? nil-val ^:mutable __hash]
66646778 Object
66656779 (toString [coll]
@@ -6685,6 +6799,13 @@ reduces them without incurring seq initialization"
66856799 ICloneable
66866800 (-clone [_] (PersistentHashMap. meta cnt root has-nil? nil-val __hash))
66876801
6802+ IIterable
6803+ (-iterator [coll]
6804+ (let [root-iter (if ^boolean root (-iterator root) nil-iter)]
6805+ (if has-nil?
6806+ (HashMapIter. nil-val root-iter false )
6807+ root-iter)))
6808+
66886809 IWithMeta
66896810 (-with-meta [coll meta] (PersistentHashMap. meta cnt root has-nil? nil-val __hash))
66906811
@@ -7812,6 +7933,16 @@ reduces them without incurring seq initialization"
78127933
78137934(declare TransientHashSet )
78147935
7936+ (deftype HashSetIter [iter]
7937+ Object
7938+ (hasNext [_]
7939+ (.hasNext iter))
7940+ (next [_]
7941+ (if ^boolean (.hasNext iter)
7942+ (aget (.-tail (.next iter)) 0 )
7943+ (throw (js/Error. " No such element" ))))
7944+ (remove [_] (js/Error. " Unsupported operation" )))
7945+
78157946(deftype PersistentHashSet [meta hash-map ^:mutable __hash]
78167947 Object
78177948 (toString [coll]
@@ -7835,6 +7966,10 @@ reduces them without incurring seq initialization"
78357966 ICloneable
78367967 (-clone [_] (PersistentHashSet. meta hash-map __hash))
78377968
7969+ IIterable
7970+ (-iterator [coll]
7971+ (HashSetIter. (-iterator hash-map)))
7972+
78387973 IWithMeta
78397974 (-with-meta [coll meta] (PersistentHashSet. meta hash-map __hash))
78407975
0 commit comments