Hashutils - Hash table utility library

version 0.1

Shiro Kawai (shiro@acm.org)


Table of Contents


1. Overview

This is a collection of small functions I found handy to have.

The newest version of the library is 0.1. It can be obtained from http://practical-scheme.net/vault/hashutils-0.1.tar.gz.

If you read this document off-line, check out the newest document online. http://practical-scheme.net/vault/hashutils.html.

Once you get the package, you can install it by the following procedure.

2. Functions

To use the functions, load and import hashutils module:

   (require "hashutils")
   (import hashutils)

Or, if you're using modutils,

   (use-module hashutils)

Function: hash-table INITARGS KEY VALUE ...
A convenient hash table constructor. It is useful when you want to embed a pre-defined hashtable in your code.

A hash table is created by (apply make-hash-table INITARGS). Then, given KEY and VALUE pairs are inserted to the hash table. It is an error to give a KEY without accompanying VALUE.

  (define *command-table*
     (hash-table ()
                 'help  (list help "show help")
                 'quit  (list (lambda () (exit 0)) "quit program")
                 'ls    (list cmd-list "list elements")))

  (define *abbrev-table*
     (hash-table `(,equal?)
                 "RCS"  "Revision Control System"
                 "CVS"  "Concurrent Versions System"))

Function: hash-table-fold HASH PROC INIT
A generalized iterator over a hash table HASH.

For each key-value pair of the hash table, a procedure PROC is called with three arguments: a key, a value, and a partial result returned by the previous call of PROC. For the first key-value pair, INIT is passed as the third argument. Returns the result of the last call of PROC.

For example, the following call returns a list of keys whose value equals "N/A".

  (hash-table-fold *table*
                   (lambda (k v r)
                     (if (equal? value "N/A")
                         (cons k r)
                         r))
                   '())

Function: hash-table-keys HASH
Function: hash-table-values HASH
Returns a list of keys or values of a hash table HASH.

Function: hash-table-push! HASH KEY VALUE
Conses VALUE to the current value of KEY in a hash table HASH. If no value is associated to the key, (list VALUE) is put as the value.

Index

Jump to: h

h

  • hash-table
  • hash-table-fold
  • hash-table-keys
  • hash-table-push!
  • hash-table-values

  • This document was generated on 17 October 2000 using texi2html 1.56k.