Next: Weak references, Previous: Queues, Up: System features
Scheme48 provides a simple hash table facility in the structure
tables.
Hash table constructors.
Make-tablecreates 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-tablemakes a table whose hash function isstring-hashand that compares the equality of keys withstring=?.Make-symbol-tableconstructs 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-tablehash 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-refreturns the value associated with key in table, or#fif 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-walkapplies 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-functioncan hash any Scheme value that could usefully be used in acaseclause.String-hashis likely to be fast, as it is implemented as a VM primitive.String-hashis the same as what thefeaturesstructure exports under the same name.