faster distinct: maintain seen items in a set
* hy/core/language.hy: maintain the seen items in a set instead of a list in `distinct`. This is much faster for lookups.
This commit is contained in:
parent
e8dfe5bfb2
commit
a41a3c7edc
@ -75,12 +75,12 @@
|
|||||||
(defn distinct [coll]
|
(defn distinct [coll]
|
||||||
"Return a generator from the original collection with duplicates
|
"Return a generator from the original collection with duplicates
|
||||||
removed"
|
removed"
|
||||||
(let [[seen []] [citer (iter coll)]]
|
(let [[seen (set)] [citer (iter coll)]]
|
||||||
(for* [val citer]
|
(for* [val citer]
|
||||||
(if (not_in val seen)
|
(if (not_in val seen)
|
||||||
(do
|
(do
|
||||||
(yield val)
|
(yield val)
|
||||||
(.append seen val))))))
|
(.add seen val))))))
|
||||||
|
|
||||||
(defn drop [count coll]
|
(defn drop [count coll]
|
||||||
"Drop `count` elements from `coll` and yield back the rest"
|
"Drop `count` elements from `coll` and yield back the rest"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user