| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.5.34.1 Creating hash tables
- Scheme Procedure: make-hash-table [equal-proc hash-proc #:weak weakness start-size]
Create and answer a new hash table with equal-proc as the equality function and hash-proc as the hashing function.
By default, equal-proc is
equal?. It can be any two-argument procedure, and should answer whether two keys are the same for this table’s purposes.My default hash-proc assumes that
equal-procis no coarser thanequal?unless it is literallystring-ci=?. If provided, hash-proc should be a two-argument procedure that takes a key and the current table size, and answers a reasonably good hash integer between 0 (inclusive) and the size (exclusive).weakness should be
#for a symbol indicating how “weak” the hash table is:#fAn ordinary non-weak hash table. This is the default.
keyWhen the key has no more non-weak references at GC, remove that entry.
valueWhen the value has no more non-weak references at GC, remove that entry.
key-or-valueWhen either has no more non-weak references at GC, remove the association.
As a legacy of the time when Guile couldn’t grow hash tables, start-size is an optional integer argument that specifies the approximate starting size for the hash table, which will be rounded to an algorithmically-sounder number.
By coarser than equal?, we mean that for all x and
y values where (equal-proc x y),
(equal? x y) as well. If that does not hold for
your equal-proc, you must provide a hash-proc.
In the case of weak tables, remember that references above
always refers to eq?-wise references. Just because you have a
reference to some string "foo" doesn’t mean that an association
with key "foo" in a weak-key table won’t be collected;
it only counts as a reference if the two "foo"s are eq?,
regardless of equal-proc. As such, it is usually only sensible
to use eq? and hashq as the equivalence and hash
functions for a weak table. See section Weak References, for more
information on Guile’s built-in weak table support.
- Scheme Procedure: alist->hash-table alist [equal-proc hash-proc #:weak weakness start-size]
As with
make-hash-table, but initialize it with the associations in alist. Where keys are repeated in alist, the leftmost association takes precedence.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 20, 2013 using texi2html 5.0.
