From a41a3c7edc647d7d9bcb64913c03fae22ef71345 Mon Sep 17 00:00:00 2001 From: Abhishek L Date: Tue, 4 Feb 2014 01:35:41 +0530 Subject: [PATCH] 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. --- hy/core/language.hy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hy/core/language.hy b/hy/core/language.hy index 520d3f1..7fd5b2a 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -75,12 +75,12 @@ (defn distinct [coll] "Return a generator from the original collection with duplicates removed" - (let [[seen []] [citer (iter coll)]] + (let [[seen (set)] [citer (iter coll)]] (for* [val citer] (if (not_in val seen) (do (yield val) - (.append seen val)))))) + (.add seen val)))))) (defn drop [count coll] "Drop `count` elements from `coll` and yield back the rest"