Next: Weak references, Previous: Queues, Up: System features
Scheme48 provides a simple hash table facility in the structure
tables
.
Hash table constructors.
Make-table
creates a table that hashes keys either with hasher, if it is passed tomake-table
, ordefault-hash-function
, and it compares keys for equality witheq?
, unless they are numbers, in which case it compares witheqv?
.Make-string-table
makes a table whose hash function isstring-hash
and that compares the equality of keys withstring=?
.Make-symbol-table
constructs a table that hashes symbol keys by converting them to strings and hashing them withstring-hash
; it compares keys' equality byeq?
. Tables made bymake-integer-table
hash keys by taking their absolute value, and test for key equality with the=
procedure.
Customized table constructor constructor: this returns a nullary procedure that creates a new table that uses comparator to compare keys for equality and hasher to hash keys.
#f
Table-ref
returns the value associated with key in table, or#f
if there is no such association. If value is#f
,table-set!
ensures that there is no longer an association with key in table; if value is any other value,table-set!
creates a new association or assigns an existing one in table whose key is key and whose associated value is value.
Table-walk
applies proc to the key & value, in that order of arguments, of every association in table.
This makes the structure of table immutable, though not its contents.
Table-set!
may not be used with tables that have been made immutable.
Two built-in hashing functions.
Default-hash-function
can hash any Scheme value that could usefully be used in acase
clause.String-hash
is likely to be fast, as it is implemented as a VM primitive.String-hash
is the same as what thefeatures
structure exports under the same name.