|
11 | 11 | (ns ^:no-doc editscript.util.pairing |
12 | 12 | #?(:clj |
13 | 13 | (:import [clojure.lang IPersistentStack IPersistentMap IPersistentCollection] |
14 | | - [java.io Writer]))) |
| 14 | + [java.io Writer]) |
| 15 | + :cljr |
| 16 | + (:import [clojure.lang IPersistentStack IPersistentMap IPersistentCollection] |
| 17 | + ))) |
15 | 18 |
|
16 | 19 | #?(:clj (set! *warn-on-reflection* true)) |
17 | 20 |
|
|
100 | 103 | (set! map (dissoc map (.-item heap))) |
101 | 104 | (set! heap n) |
102 | 105 | this))) |
| 106 | +:cljr |
| 107 | + (deftype PriorityMap [^:unsynchronized-mutable ^HeapNode heap |
| 108 | + ^:unsynchronized-mutable map] |
| 109 | + IPersistentCollection |
| 110 | + (count [_] (count map)) |
| 111 | + (^IPersistentCollection cons [this e] |
| 112 | + (let [[item priority] e] |
| 113 | + (set! map (assoc map item priority)) |
| 114 | + (set! heap (insert heap item priority)) |
| 115 | + this)) |
| 116 | + (empty [this] |
| 117 | + (set! heap nil) |
| 118 | + (set! map {}) |
| 119 | + this) |
| 120 | + (equiv [this o] (identical? this o)) |
| 121 | + |
| 122 | + IPersistentMap |
| 123 | + (^IPersistentMap assoc [this item priority] |
| 124 | + (set! map (assoc map item priority)) |
| 125 | + (set! heap (insert heap item priority)) |
| 126 | + this) |
| 127 | + (^clojure.lang.Associative assoc [this item priority] |
| 128 | + (set! map (assoc map item priority)) |
| 129 | + (set! heap (insert heap item priority)) |
| 130 | + this) |
| 131 | + (GetHashCode [_] (hash map)) |
| 132 | + (Equals [this o] (identical? this o)) |
| 133 | + (containsKey [_ item] (contains? map item)) |
| 134 | + (entryAt [_ k] (find map k)) |
| 135 | + (seq [_] (seq map)) |
| 136 | + (without [this item] (dissoc map item) this) |
103 | 137 |
|
| 138 | + IPersistentStack |
| 139 | + (peek [_] [(.-item heap) (.-priority heap)]) |
| 140 | + (pop [this] |
| 141 | + (let [n (two-pass (get-left heap))] |
| 142 | + (set! map (dissoc map (.-item heap))) |
| 143 | + (set! heap n) |
| 144 | + this))) |
104 | 145 | :cljs |
105 | 146 | (deftype PriorityMap [^:mutable ^HeapNode heap |
106 | 147 | ^:mutable map] |
|
115 | 156 | (set! heap (insert heap item priority)) |
116 | 157 | this)) |
117 | 158 |
|
| 159 | + IAssociative |
118 | 160 | IAssociative |
119 | 161 | (-assoc [this item priority] |
120 | 162 | (set! map (assoc map item priority)) |
|
0 commit comments