Skip to content

Commit 930fbef

Browse files
committed
update HashMap and Set
1 parent 85a3620 commit 930fbef

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12481,9 +12481,15 @@ reduces them without incurring seq initialization"
1248112481
; hashobj. Each values in hashobj is actually a bucket in order to handle hash
1248212482
; collisions. A bucket is an array of alternating keys (not their hashes) and
1248312483
; vals.
12484-
(deftype HashMap [meta count hashobj]
12484+
(deftype HashMap [meta count hashobj ^:mutable __hash]
12485+
Object
12486+
(toString [coll]
12487+
(pr-str* coll))
12488+
(equiv [this other]
12489+
(-equiv this other))
12490+
1248512491
IWithMeta
12486-
(-with-meta [coll meta] (HashMap. meta count hashobj))
12492+
(-with-meta [coll meta] (HashMap. meta count hashobj __hash))
1248712493

1248812494
IMeta
1248912495
(-meta [coll] meta)
@@ -12503,7 +12509,7 @@ reduces them without incurring seq initialization"
1250312509
(-equiv [coll other] (equiv-map coll other))
1250412510

1250512511
IHash
12506-
(-hash [coll] (hash-coll coll))
12512+
(-hash [coll] (caching-hash coll hash-unordered-coll __hash))
1250712513

1250812514
ISeqable
1250912515
(-seq [coll]
@@ -12535,13 +12541,13 @@ reduces them without incurring seq initialization"
1253512541
(if-let [i (scan-array 2 k new-bucket)]
1253612542
(do ; found key, replace
1253712543
(aset new-bucket (inc i) v)
12538-
(HashMap. meta count new-hashobj))
12544+
(HashMap. meta count new-hashobj nil))
1253912545
(do ; did not find key, append
1254012546
(.push new-bucket k v)
12541-
(HashMap. meta (inc count) new-hashobj))))
12547+
(HashMap. meta (inc count) new-hashobj nil))))
1254212548
(let [new-hashobj (goog.object/clone hashobj)] ; did not find bucket
1254312549
(aset new-hashobj h (array k v))
12544-
(HashMap. meta (inc count) new-hashobj)))))
12550+
(HashMap. meta (inc count) new-hashobj nil)))))
1254512551
(-contains-key? [coll k]
1254612552
(let [bucket (aget hashobj (hash k))
1254712553
i (when bucket (scan-array 2 k bucket))]
@@ -12562,7 +12568,7 @@ reduces them without incurring seq initialization"
1256212568
(let [new-bucket (aclone bucket)]
1256312569
(.splice new-bucket i 2)
1256412570
(aset new-hashobj h new-bucket)))
12565-
(HashMap. meta (dec count) new-hashobj)))))
12571+
(HashMap. meta (dec count) new-hashobj nil)))))
1256612572

1256712573
IFn
1256812574
(-invoke [coll k]
@@ -12574,7 +12580,7 @@ reduces them without incurring seq initialization"
1257412580
(-pr-writer [coll writer opts]
1257512581
(print-map coll pr-writer writer opts)))
1257612582

12577-
(set! (. HashMap -EMPTY) (HashMap. nil 0 (js-obj)))
12583+
(set! (. HashMap -EMPTY) (HashMap. nil 0 (js-obj) empty-unordered-hash))
1257812584

1257912585
(set! (. HashMap -fromArrays) (fn [ks vs]
1258012586
(let [len (.-length ks)]
@@ -12592,16 +12598,22 @@ reduces them without incurring seq initialization"
1259212598
(recur (nnext in) (assoc out (first in) (second in)))
1259312599
out)))
1259412600

12595-
(deftype Set [meta hash-map]
12601+
(deftype Set [meta hash-map ^:mutable __hash]
12602+
Object
12603+
(toString [coll]
12604+
(pr-str* coll))
12605+
(equiv [this other]
12606+
(-equiv this other))
12607+
1259612608
IWithMeta
12597-
(-with-meta [coll meta] (Set. meta hash-map))
12609+
(-with-meta [coll meta] (Set. meta hash-map __hash))
1259812610

1259912611
IMeta
1260012612
(-meta [coll] meta)
1260112613

1260212614
ICollection
1260312615
(-conj [coll o]
12604-
(Set. meta (assoc hash-map o nil)))
12616+
(Set. meta (assoc hash-map o nil) nil))
1260512617

1260612618
IEmptyableCollection
1260712619
(-empty [coll] (with-meta (. Set -EMPTY) meta))
@@ -12615,7 +12627,7 @@ reduces them without incurring seq initialization"
1261512627
other)))
1261612628

1261712629
IHash
12618-
(-hash [coll] (hash-coll coll))
12630+
(-hash [coll] (caching-hash coll hash-unordered-coll __hash))
1261912631

1262012632
ISeqable
1262112633
(-seq [coll] (keys hash-map))
@@ -12633,7 +12645,7 @@ reduces them without incurring seq initialization"
1263312645

1263412646
ISet
1263512647
(-disjoin [coll v]
12636-
(Set. meta (dissoc hash-map v)))
12648+
(Set. meta (dissoc hash-map v) nil))
1263712649

1263812650
IFn
1263912651
(-invoke [coll k]
@@ -12644,4 +12656,4 @@ reduces them without incurring seq initialization"
1264412656
IPrintWithWriter
1264512657
(-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll)))
1264612658

12647-
(set! (. Set -EMPTY) (Set. nil (hash-map)))
12659+
(set! (. Set -EMPTY) (Set. nil (hash-map) empty-unordered-hash))

0 commit comments

Comments
 (0)