@@ -12243,345 +12243,3 @@ reduces them without incurring seq initialization"
12243
12243
(identical? " window" *global*) (set! goog/global js/window)
12244
12244
(identical? " self" *global*) (set! goog/global js/self)
12245
12245
(identical? " global" *global*) (set! goog/global js/global)))
12246
-
12247
- ; ; -----------------------------------------------------------------------------
12248
- ; ; Original 2011 Copy-on-Write Types
12249
-
12250
- ; ;; Vector
12251
-
12252
- (deftype Vector [meta array]
12253
- IWithMeta
12254
- (-with-meta [coll meta] (Vector. meta array))
12255
-
12256
- IMeta
12257
- (-meta [coll] meta)
12258
-
12259
- IStack
12260
- (-peek [coll]
12261
- (let [count (.-length array)]
12262
- (when (> count 0 )
12263
- (aget array (dec count)))))
12264
- (-pop [coll]
12265
- (if (> (.-length array) 0 )
12266
- (let [new-array (aclone array)]
12267
- (. new-array (pop ))
12268
- (Vector. meta new-array))
12269
- (throw (js/Error. " Can't pop empty vector" ))))
12270
-
12271
- ICollection
12272
- (-conj [coll o]
12273
- (let [new-array (aclone array)]
12274
- (.push new-array o)
12275
- (Vector. meta new-array)))
12276
-
12277
- IEmptyableCollection
12278
- (-empty [coll] (with-meta cljs.core.Vector/EMPTY meta))
12279
-
12280
- ISequential
12281
- IEquiv
12282
- (-equiv [coll other] (equiv-sequential coll other))
12283
-
12284
- IHash
12285
- (-hash [coll] (hash-coll coll))
12286
-
12287
- ISeqable
12288
- (-seq [coll]
12289
- (when (> (.-length array) 0 )
12290
- (let [vector-seq
12291
- (fn vector-seq [i]
12292
- (lazy-seq
12293
- (when (< i (.-length array))
12294
- (cons (aget array i) (vector-seq (inc i))))))]
12295
- (vector-seq 0 ))))
12296
-
12297
- ICounted
12298
- (-count [coll] (.-length array))
12299
-
12300
- IIndexed
12301
- (-nth [coll n]
12302
- (if (and (<= 0 n) (< n (.-length array)))
12303
- (aget array n)
12304
- #_(throw (js/Error. (str " No item " n " in vector of length " (.-length array))))))
12305
- (-nth [coll n not-found]
12306
- (if (and (<= 0 n) (< n (.-length array)))
12307
- (aget array n)
12308
- not-found))
12309
-
12310
- ILookup
12311
- (-lookup [coll k] (-nth coll k nil ))
12312
- (-lookup [coll k not-found] (-nth coll k not-found))
12313
-
12314
- IAssociative
12315
- (-assoc [coll k v]
12316
- (let [new-array (aclone array)]
12317
- (aset new-array k v)
12318
- (Vector. meta new-array)))
12319
-
12320
- IVector
12321
- (-assoc-n [coll n val] (-assoc coll n val))
12322
-
12323
- IReduce
12324
- (-reduce [v f]
12325
- (ci-reduce array f))
12326
- (-reduce [v f start]
12327
- (ci-reduce array f start))
12328
-
12329
- IFn
12330
- (-invoke [coll k]
12331
- (-lookup coll k))
12332
- (-invoke [coll k not-found]
12333
- (-lookup coll k not-found)))
12334
-
12335
- (set! (. Vector -EMPTY) (Vector. nil (array )))
12336
-
12337
- (set! (. Vector -fromArray) (fn [xs] (Vector. nil xs)))
12338
-
12339
- ; The keys field is an array of all keys of this map, in no particular
12340
- ; order. Any string, keyword, or symbol key is used as a property name
12341
- ; to store the value in strobj. If a key is assoc'ed when that same
12342
- ; key already exists in strobj, the old value is overwritten. If a
12343
- ; non-string key is assoc'ed, return a HashMap object instead.
12344
-
12345
- (defn- obj-map-contains-key?
12346
- ([k strobj]
12347
- (obj-map-contains-key? k strobj true false ))
12348
- ([k strobj true -val false -val]
12349
- (if (and (goog/isString k) (.hasOwnProperty strobj k))
12350
- true -val
12351
- false -val)))
12352
-
12353
- (defn- obj-map-compare-keys [a b]
12354
- (let [a (hash a)
12355
- b (hash b)]
12356
- (cond
12357
- (< a b) -1
12358
- (> a b) 1
12359
- :else 0 )))
12360
-
12361
- (deftype ObjMap [meta keys strobj]
12362
- IWithMeta
12363
- (-with-meta [coll meta] (ObjMap. meta keys strobj))
12364
-
12365
- IMeta
12366
- (-meta [coll] meta)
12367
-
12368
- ICollection
12369
- (-conj [coll entry]
12370
- (if (vector? entry)
12371
- (-assoc coll (-nth entry 0 ) (-nth entry 1 ))
12372
- (reduce -conj
12373
- coll
12374
- entry)))
12375
-
12376
- IEmptyableCollection
12377
- (-empty [coll] (with-meta cljs.core.ObjMap/EMPTY meta))
12378
-
12379
- IEquiv
12380
- (-equiv [coll other] (equiv-map coll other))
12381
-
12382
- IHash
12383
- (-hash [coll] (hash-coll coll))
12384
-
12385
- ISeqable
12386
- (-seq [coll]
12387
- (when (pos? (.-length keys))
12388
- (map #(vector % (aget strobj %))
12389
- (.sort keys obj-map-compare-keys))))
12390
-
12391
- ICounted
12392
- (-count [coll] (.-length keys))
12393
-
12394
- ILookup
12395
- (-lookup [coll k] (-lookup coll k nil ))
12396
- (-lookup [coll k not-found]
12397
- (obj-map-contains-key? k strobj (aget strobj k) not-found))
12398
-
12399
- IAssociative
12400
- (-assoc [coll k v]
12401
- (if (goog/isString k)
12402
- (let [new-strobj (goog.object/clone strobj)
12403
- overwrite? (.hasOwnProperty new-strobj k)]
12404
- (aset new-strobj k v)
12405
- (if overwrite?
12406
- (ObjMap. meta keys new-strobj) ; overwrite
12407
- (let [new-keys (aclone keys)] ; append
12408
- (.push new-keys k)
12409
- (ObjMap. meta new-keys new-strobj))))
12410
- ; non-string key. game over.
12411
- (with-meta (into (hash-map k v) (seq coll)) meta)))
12412
- (-contains-key? [coll k]
12413
- (obj-map-contains-key? k strobj))
12414
-
12415
- IMap
12416
- (-dissoc [coll k]
12417
- (if (and (goog/isString k) (.hasOwnProperty strobj k))
12418
- (let [new-keys (aclone keys)
12419
- new-strobj (goog.object/clone strobj)]
12420
- (.splice new-keys (scan-array 1 k new-keys) 1 )
12421
- (js-delete new-strobj k)
12422
- (ObjMap. meta new-keys new-strobj))
12423
- coll)) ; key not found, return coll unchanged
12424
-
12425
- IFn
12426
- (-invoke [coll k]
12427
- (-lookup coll k))
12428
- (-invoke [coll k not-found]
12429
- (-lookup coll k not-found)))
12430
-
12431
- (set! (. ObjMap -EMPTY) (ObjMap. nil (array ) (js-obj )))
12432
-
12433
- (set! (. ObjMap -fromObject) (fn [ks obj] (ObjMap. nil ks obj)))
12434
-
12435
- ; The keys field is an array of all keys of this map, in no particular
12436
- ; order. Each key is hashed and the result used as a property name of
12437
- ; hashobj. Each values in hashobj is actually a bucket in order to handle hash
12438
- ; collisions. A bucket is an array of alternating keys (not their hashes) and
12439
- ; vals.
12440
- (deftype HashMap [meta count hashobj]
12441
- IWithMeta
12442
- (-with-meta [coll meta] (HashMap. meta count hashobj))
12443
-
12444
- IMeta
12445
- (-meta [coll] meta)
12446
-
12447
- ICollection
12448
- (-conj [coll entry]
12449
- (if (vector? entry)
12450
- (-assoc coll (-nth entry 0 ) (-nth entry 1 ))
12451
- (reduce -conj
12452
- coll
12453
- entry)))
12454
-
12455
- IEmptyableCollection
12456
- (-empty [coll] (with-meta cljs.core.HashMap/EMPTY meta))
12457
-
12458
- IEquiv
12459
- (-equiv [coll other] (equiv-map coll other))
12460
-
12461
- IHash
12462
- (-hash [coll] (hash-coll coll))
12463
-
12464
- ISeqable
12465
- (-seq [coll]
12466
- (when (pos? count)
12467
- (let [hashes (.sort (js-keys hashobj))]
12468
- (mapcat #(map vec (partition 2 (aget hashobj %)))
12469
- hashes))))
12470
-
12471
- ICounted
12472
- (-count [coll] count)
12473
-
12474
- ILookup
12475
- (-lookup [coll k] (-lookup coll k nil ))
12476
- (-lookup [coll k not-found]
12477
- (let [bucket (aget hashobj (hash k))
12478
- i (when bucket (scan-array 2 k bucket))]
12479
- (if i
12480
- (aget bucket (inc i))
12481
- not-found)))
12482
-
12483
- IAssociative
12484
- (-assoc [coll k v]
12485
- (let [h (hash k)
12486
- bucket (aget hashobj h)]
12487
- (if bucket
12488
- (let [new-bucket (aclone bucket)
12489
- new-hashobj (goog.object/clone hashobj)]
12490
- (aset new-hashobj h new-bucket)
12491
- (if-let [i (scan-array 2 k new-bucket)]
12492
- (do ; found key, replace
12493
- (aset new-bucket (inc i) v)
12494
- (HashMap. meta count new-hashobj))
12495
- (do ; did not find key, append
12496
- (.push new-bucket k v)
12497
- (HashMap. meta (inc count) new-hashobj))))
12498
- (let [new-hashobj (goog.object/clone hashobj)] ; did not find bucket
12499
- (aset new-hashobj h (array k v))
12500
- (HashMap. meta (inc count) new-hashobj)))))
12501
- (-contains-key? [coll k]
12502
- (let [bucket (aget hashobj (hash k))
12503
- i (when bucket (scan-array 2 k bucket))]
12504
- (if i
12505
- true
12506
- false )))
12507
-
12508
- IMap
12509
- (-dissoc [coll k]
12510
- (let [h (hash k)
12511
- bucket (aget hashobj h)
12512
- i (when bucket (scan-array 2 k bucket))]
12513
- (if (not i)
12514
- coll ; key not found, return coll unchanged
12515
- (let [new-hashobj (goog.object/clone hashobj)]
12516
- (if (> 3 (.-length bucket))
12517
- (js-delete new-hashobj h)
12518
- (let [new-bucket (aclone bucket)]
12519
- (.splice new-bucket i 2 )
12520
- (aset new-hashobj h new-bucket)))
12521
- (HashMap. meta (dec count) new-hashobj)))))
12522
-
12523
- IFn
12524
- (-invoke [coll k]
12525
- (-lookup coll k))
12526
- (-invoke [coll k not-found]
12527
- (-lookup coll k not-found)))
12528
-
12529
- (set! (. HashMap -EMPTY) (HashMap. nil 0 (js-obj )))
12530
-
12531
- (set! cljs.core.HashMap/fromArrays (fn [ks vs]
12532
- (let [len (.-length ks)]
12533
- (loop [i 0 , out cljs.core.HashMap/EMPTY]
12534
- (if (< i len)
12535
- (recur (inc i) (assoc out (aget ks i) (aget vs i)))
12536
- out)))))
12537
-
12538
- (deftype Set [meta hash-map]
12539
- IWithMeta
12540
- (-with-meta [coll meta] (Set. meta hash-map))
12541
-
12542
- IMeta
12543
- (-meta [coll] meta)
12544
-
12545
- ICollection
12546
- (-conj [coll o]
12547
- (Set. meta (assoc hash-map o nil )))
12548
-
12549
- IEmptyableCollection
12550
- (-empty [coll] (with-meta cljs.core.Set/EMPTY meta))
12551
-
12552
- IEquiv
12553
- (-equiv [coll other]
12554
- (and
12555
- (set? other)
12556
- (= (count coll) (count other))
12557
- (every? #(contains? coll %)
12558
- other)))
12559
-
12560
- IHash
12561
- (-hash [coll] (hash-coll coll))
12562
-
12563
- ISeqable
12564
- (-seq [coll] (keys hash-map))
12565
-
12566
- ICounted
12567
- (-count [coll] (count (seq coll)))
12568
-
12569
- ILookup
12570
- (-lookup [coll v]
12571
- (-lookup coll v nil ))
12572
- (-lookup [coll v not-found]
12573
- (if (-contains-key? hash-map v)
12574
- v
12575
- not-found))
12576
-
12577
- ISet
12578
- (-disjoin [coll v]
12579
- (Set. meta (dissoc hash-map v)))
12580
-
12581
- IFn
12582
- (-invoke [coll k]
12583
- (-lookup coll k))
12584
- (-invoke [coll k not-found]
12585
- (-lookup coll k not-found)))
12586
-
12587
- (set! (. Set -EMPTY) (Set. nil (hash-map )))
0 commit comments