File tree Expand file tree Collapse file tree 2 files changed +6
-88
lines changed Expand file tree Collapse file tree 2 files changed +6
-88
lines changed Original file line number Diff line number Diff line change @@ -1166,80 +1166,14 @@ reduces them without incurring seq initialization"
11661166
11671167; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Sets ;;;;;;;;;;;;;;;;
11681168
1169- (defn- member? [coll o]
1170- (not (every? #(not (= % o)) coll)))
1171-
1172- (defn- reverse-rember [coll o]
1173- (loop [rev ()
1174- coll (seq coll)]
1175- (if coll
1176- (let [f (first coll)]
1177- (if (= o f)
1178- (recur rev (next coll))
1179- (recur (cons f rev) (next coll))))
1180- rev)))
1181-
1182- (deftype ListSet [elems]
1183- ICollection
1184- (-conj [coll o]
1185- (if (member? elems o)
1186- coll
1187- (ListSet. (conj elems o))))
1188-
1189- IEquiv
1190- (-equiv [coll other]
1191- (and
1192- (set? other)
1193- (== (count coll) (count other))
1194- (every? #(contains? coll %)
1195- other)))
1196-
1197- ISeqable
1198- (-seq [_] elems)
1199-
1200- ICounted
1201- (-count [coll] (count (seq coll)))
1202-
1203- ILookup
1204- (-lookup [coll v]
1205- (-lookup coll v nil ))
1206- (-lookup [coll v not-found]
1207- (if (member? elems v)
1208- v
1209- not-found))
1210-
1211- ISet
1212- (-disjoin [coll v]
1213- (if (member? elems v)
1214- (ListSet. (reverse-rember elems v))
1215- coll))
1216-
1217- IFn
1218- (-invoke [coll k]
1219- (-lookup coll k))
1220- (-invoke [coll k not-found]
1221- (-lookup coll k not-found))
1222-
1223- IPrintable
1224- (-pr-seq [coll opts] (pr-sequential pr-seq " #{" " " " }" opts elems)))
1225-
12261169(defn set
12271170 " Returns a set of the distinct elements of coll."
1228- [coll]
1229- (loop [in (seq coll)
1230- out (ListSet. ())]
1231- (if (seq in)
1232- (recur (next in) (conj out (first in)))
1233- out)))
1234-
1235- (defn hash-set
1236- ([] cljc.core.PersistentHashSet/EMPTY)
1237- ([& keys]
1238- (loop [in (seq keys)
1239- out (transient cljc.core.PersistentHashSet/EMPTY)]
1240- (if (seq in)
1241- (recur (next in) (conj! out (first in)))
1242- (persistent! out)))))
1171+ ([coll]
1172+ (loop [in (seq coll)
1173+ out (transient cljc.core.PersistentHashSet/EMPTY)]
1174+ (if (seq in)
1175+ (recur (next in) (conj! out (first in)))
1176+ (persistent! out)))))
12431177
12441178; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Strings ;;;;;;;;;;;;;;;;
12451179
Original file line number Diff line number Diff line change 549549 (is (= (core-run '(pr ((set '(1 2 3 )) 1 )
550550 ((set '(1 2 3 )) 4 )
551551 ((set '(1 2 3 )) 4 5 )))
552- [1 nil 5 ]))
553-
554- ; ;persistent hash sets
555- (is (= (core-run '(pr (conj (conj (conj (conj (hash-set ()) 1 ) 2 ) 3 ) 1 )))
556- ; ; Note -- this result differs from what ListSet gives above, but jibes
557- ; ; with what jvm clojure at the REPL gives
558- [#{() 1 2 3 }]))
559- (is (= (core-run '(pr (disj (hash-set 1 2 3 ) 2 )))
560- [#{1 3 }]))
561- (is (= (core-run '(pr (get (hash-set 1 2 3 ) 1 )
562- (get (hash-set 1 2 3 ) 4 )
563- (get (hash-set 1 2 3 ) 4 5 )))
564- [1 nil 5 ]))
565- (is (= (core-run '(pr ((hash-set 1 2 3 ) 1 )
566- ((hash-set 1 2 3 ) 4 )
567- ((hash-set 1 2 3 ) 4 5 )))
568552 [1 nil 5 ]))))
569553
570554(deftest functions
You can’t perform that action at this time.
0 commit comments