hash-sets,hashtables: improved key@ word

Don't need to check the length of the backing array because it can be
assumed to be > 0. That should make hash lookups a little faster.
char-rename
Björn Lindqvist 2016-09-25 20:07:08 +02:00
parent d71bd83f57
commit 70c7f9e029
3 changed files with 14 additions and 6 deletions

View File

@ -1,7 +1,17 @@
! Copyright (C) 2010 Daniel Ehrenberg ! Copyright (C) 2010 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors fry hash-sets kernel math prettyprint sequences USING: accessors arrays fry hash-sets hash-sets.private kernel math
sets sorting tools.test ; 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
{ { 1 2 3 } } [ HS{ 1 2 3 } members natural-sort ] unit-test { { 1 2 3 } } [ HS{ 1 2 3 } members natural-sort ] unit-test

View File

@ -32,8 +32,7 @@ TUPLE: hash-set
] if ; inline recursive ] if ; inline recursive
: key@ ( key hash -- array n ? ) : key@ ( key hash -- array n ? )
array>> dup length>> 0 eq? array>> 2dup hash@ 0 (key@) ; inline
[ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
: <hash-array> ( n -- array ) : <hash-array> ( n -- array )
3 * 1 + 2/ next-power-of-2 +empty+ <array> ; inline 3 * 1 + 2/ next-power-of-2 +empty+ <array> ; inline

View File

@ -32,8 +32,7 @@ TUPLE: hashtable
] if ; inline recursive ] if ; inline recursive
: key@ ( key hash -- array n ? ) : key@ ( key hash -- array n ? )
array>> dup length>> 0 eq? array>> 2dup hash@ 0 (key@) ; inline
[ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
: <hash-array> ( n -- array ) : <hash-array> ( n -- array )
3 * 1 + 2/ next-power-of-2 2 * +empty+ <array> ; inline 3 * 1 + 2/ next-power-of-2 2 * +empty+ <array> ; inline