|  | 
| 45 | 45 |     then | 
| 46 | 46 |     else)) | 
| 47 | 47 | 
 | 
| 48 |  | -(declare ->transient-int-map) | 
|  | 48 | +(declare ->transient-int-map | 
|  | 49 | +         ^:private EMPTY-INT-MAP) | 
| 49 | 50 | 
 | 
| 50 | 51 | (deftype PersistentIntMap | 
| 51 | 52 |   [^INode root | 
|  | 
| 292 | 293 |   (invoke [this k default] | 
| 293 | 294 |     (.valAt this k default))) | 
| 294 | 295 | 
 | 
|  | 296 | +(def ^:private ^PersistentIntMap EMPTY-INT-MAP (PersistentIntMap. Nodes$Empty/EMPTY 0 nil)) | 
|  | 297 | + | 
| 295 | 298 | (deftype TransientIntMap | 
| 296 | 299 |   [^INode root | 
| 297 | 300 |    ^long epoch | 
|  | 
| 396 | 399 |   "Given alternating keys and values, creates an integer map that can only | 
| 397 | 400 |   have non-negative integers as keys." | 
| 398 | 401 |   ([] | 
| 399 |  | -     (PersistentIntMap. Nodes$Empty/EMPTY 0 nil)) | 
|  | 402 | +     EMPTY-INT-MAP) | 
| 400 | 403 |   ([a b] | 
| 401 |  | -     (assoc (int-map) a b)) | 
|  | 404 | +     (assoc EMPTY-INT-MAP a b)) | 
| 402 | 405 |   ([a b & rest] | 
| 403 |  | -     (apply assoc (int-map) a b rest))) | 
|  | 406 | +     (apply assoc EMPTY-INT-MAP a b rest))) | 
| 404 | 407 | 
 | 
| 405 | 408 | (defn merge-with | 
| 406 | 409 |   "Merges together two int-maps, using `f` to resolve value conflicts." | 
| 407 | 410 |   ([f] | 
| 408 |  | -     (int-map)) | 
|  | 411 | +     EMPTY-INT-MAP) | 
| 409 | 412 |   ([f a b] | 
| 410 | 413 |      (let [a' (if (instance? TransientIntMap a) | 
| 411 | 414 |                 (persistent! a) | 
|  | 
| 420 | 423 | (defn merge | 
| 421 | 424 |   "Merges together two int-maps, giving precedence to values from the right-most map." | 
| 422 | 425 |   ([] | 
| 423 |  | -     (int-map)) | 
|  | 426 | +     EMPTY-INT-MAP) | 
| 424 | 427 |   ([a b] | 
| 425 | 428 |      (merge-with (fn [_ b] b) a b)) | 
| 426 | 429 |   ([a b & rest] | 
|  | 
| 576 | 579 | 
 | 
| 577 | 580 | ;;; | 
| 578 | 581 | 
 | 
|  | 582 | +(def ^:private ^PersistentIntSet EMPTY-INT-SET (PersistentIntSet. (IntSet. 128) 0 nil)) | 
|  | 583 | +(def ^:private ^PersistentIntSet EMPTY-DENSE-INT-SET (PersistentIntSet. (IntSet. 4096) 0 nil)) | 
|  | 584 | + | 
| 579 | 585 | (defn int-set | 
| 580 | 586 |   "Given a collection, creates an immutable set which can only store integral values. | 
| 581 | 587 |   This should be used unless elements are densely clustered (each element has multiple | 
| 582 | 588 |   elements within +/- 1000)." | 
| 583 | 589 |   ([] | 
| 584 |  | -     (PersistentIntSet. (IntSet. 128) 0 nil)) | 
|  | 590 | +     EMPTY-INT-SET) | 
| 585 | 591 |   ([s] | 
| 586 |  | -     (into (int-set) s))) | 
|  | 592 | +     (into EMPTY-INT-SET s))) | 
| 587 | 593 | 
 | 
| 588 | 594 | (defn dense-int-set | 
| 589 | 595 |   "Given a collection, creates an immutable set which can only store integral values. | 
| 590 | 596 |   This should be used only if elements are densely clustered (each element has multiple | 
| 591 | 597 |   elements within +/- 1000)." | 
| 592 | 598 |   ([] | 
| 593 |  | -     (PersistentIntSet. (IntSet. 4096) 0 nil)) | 
|  | 599 | +     EMPTY-DENSE-INT-SET) | 
| 594 | 600 |   ([s] | 
| 595 |  | -     (into (dense-int-set) s))) | 
|  | 601 | +     (into EMPTY-DENSE-INT-SET s))) | 
| 596 | 602 | 
 | 
| 597 | 603 | (defn union | 
| 598 | 604 |   "Returns the union of two bitsets." | 
|  | 
0 commit comments