@@ -6561,163 +6561,6 @@ reduces them without incurring seq initialization"
65616561 i
65626562 (recur (+ i incr)))))))
65636563
6564- ; The keys field is an array of all keys of this map, in no particular
6565- ; order. Any string, keyword, or symbol key is used as a property name
6566- ; to store the value in strobj. If a key is assoc'ed when that same
6567- ; key already exists in strobj, the old value is overwritten. If a
6568- ; non-string key is assoc'ed, return a HashMap object instead.
6569-
6570- (defn- obj-map-compare-keys [a b]
6571- (let [a (hash a)
6572- b (hash b)]
6573- (cond
6574- (< a b) -1
6575- (> a b) 1
6576- :else 0 )))
6577-
6578- (defn- obj-map->hash-map [m k v]
6579- (let [ks (.-keys m)
6580- len (alength ks)
6581- so (.-strobj m)
6582- mm (meta m)]
6583- (loop [i 0
6584- out (transient (.-EMPTY PersistentHashMap))]
6585- (if (< i len)
6586- (let [k (aget ks i)]
6587- (recur (inc i) (assoc! out k (gobject/get so k))))
6588- (-with-meta (persistent! (assoc! out k v)) mm)))))
6589-
6590- ; ;; ObjMap - DEPRECATED
6591-
6592- (defn- obj-clone [obj ks]
6593- (let [new-obj (js-obj )
6594- l (alength ks)]
6595- (loop [i 0 ]
6596- (when (< i l)
6597- (let [k (aget ks i)]
6598- (gobject/set new-obj k (gobject/get obj k))
6599- (recur (inc i)))))
6600- new-obj))
6601-
6602- (deftype ObjMap [meta keys strobj update-count ^:mutable __hash]
6603- Object
6604- (toString [coll]
6605- (pr-str* coll))
6606- (equiv [this other]
6607- (-equiv this other))
6608-
6609- IWithMeta
6610- (-with-meta [coll new-meta]
6611- (if (identical? new-meta meta)
6612- coll
6613- (ObjMap. new-meta keys strobj update-count __hash)))
6614-
6615- IMeta
6616- (-meta [coll] meta)
6617-
6618- ICollection
6619- (-conj [coll entry]
6620- (if (vector? entry)
6621- (-assoc coll (-nth entry 0 ) (-nth entry 1 ))
6622- (reduce -conj
6623- coll
6624- entry)))
6625-
6626- IEmptyableCollection
6627- (-empty [coll] (-with-meta (.-EMPTY ObjMap) meta))
6628-
6629- IEquiv
6630- (-equiv [coll other] (equiv-map coll other))
6631-
6632- IHash
6633- (-hash [coll] (caching-hash coll hash-unordered-coll __hash))
6634-
6635- ISeqable
6636- (-seq [coll]
6637- (when (pos? (alength keys))
6638- (map #(vector % (unchecked-get strobj %))
6639- (.sort keys obj-map-compare-keys))))
6640-
6641- ICounted
6642- (-count [coll] (alength keys))
6643-
6644- ILookup
6645- (-lookup [coll k] (-lookup coll k nil ))
6646- (-lookup [coll k not-found]
6647- (if (and (string? k)
6648- (not (nil? (scan-array 1 k keys))))
6649- (unchecked-get strobj k)
6650- not-found))
6651-
6652- IAssociative
6653- (-assoc [coll k v]
6654- (if (string? k)
6655- (if (or (> update-count (.-HASHMAP_THRESHOLD ObjMap))
6656- (>= (alength keys) (.-HASHMAP_THRESHOLD ObjMap)))
6657- (obj-map->hash-map coll k v)
6658- (if-not (nil? (scan-array 1 k keys))
6659- (let [new-strobj (obj-clone strobj keys)]
6660- (gobject/set new-strobj k v)
6661- (ObjMap. meta keys new-strobj (inc update-count) nil )) ; overwrite
6662- (let [new-strobj (obj-clone strobj keys) ; append
6663- new-keys (aclone keys)]
6664- (gobject/set new-strobj k v)
6665- (.push new-keys k)
6666- (ObjMap. meta new-keys new-strobj (inc update-count) nil ))))
6667- ; ; non-string key. game over.
6668- (obj-map->hash-map coll k v)))
6669- (-contains-key? [coll k]
6670- (if (and (string? k)
6671- (not (nil? (scan-array 1 k keys))))
6672- true
6673- false ))
6674-
6675- IFind
6676- (-find [coll k]
6677- (when (and (string? k)
6678- (not (nil? (scan-array 1 k keys))))
6679- (MapEntry. k (unchecked-get strobj k) nil )))
6680-
6681- IKVReduce
6682- (-kv-reduce [coll f init]
6683- (let [len (alength keys)]
6684- (loop [keys (.sort keys obj-map-compare-keys)
6685- init init]
6686- (if (seq keys)
6687- (let [k (first keys)
6688- init (f init k (unchecked-get strobj k))]
6689- (if (reduced? init)
6690- @init
6691- (recur (rest keys) init)))
6692- init))))
6693-
6694- IMap
6695- (-dissoc [coll k]
6696- (if (and (string? k)
6697- (not (nil? (scan-array 1 k keys))))
6698- (let [new-keys (aclone keys)
6699- new-strobj (obj-clone strobj keys)]
6700- (.splice new-keys (scan-array 1 k new-keys) 1 )
6701- (js-delete new-strobj k)
6702- (ObjMap. meta new-keys new-strobj (inc update-count) nil ))
6703- coll)) ; key not found, return coll unchanged
6704-
6705- IFn
6706- (-invoke [coll k]
6707- (-lookup coll k))
6708- (-invoke [coll k not-found]
6709- (-lookup coll k not-found))
6710-
6711- IEditableCollection
6712- (-as-transient [coll]
6713- (transient (into (hash-map ) coll))))
6714-
6715- (set! (.-EMPTY ObjMap) (ObjMap. nil (array ) (js-obj ) 0 empty-unordered-hash))
6716-
6717- (set! (.-HASHMAP_THRESHOLD ObjMap) 8 )
6718-
6719- (set! (.-fromObject ObjMap) (fn [ks obj] (ObjMap. nil ks obj 0 nil )))
6720-
67216564; ; Record Iterator
67226565(deftype RecordIter [^:mutable i record base-count fields ext-map-iter]
67236566 Object
@@ -9191,19 +9034,6 @@ reduces them without incurring seq initialization"
91919034 (.createAsIfByAssoc PersistentArrayMap (to-array s))
91929035 (if (seq s) (first s) (.-EMPTY PersistentArrayMap))))
91939036
9194- (defn obj-map
9195- " keyval => key val
9196- Returns a new object map with supplied mappings."
9197- [& keyvals]
9198- (let [ks (array )
9199- obj (js-obj )]
9200- (loop [kvs (seq keyvals)]
9201- (if kvs
9202- (do (.push ks (first kvs))
9203- (gobject/set obj (first kvs) (second kvs))
9204- (recur (nnext kvs)))
9205- (.fromObject ObjMap ks obj)))))
9206-
92079037(defn sorted-map
92089038 " keyval => key val
92099039 Returns a new sorted map with supplied mappings."
@@ -10855,10 +10685,6 @@ reduces them without incurring seq initialization"
1085510685 MapEntry
1085610686 (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " [" " " " ]" opts coll))
1085710687
10858- ObjMap
10859- (-pr-writer [coll writer opts]
10860- (print-map coll pr-writer writer opts))
10861-
1086210688 KeySeq
1086310689 (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
1086410690
@@ -12502,14 +12328,6 @@ reduces them without incurring seq initialization"
1250212328; key already exists in strobj, the old value is overwritten. If a
1250312329; non-string key is assoc'ed, return a HashMap object instead.
1250412330
12505- (defn- obj-map-contains-key?
12506- ([k strobj]
12507- (obj-map-contains-key? k strobj true false ))
12508- ([k strobj true -val false -val]
12509- (if (and (goog/isString k) (.hasOwnProperty strobj k))
12510- true -val
12511- false -val)))
12512-
1251312331(defn- obj-map-compare-keys [a b]
1251412332 (let [a (hash a)
1251512333 b (hash b)]
@@ -12518,7 +12336,25 @@ reduces them without incurring seq initialization"
1251812336 (> a b) 1
1251912337 :else 0 )))
1252012338
12521- (deftype ObjMap [meta keys strobj]
12339+ (defn- obj-clone [obj ks]
12340+ (let [new-obj (js-obj )
12341+ l (alength ks)]
12342+ (loop [i 0 ]
12343+ (when (< i l)
12344+ (let [k (aget ks i)]
12345+ (gobject/set new-obj k (gobject/get obj k))
12346+ (recur (inc i)))))
12347+ new-obj))
12348+
12349+ (declare simple-hash-map )
12350+
12351+ (deftype ObjMap [meta keys strobj ^:mutable __hash]
12352+ Object
12353+ (toString [coll]
12354+ (pr-str* coll))
12355+ (equiv [this other]
12356+ (-equiv this other))
12357+
1252212358 IWithMeta
1252312359 (-with-meta [coll meta] (ObjMap. meta keys strobj))
1252412360
@@ -12540,46 +12376,73 @@ reduces them without incurring seq initialization"
1254012376 (-equiv [coll other] (equiv-map coll other))
1254112377
1254212378 IHash
12543- (-hash [coll] (hash- coll coll))
12379+ (-hash [coll] (caching-hash coll hash-unordered- coll __hash ))
1254412380
1254512381 ISeqable
1254612382 (-seq [coll]
12547- (when (pos? (.-length keys))
12548- (map #(vector % (aget strobj %))
12383+ (when (pos? (alength keys))
12384+ (map #(vector % (unchecked-get strobj %))
1254912385 (.sort keys obj-map-compare-keys))))
1255012386
1255112387 ICounted
12552- (-count [coll] (.-length keys))
12388+ (-count [coll] (alength keys))
1255312389
1255412390 ILookup
1255512391 (-lookup [coll k] (-lookup coll k nil ))
1255612392 (-lookup [coll k not-found]
12557- (obj-map-contains-key? k strobj (aget strobj k) not-found))
12393+ (if (and (string? k)
12394+ (not (nil? (scan-array 1 k keys))))
12395+ (unchecked-get strobj k)
12396+ not-found))
1255812397
1255912398 IAssociative
1256012399 (-assoc [coll k v]
12561- (if (goog/isString k)
12562- (let [new-strobj (goog.object/clone strobj)
12563- overwrite? (.hasOwnProperty new-strobj k)]
12564- (aset new-strobj k v)
12565- (if overwrite?
12566- (ObjMap. meta keys new-strobj) ; overwrite
12567- (let [new-keys (aclone keys)] ; append
12568- (.push new-keys k)
12569- (ObjMap. meta new-keys new-strobj))))
12400+ (if (string? k)
12401+ (if-not (nil? (scan-array 1 k keys))
12402+ (let [new-strobj (obj-clone strobj keys)]
12403+ (gobject/set new-strobj k v)
12404+ (ObjMap. meta keys new-strobj nil )) ; overwrite
12405+ (let [new-strobj (obj-clone strobj keys) ; append
12406+ new-keys (aclone keys)]
12407+ (gobject/set new-strobj k v)
12408+ (.push new-keys k)
12409+ (ObjMap. meta new-keys new-strobj nil )))
1257012410 ; non-string key. game over.
12571- (with-meta (into (hash-map k v) (seq coll)) meta)))
12411+ (with-meta (into (simple- hash-map k v) (seq coll)) meta)))
1257212412 (-contains-key? [coll k]
12573- (obj-map-contains-key? k strobj))
12413+ (if (and (string? k)
12414+ (not (nil? (scan-array 1 k keys))))
12415+ true
12416+ false ))
12417+
12418+ IFind
12419+ (-find [coll k]
12420+ (when (and (string? k)
12421+ (not (nil? (scan-array 1 k keys))))
12422+ (MapEntry. k (unchecked-get strobj k) nil )))
12423+
12424+ IKVReduce
12425+ (-kv-reduce [coll f init]
12426+ (let [len (alength keys)]
12427+ (loop [keys (.sort keys obj-map-compare-keys)
12428+ init init]
12429+ (if (seq keys)
12430+ (let [k (first keys)
12431+ init (f init k (unchecked-get strobj k))]
12432+ (if (reduced? init)
12433+ @init
12434+ (recur (rest keys) init)))
12435+ init))))
1257412436
1257512437 IMap
1257612438 (-dissoc [coll k]
12577- (if (and (goog/isString k) (.hasOwnProperty strobj k))
12439+ (if (and (string? k)
12440+ (not (nil? (scan-array 1 k keys))))
1257812441 (let [new-keys (aclone keys)
12579- new-strobj (goog.object/ clone strobj)]
12442+ new-strobj (obj- clone strobj keys )]
1258012443 (.splice new-keys (scan-array 1 k new-keys) 1 )
1258112444 (js-delete new-strobj k)
12582- (ObjMap. meta new-keys new-strobj))
12445+ (ObjMap. meta new-keys new-strobj nil ))
1258312446 coll)) ; key not found, return coll unchanged
1258412447
1258512448 IFn
@@ -12588,6 +12451,10 @@ reduces them without incurring seq initialization"
1258812451 (-invoke [coll k not-found]
1258912452 (-lookup coll k not-found))
1259012453
12454+ ; IEditableCollection
12455+ ; (-as-transient [coll]
12456+ ; (transient (into (simple-hash-map) coll)))
12457+
1259112458 IPrintWithWriter
1259212459 (-pr-writer [coll writer opts]
1259312460 (print-map coll pr-writer writer opts)))
@@ -12716,6 +12583,15 @@ reduces them without incurring seq initialization"
1271612583 (recur (inc i) (assoc out (aget ks i) (aget vs i)))
1271712584 out)))))
1271812585
12586+ (defn simple-hash-map
12587+ " keyval => key val
12588+ Returns a new hash map with supplied mappings."
12589+ [& keyvals]
12590+ (loop [in (seq keyvals), out (. HashMap -EMPTY)]
12591+ (if in
12592+ (recur (nnext in) (assoc out (first in) (second in)))
12593+ out)))
12594+
1271912595(deftype Set [meta hash-map]
1272012596 IWithMeta
1272112597 (-with-meta [coll meta] (Set. meta hash-map))
0 commit comments