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: , Previous: , Up: R6RS Standard Libraries   [Contents][Index]


7.6.2.23 rnrs hashtables

The (rnrs hashtables (6)) library provides structures and procedures for creating and accessing hash tables. The hash tables API defined by R6RS is substantially similar to both Guile’s native hash tables implementation as well as the one provided by SRFI-69; See Hash Tables, and SRFI-69, respectively. Note that you can write portable R6RS library code that manipulates SRFI-69 hash tables (by importing the (srfi :69) library); however, hash tables created by one API cannot be used by another.

Like SRFI-69 hash tables—and unlike Guile’s native ones—R6RS hash tables associate hash and equality functions with a hash table at the time of its creation. Additionally, R6RS allows for the creation (via hashtable-copy; see below) of immutable hash tables.

Scheme Procedure: make-eq-hashtable
Scheme Procedure: make-eq-hashtable k

Returns a new hash table that uses eq? to compare keys and Guile’s hashq procedure as a hash function. If k is given, it specifies the initial capacity of the hash table.

Scheme Procedure: make-eqv-hashtable
Scheme Procedure: make-eqv-hashtable k

Returns a new hash table that uses eqv? to compare keys and Guile’s hashv procedure as a hash function. If k is given, it specifies the initial capacity of the hash table.

Scheme Procedure: make-hashtable hash-function equiv
Scheme Procedure: make-hashtable hash-function equiv k

Returns a new hash table that uses equiv to compare keys and hash-function as a hash function. equiv must be a procedure that accepts two arguments and returns a true value if they are equivalent, #f otherwise; hash-function must be a procedure that accepts one argument and returns a non-negative integer.

If k is given, it specifies the initial capacity of the hash table.

Scheme Procedure: hashtable? obj

Returns #t if obj is an R6RS hash table, #f otherwise.

Scheme Procedure: hashtable-size hashtable

Returns the number of keys currently in the hash table hashtable.

Scheme Procedure: hashtable-ref hashtable key default

Returns the value associated with key in the hash table hashtable, or default if none is found.

Scheme Procedure: hashtable-set! hashtable key obj

Associates the key key with the value obj in the hash table hashtable, and returns an unspecified value. An &assertion condition is raised if hashtable is immutable.

Scheme Procedure: hashtable-delete! hashtable key

Removes any association found for the key key in the hash table hashtable, and returns an unspecified value. An &assertion condition is raised if hashtable is immutable.

Scheme Procedure: hashtable-contains? hashtable key

Returns #t if the hash table hashtable contains an association for the key key, #f otherwise.

Scheme Procedure: hashtable-update! hashtable key proc default

Associates with key in the hash table hashtable the result of calling proc, which must be a procedure that takes one argument, on the value currently associated key in hashtable—or on default if no such association exists. An &assertion condition is raised if hashtable is immutable.

Scheme Procedure: hashtable-copy hashtable
Scheme Procedure: hashtable-copy hashtable mutable

Returns a copy of the hash table hashtable. If the optional argument mutable is provided and is a true value, the new hash table will be mutable.

Scheme Procedure: hashtable-clear! hashtable
Scheme Procedure: hashtable-clear! hashtable k

Removes all of the associations from the hash table hashtable. The optional argument k, which specifies a new capacity for the hash table, is accepted by Guile’s (rnrs hashtables) implementation, but is ignored.

Scheme Procedure: hashtable-keys hashtable

Returns a vector of the keys with associations in the hash table hashtable, in an unspecified order.

Scheme Procedure: hashtable-entries hashtable

Return two values—a vector of the keys with associations in the hash table hashtable, and a vector of the values to which these keys are mapped, in corresponding but unspecified order.

Scheme Procedure: hashtable-equivalence-function hashtable

Returns the equivalence predicated use by hashtable. This procedure returns eq? and eqv?, respectively, for hash tables created by make-eq-hashtable and make-eqv-hashtable.

Scheme Procedure: hashtable-hash-function hashtable

Returns the hash function used by hashtable. For hash tables created by make-eq-hashtable or make-eqv-hashtable, #f is returned.

Scheme Procedure: hashtable-mutable? hashtable

Returns #t if hashtable is mutable, #f otherwise.

A number of hash functions are provided for convenience:

Scheme Procedure: equal-hash obj

Returns an integer hash value for obj, based on its structure and current contents. This hash function is suitable for use with equal? as an equivalence function.

Scheme Procedure: string-hash string
Scheme Procedure: symbol-hash symbol

These procedures are identical to the ones provided by Guile’s core library. See Hash Table Reference, for documentation.

Scheme Procedure: string-ci-hash string

Returns an integer hash value for string based on its contents, ignoring case. This hash function is suitable for use with string-ci=? as an equivalence function.


Next: , Previous: , Up: R6RS Standard Libraries   [Contents][Index]