Like the association list functions, the hash table functions come
in several varieties: hashq
, hashv
, and hash
.
The hashq
functions use eq?
to determine whether two
keys match. The hashv
functions use eqv?
, and the
hash
functions use equal?
.
In each of the functions that follow, the table argument must be a vector. The key and value arguments may be any Scheme object.
#f
if no default argument is
supplied).
The standard hash table functions may be too limited for some applications. For example, you may want a hash table to store strings in a case-insensitive manner, so that references to keys named "foobar", "FOOBAR" and "FooBaR" will all yield the same item. Guile provides you with extended hash tables that permit you to specify a hash function and associator function of your choosing. The functions described in the rest of this section can be used to implement such custom hash table structures.
If you are unfamiliar with the inner workings of hash tables, then this facility will probably be a little too abstract for you to use comfortably. If you are interested in learning more, see an introductory textbook on data structures or algorithms for an explanation of how hash tables are implemented.
ref
and
set!
functions described above, but use hasher as a
hash function and assoc to compare keys. hasher
must
be a function that takes two arguments, a key to be hashed and a
table size. assoc
must be an associator function, like
assoc
, assq
or assv
.
By way of illustration, hashq-ref table key
is equivalent
to hashx-ref hashq assq table key
.
-ref
cousins, but return a
handle from the hash table rather than the value associated with
key. By convention, a handle in a hash table is the pair which
associates a key with a value. Where hashq-ref table key
returns
only a value
, hashq-get-handle table key
returns the pair
(key . value)
.
Go to the first, previous, next, last section, table of contents.