Next: Structures Up: Basic Data Extensions Previous: Promises

# Hash Tables

MzScheme provides efficient built-in hash tables. Key comparisons use `eq?`.

- `(make-hash-table)` creates and returns a new hash table.
- `(make-hash-table-weak)` creates a hash table with weakly-held keys (see section 12.1).
- `(hash-table? v)` returns `#t` if v was created by `make-hash-table` or `make-hash-table-weak`, `#f` otherwise.
- `(hash-table-put! hash-table key-v v)` maps key-v to v in hash-table, overwriting any existing mapping for key-v.
- `(hash-table-get hash-table key-v [failure-thunk])` returns the value for key-v in hash-table. If no value is found for key-v, then the result of invoking failure-thunk (a procedure of no arguments) is returned. If failure-thunk is not provided, the `exn:application:mismatch` exception is raised if no value is found for key-v.
- `(hash-table-remove! hash-table key-v)` removes the value mapping for key-v if it exists in hash-table.
- `(hash-table-map hash-table proc)` applies the procedure proc to each element in hash-table, accumulating the results into a list. The procedure proc must take two arguments: a key and its value.
- `(hash-table-for-each hash-table proc)` applies the procedure proc to each element in hash-table (for the side-effects of proc) and returns void. The procedure proc must take two arguments: a key and its value.