! Copyright (C) 2010 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays fry hash-sets hash-sets.private kernel math
-prettyprint sequences sets sorting tools.test ;
-FROM: hashtables.private => tombstone ;
-
-! key@
-{
- { { T{ tombstone } T{ tombstone } } f f }
- { { T{ tombstone } 123 } 1 t }
-} [
- "hi" 0 <hash-set> key@ 3array
- 123 HS{ 123 } key@ 3array
-] unit-test
+USING: accessors fry hash-sets kernel math prettyprint sequences
+sets sorting tools.test ;
{ { 1 2 3 } } [ HS{ 1 2 3 } members natural-sort ] unit-test
] if ; inline recursive
: key@ ( key hash -- array n ? )
- array>> 2dup hash@ 0 (key@) ; inline
+ array>> dup length>> 0 eq?
+ [ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
: <hash-array> ( n -- array )
3 * 1 + 2/ next-power-of-2 +empty+ <array> ; inline
] if ; inline recursive
: key@ ( key hash -- array n ? )
- array>> 2dup hash@ 0 (key@) ; inline
+ array>> dup length>> 0 eq?
+ [ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
: <hash-array> ( n -- array )
3 * 1 + 2/ next-power-of-2 2 * +empty+ <array> ; inline