| www.delorie.com/gnu/docs/guile/guile_252.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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). Uses eq? for equality testing.
#f if no default argument
is supplied). Uses eqv? for equality testing.
#f if no default argument
is supplied). Uses equal? for equality testing.
eq? for equality testing.
eqv? for equality testing.
equal? for equality
testing.
eq? for equality tests.
eqv? for equality tests.
equal? for equality tests.
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.
eq? is
used as the equality predicate. The function returns an
integer in the range 0 to size - 1. Note that
hashq may use internal addresses. Thus two calls to
hashq where the keys are eq? are not guaranteed to
deliver the same value if the key object gets garbage collected
in between. This can happen, for example with symbols:
(hashq 'foo n) (gc) (hashq 'foo n) may produce two
different values, since foo will be garbage collected.
eqv? is
used as the equality predicate. The function returns an
integer in the range 0 to size - 1. Note that
(hashv key) may use internal addresses. Thus two calls
to hashv where the keys are eqv? are not guaranteed to
deliver the same value if the key object gets garbage collected
in between. This can happen, for example with symbols:
(hashv 'foo n) (gc) (hashv 'foo n) may produce two
different values, since foo will be garbage collected.
equal?
is used as the equality predicate. The function returns an
integer in the range 0 to size - 1.
ref
function, but uses hash as a hash function and
assoc to compare keys. hash 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.
set!
function, but uses hash as a hash function and
assoc to compare keys. hash 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-set! table key is
equivalent to hashx-set! hashq assq table key.
(key . value) pair from the
hash table table. If table does not hold an
associated value for key, #f is returned.
Uses eq? for equality testing.
(key . value) pair from the
hash table table. If table does not hold an
associated value for key, #f is returned.
Uses eqv? for equality testing.
(key . value) pair from the
hash table table. If table does not hold an
associated value for key, #f is returned.
Uses equal? for equality testing.
-get-handle function, but uses hash as a hash
function and assoc to compare keys. hash 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.
-create-handle function, but uses hash as a hash
function and assoc to compare keys. hash 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.
(hash-fold acons '() tab) will convert a hash
table into an a-list of key-value pairs.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |