[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.13 Hashtables

Builtin Class: <hash-table>
Hash table class.

Function: make-hash-table &optional type
Creates a hash table. A symbol type specifies the type of the table. The following types are currently supported.
Keys are compared by eq?
Keys are compared by eqv?
Keys are compared by equal?
Keys are compared by string=?. Key must be a string.

If type is omitted, eq? is assumed.

Function: hash-table? obj
Returns #t if obj is a hash table.

Function: hash-table-get hash key &optional default
Search key from a hash table hash, and returns its value if found. If the key is not found in the table and default is given, it is returned. Otherwise an error is signalled.

Function: hash-table-put! hash key value
Puts a key key with a value value to the hash table hash.

Function: hash-table-exists? hash key
Returns #t if a hash table hash has a key key.

Function: hash-table-delete! hash key
Deletes an entry that has a key key from the hash table hash. Returns #t if the entry has exist, or #f if the entry hasn't exist. The same function is called hash-table-remove! in STk (except that it returns an undefined value); I use `delete' for consistency to SRFI-1, SRFI-13 and other parts of the libraries.

Function: hash-table-push! hash key value
Conses value to the existing value for the key key in the hash table hash and makes it the new value for key. If there's no entry for key, an entry is created with the value (list value).

Works the same as the following code, except that this function only looks up the key once, thus it's more efficient.
(hash-table-put! hash key
    (cons value (hash-table-get hash key '())))

Function: hash-table-pop! hash key &optional default
Looks for the value for the key key in the hash table hash. If found and it is a pair, replaces the value for its cdr and returns car of the original value. If no entry for key is in the table, or the value is not a pair, the table is not modified and the procedure returns default if given, or signals an error otherwise.

During the operation the key is looked for only once, thus runs efficiently.

Function: hash-table-for-each hash proc
Function: hash-table-map hash proc
A procedure proc is called with two arguments, a key and associated value, over all the entries in the hash table hash.

Function: hash-table-keys hash
Function: hash-table-values hash
Returns all the keys or values of hash table hash in a list, respectively.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html