hashtables: rename ((tombstone)) to +tombstone+, ((empty)) to +empty+

locals-and-roots
Doug Coleman 2016-03-25 01:52:07 -07:00
parent 58efceb408
commit 92afdc3ad0
5 changed files with 15 additions and 15 deletions

View File

@ -375,7 +375,7 @@ ERROR: tuple-removed class ;
M: tuple prepare-object emit-tuple ;
M: tombstone prepare-object
state>> "((tombstone))" "((empty))" ?
state>> "+tombstone+" "+empty+" ?
"hashtables.private" lookup-word def>> first
[ emit-tuple ] cache-eql-object ;

View File

@ -265,11 +265,11 @@ bi
tuple
{ "state" } define-tuple-class
"((empty))" "hashtables.private" create-word
"+empty+" "hashtables.private" create-word
{ f } "tombstone" "hashtables.private" lookup-word
slots>tuple 1quotation ( -- value ) define-inline
"((tombstone))" "hashtables.private" create-word
"+tombstone+" "hashtables.private" create-word
{ t } "tombstone" "hashtables.private" lookup-word
slots>tuple 1quotation ( -- value ) define-inline

View File

@ -23,7 +23,7 @@ TUPLE: hash-set
: no-key ( key array -- array n ? ) nip f f ; inline
: (key@) ( key array i probe# -- array n ? )
[ 3dup swap array-nth ] dip over ((empty)) eq?
[ 3dup swap array-nth ] dip over +empty+ eq?
[ 4drop no-key ] [
[ = ] dip swap
[ drop rot drop t ]
@ -36,7 +36,7 @@ TUPLE: hash-set
[ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
: <hash-array> ( n -- array )
3 * 1 + 2/ next-power-of-2 ((empty)) <array> ; inline
3 * 1 + 2/ next-power-of-2 +empty+ <array> ; inline
: reset-hash ( n hash -- )
swap <hash-array> >>array init-hash ; inline
@ -44,7 +44,7 @@ TUPLE: hash-set
: (new-key@) ( key array i probe# j -- array i j empty? )
[ 2dup swap array-nth ] 2dip pick tombstone?
[
rot ((empty)) eq?
rot +empty+ eq?
[ nip [ drop ] 3dip t ]
[ pick or [ probe ] dip (new-key@) ]
if
@ -95,11 +95,11 @@ M: hash-set in?
key@ 2nip ;
M: hash-set clear-set
[ init-hash ] [ array>> [ drop ((empty)) ] map! drop ] bi ;
[ init-hash ] [ array>> [ drop +empty+ ] map! drop ] bi ;
M: hash-set delete
[ nip ] [ key@ ] 2bi [
[ ((tombstone)) ] 2dip set-nth-item
[ +tombstone+ ] 2dip set-nth-item
hash-deleted+
] [
3drop

View File

@ -5,7 +5,7 @@ IN: hashtables
ARTICLE: "hashtables.private" "Hashtable implementation details"
"This hashtable implementation uses only one auxiliary array in addition to the hashtable tuple itself. The array stores keys in even slots and values in odd slots. Values are looked up with a hashing strategy that uses quadratic probing to resolve collisions."
$nl
"There are two special objects: the " { $link ((tombstone)) } " marker and the " { $link ((empty)) } " marker. Neither of these markers can be used as hashtable keys."
"There are two special objects: the " { $link +tombstone+ } " marker and the " { $link +empty+ } " marker. Neither of these markers can be used as hashtable keys."
$nl
"The " { $snippet "count" } " slot is the number of entries including deleted entries, and " { $snippet "deleted" } " is the number of deleted entries."
{ $subsections
@ -70,7 +70,7 @@ HELP: probe
HELP: key@
{ $values { "key" "a key" } { "hash" hashtable } { "array" "the underlying array of the hashtable" } { "n" "the index of the key" } { "?" "a boolean indicating whether the key was present" } }
{ $description "Searches the hashtable for the key using a quadratic probing strategy. Searches stop if either the key or an " { $link ((empty)) } " sentinel is found. Searches skip the " { $link ((tombstone)) } " sentinel." } ;
{ $description "Searches the hashtable for the key using a quadratic probing strategy. Searches stop if either the key or an " { $link +empty+ } " sentinel is found. Searches skip the " { $link +tombstone+ } " sentinel." } ;
{ key@ new-key@ } related-words

View File

@ -23,7 +23,7 @@ TUPLE: hashtable
: no-key ( key array -- array n ? ) nip f f ; inline
: (key@) ( key array i probe# -- array n ? )
[ 3dup swap array-nth ] dip over ((empty)) eq?
[ 3dup swap array-nth ] dip over +empty+ eq?
[ 4drop no-key ] [
[ = ] dip swap
[ drop rot drop t ]
@ -36,7 +36,7 @@ TUPLE: hashtable
[ no-key ] [ 2dup hash@ 0 (key@) ] if ; inline
: <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
: init-hash ( hash -- )
0 >>count 0 >>deleted drop ; inline
@ -68,7 +68,7 @@ TUPLE: hashtable
: (new-key@) ( key array i probe# j -- array i j empty? )
[ 2dup swap array-nth ] 2dip pick tombstone?
[
rot ((empty)) eq?
rot +empty+ eq?
[ nip [ drop ] 3dip t ]
[ pick or [ probe ] dip (new-key@) ]
if
@ -126,11 +126,11 @@ M: hashtable at*
key@ [ 3 fixnum+fast slot t ] [ 2drop f f ] if ;
M: hashtable clear-assoc
[ init-hash ] [ array>> [ drop ((empty)) ] map! drop ] bi ;
[ init-hash ] [ array>> [ drop +empty+ ] map! drop ] bi ;
M: hashtable delete-at
[ nip ] [ key@ ] 2bi [
[ ((tombstone)) dup ] 2dip set-nth-pair
[ +tombstone+ dup ] 2dip set-nth-pair
hash-deleted+
] [
3drop