Next: , Previous: , Up: stdlib hashtable   [Index]


5.13.2 Procedures

Procedure: hashtable? obj

Return #t if obj is a hashtable, #f otherwise.

Procedure: hashtable-size hashtable

Return the number of keys contained in hashtable as an exact integer object.

Procedure: hashtable-ref hashtable key
Procedure: hashtable-ref hashtable key default

Return the value in hashtable associated with key. If hashtable does not contain an association for key, default is returned.

As Vicare extension: when default is not used, it defaults to the sentinel object. When in doubt: we should always use the sentinel object as default argument. See The sentinel object.

Procedure: hashtable-set! hashtable key obj

Change hashtable to associate key with obj, adding a new association or replacing any existing association for key, and returns unspecified values.

As Vicare extension: if obj is (void) an exception is raised with condition object type &procedure-argument-violation; the void value is to be used as sentinel value for hash tables.

Procedure: hashtable-delete! hashtable key

Remove any association for key within hashtable; if there is no association for key: do nothing.

As Vicare extension return two values:

Procedure: hashtable-contains? hashtable key

Return #t if hashtable contains an association for key, #f otherwise.

Procedure: hashtable-update! hashtable key proc default

proc should accept one argument, should return a single value, and should not mutate hashtable.

The hashtable-update! procedure applies proc to the value in hashtable associated with key, or to default if hashtable does not contain an association for key. The hashtable is then changed to associate key with the value returned by proc.

The behavior of hashtable-update! is equivalent to the following code, but may be implemented more efficiently in cases where the implementation can avoid multiple lookups of the same key:

(hashtable-set!
  hashtable key
  (proc (hashtable-ref
         hashtable key default)))
Procedure: hashtable-copy hashtable
Procedure: hashtable-copy hashtable mutable

Return a copy of hashtable. If the mutable argument is provided and is true, the returned hashtable is mutable; otherwise it is immutable.

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

Remove all associations from hashtable and returns unspecified values.

If a second argument is given, the current capacity of the hashtable is reset to approximately k elements.

Procedure: hashtable-keys hashtable

Return a vector of all keys in hashtable. The order of the vector is unspecified.

Procedure: hashtable-entries hashtable

Return two values, a vector of the keys in hashtable, and a vector of the corresponding values.

Example:

(let ((h (make-eqv-hashtable)))
  (hashtable-set! h 1 'one)
  (hashtable-set! h 2 'two)
  (hashtable-set! h 3 'three)
  (hashtable-entries h))
⇒ #(1 2 3) #(one two three) ; two return values

the order of the entries in the result vectors is not known.


Next: , Previous: , Up: stdlib hashtable   [Index]