Next: , Previous: , Up: The language   [Contents][Index]


5.22 Hash Tables

The rep.data.tables module provides a flexible hash table implementation (see Modules). Each hash table is represented by a lisp object satisfying the tablep predicate:

Function: tablep arg

Return true if arg is a hash table.

Hash tables may be created by using the make-table and make-weak-table functions:

Function: make-table hash-fun compare-fun

Create and return a new hash table. When storing and referencing keys it will use the function hash-fun to map keys to hash codes (positive fixnums), and the predicate function compare-fun to compare two keys (should return true if the keys are considered equal).

Function: make-weak-table hash-fun compare-fun

Similar to make-table, except that key-value pairs stored in the table are said to be “weakly keyed”. That is, they are only retained in the table as long the key has not been garbage collected.

Unlike with tables created by the make-table function, the fact that the key is stored in the table is not considered good enough to prevent it being garbage collected.

Function: table-ref table key

Return the value stored in hash table table indexed by object key. Returns false if no such value exists.

Function: table-bound-p table key

Returns true if the hash table table contains a value associated with key.

Function: table-set table key value

Associate the value value with key in hash table table. Returns value.

Function: table-unset table key

Remove any value stored in table associated with key.

Function: table-walk function table

Call function function for every key-value pair stored in hash table table. For each pair, the function is called with arguments (key value).

Function: table-size table

Returns the number of items currently stored in table.

Several hash functions are also provided:

Function: string-hash string

Return an integer representing the string string.

Function: symbol-hash symbol

Call (string-hash (symbol-name symbol)).

Function: eq-hash arg

Return a hash value representing object arg. The hash is generated from the address of the object.

Function: equal-hash arg

Return a hash value representing object arg. The hash is generated from the contents of the object.


Next: , Previous: , Up: The language   [Contents][Index]