|
1168 | 1168 | (is (every? keyword? (keys c)))
|
1169 | 1169 | (is (= (set [:a :b :c]) (set (keys c)))))
|
1170 | 1170 | (is (= (obj-map :a 1 :b 2 :c 3)
|
1171 |
| - (obj-map :a 1 :b 2 :c 3)))) |
| 1171 | + (obj-map :a 1 :b 2 :c 3))) |
| 1172 | + (is (= (obj-map :a 1 :b 2) |
| 1173 | + (into (obj-map) [[:a 1] [:b 2]]))) |
| 1174 | + (is (= (merge-with + |
| 1175 | + (obj-map :a 1 :b 2) |
| 1176 | + (obj-map :a 1 :b 2)) |
| 1177 | + (into (obj-map) [[:a 2] [:b 4]]))) |
| 1178 | + (is (= (transient (obj-map :a 1 :b 2)) |
| 1179 | + (obj-map :a 1 :b 2)))) |
| 1180 | + |
| 1181 | +(deftest test-hash-map |
| 1182 | + (let [a (simple-hash-map)] |
| 1183 | + (is (empty? a)) |
| 1184 | + (is (zero? (count a)))) |
| 1185 | + (let [b (simple-hash-map :a 1)] |
| 1186 | + (is (not (empty? b))) |
| 1187 | + (is (== 1 (count b)))) |
| 1188 | + (let [c (simple-hash-map :a 1 :b 2 :c 3)] |
| 1189 | + (is (== 3 (count c))) |
| 1190 | + (is (= 1 (get c :a))) |
| 1191 | + (is (= 1 (:a c))) |
| 1192 | + (is (every? keyword? (keys c))) |
| 1193 | + (is (= (set [:a :b :c]) (set (keys c))))) |
| 1194 | + (is (= (simple-hash-map :a 1 :b 2 :c 3) |
| 1195 | + (simple-hash-map :a 1 :b 2 :c 3))) |
| 1196 | + (is (= (simple-hash-map :a 1 :b 2) |
| 1197 | + (into (simple-hash-map) [[:a 1] [:b 2]]))) |
| 1198 | + (is (= (merge-with + |
| 1199 | + (simple-hash-map :a 1 :b 2) |
| 1200 | + (simple-hash-map :a 1 :b 2)) |
| 1201 | + (into (simple-hash-map) [[:a 2] [:b 4]]))) |
| 1202 | + (is (= (transient (simple-hash-map :a 1 :b 2)) |
| 1203 | + (simple-hash-map :a 1 :b 2)))) |
1172 | 1204 |
|
1173 | 1205 | (comment
|
1174 | 1206 |
|
1175 | 1207 | (run-tests)
|
1176 | 1208 |
|
| 1209 | + (defn simple-group-by |
| 1210 | + [f coll] |
| 1211 | + (persistent! |
| 1212 | + (reduce |
| 1213 | + (fn [ret x] |
| 1214 | + (let [k (f x)] |
| 1215 | + (assoc! ret k (conj (get ret k (. Vector -EMPTY)) x)))) |
| 1216 | + (transient (. ObjMap -EMPTY)) coll))) |
| 1217 | + |
| 1218 | + (simple-group-by |
| 1219 | + :ns |
| 1220 | + '[{:ns foo :name woz} |
| 1221 | + {:ns bar :name goz} |
| 1222 | + {:ns bar :name baz} |
| 1223 | + {:ns foo :name naz}]) |
| 1224 | + |
| 1225 | + (get (simple-hash-map :a 1 :b 2 :c 3) :a) |
| 1226 | + |
| 1227 | + (#'scan-array-equiv 2 :a |
| 1228 | + (unchecked-get (. (simple-hash-map :a 1 :b 2 :c 3) -hashobj) (hash :a))) |
| 1229 | + |
1177 | 1230 | )
|
0 commit comments