]> gitweb.factorcode.org Git - factor.git/commitdiff
hash-sets: faster members.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 7 Feb 2014 06:38:48 +0000 (22:38 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 7 Feb 2014 06:38:48 +0000 (22:38 -0800)
core/hash-sets/hash-sets.factor

index 178ccf11eadf5fcd58d4a5e102e978c76e5e1688..3f98d7fdd7687c2a94302d84dba45fcc9579ae24 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2010 Daniel Ehrenberg
 ! Copyright (C) 2005, 2011 John Benediktsson, Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays hash-sets hashtables.private kernel
-kernel.private math math.private sequences sequences.private
-sets sets.private slots.private vectors ;
+USING: accessors arrays growable.private hash-sets
+hashtables.private kernel kernel.private math math.private
+sequences sequences.private sets sets.private slots.private
+vectors ;
 IN: hash-sets
 
 TUPLE: hash-set
@@ -71,7 +72,7 @@ TUPLE: hash-set
     [ count>> 3 fixnum*fast ]
     [ array>> length>> 1 fixnum-shift-fast ] bi fixnum>= ; inline
 
-: each-member ( array quot: ( elt -- ) -- )
+: each-member ( ... array quot: ( ... elt -- ... ) -- ... )
     [ if ] curry [ dup tombstone? [ drop ] ] prepose each ; inline
 
 : grow-hash ( hash -- )
@@ -116,9 +117,9 @@ M: hash-set ?adjoin
     dup ?grow-hash (adjoin) ;
 
 M: hash-set members
-    [ array>> ] [ cardinality <vector> ] bi [
-        [ push-unsafe ] curry each-member
-    ] keep { } like ;
+    [ array>> 0 swap ] [ cardinality f <array> ] bi [
+        [ [ over ] dip set-nth-unsafe 1 + ] curry each-member
+    ] keep nip ;
 
 M: hash-set clone
     (clone) [ clone ] change-array ; inline