Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.

Next: , Up: SRFI-69   [Contents][Index]


7.5.39.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-proc is no coarser than equal? unless it is literally string-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 #f or a symbol indicating how “weak” the hash table is:

#f

An ordinary non-weak hash table. This is the default.

key

When the key has no more non-weak references at GC, remove that entry.

value

When the value has no more non-weak references at GC, remove that entry.

key-or-value

When 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 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.


Next: , Up: SRFI-69   [Contents][Index]