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