Next: , Previous: , Up: Scheme reference   [Contents][Index]


4.9 Hash tables

There are many mutable hashtable APIs amongst all the various Scheme implementations, standards, and SRFIs. From our point of view, there is no clear “best” hashtable API that has emerged, but we think the R6RS interface is OK. Guile’s own hashtable API has design issues that are best left in the past. So, the (hoot hashtables) module is R6RS-like.

Currently, this interface supports keys hashed by object identity (eq?) only. The object equivalence (eqv?) and deep object equality (equal?) hashing strategies are not yet implemented.

Procedure: make-eq-hashtable

Return a new, empty hash table.

Procedure: hashtable? obj

Return #t if obj

Procedure: hashtable-size hashtable

Return the number of key/value pairs in hashtable.

Procedure: hashtable-ref hashtable key default

Return the value associated with key in hashtable or default if there is no such association.

Procedure: hashtable-set! hashtable key value

Modify hashtable to associate key with value, overwriting any previous association that may have existed.

Procedure: hashtable-delete! hashtable key

Remove the association with key in hashtable, if one exists.

Procedure: hashtable-clear! hashtable

Remove all of the key/value associations in hashtable.

Procedure: hashtable-contains? hashtable key

Return #t if key has an associated value in hashtable.

Procedure: hashtable-copy hashtable

Return a copy of hashtable.

Procedure: hashtable-keys hashtable

Return a vector of keys in hashtable.

Procedure: hashtable-entries hashtable

Return a vector of values in hashtable.

Procedure: hashtable-for-each proc hashtable

For each key/value pair in hashtable, call proc with two arguments: the key and the value.

Hoot also includes weak key hash tables that wrap those of the Wasm host platform, such as the WeakMap JavaScript class on the web.

Procedure: make-weak-key-hashtable

Return a new weak key hashtable.

Procedure: weak-key-hashtable? obj

Return #t if obj is a weak key hashtable.

Procedure: weak-key-hashtable-ref hashtable key [default #f]

Return the value associated with key in hashtable or default if there is no such association.

Procedure: weak-key-hashtable-set! hashtable key value

Modify hashtable to associate key with value, overwriting any previous association that may have existed.

Procedure: weak-key-hashtable-delete! hashtable key

Remove the association with key in hashtable, if one exists.

The underlying hash functions are also available.

Procedure: hashq key size

Return a hash value for key suitable for using in a table containing size buckets. The returned hash value will be in the range [0, size).


Next: Records, Previous: Parameters, Up: Scheme reference   [Contents][Index]