cosmetic surgery on loop figure; a few minor changes elsewhere
[clqr.git] / clqr-hash-tables.tex
blob531f8b1a5141c151db9b5f00796e1dc46d1cec9a
1 % Copyright (C) 2008 Bert Burgemeister
3 % Permission is granted to copy, distribute and/or modify this
4 % document under the terms of the GNU Free Documentation License,
5 % Version 1.2 or any later version published by the Free Software
6 % Foundation; with no Invariant Sections, no Front-Cover Texts and
7 % no Back-Cover Texts. For details see file COPYING.
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 \section{Hash Tables}
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 Key-value storage similar to hash tables can as well be achieved using
14 association lists and property lists; see
15 pages \pageref{section:Association Lists} and \pageref{:property_lists}.
18 \begin{LIST}{1cm}
20 \IT{(\FU*{HASH-TABLE-P} \VAR{foo})}
22 Return \retval{\T} if \VAR{foo} is of type \kwd{hash-table}.
25 \IT{(\FU*{MAKE-HASH-TABLE}
26 \orGOO{\kwd{:test}\Goo{\FU{eq}\XOR \FU{eql}\XOR
27 \FU{equal}}\DF{\kwd{eql}}\\
28 \kwd{:size} \VAR{ int}\\
29 \kwd{:rehash-size} \VAR{ int}\\
30 \kwd{:rehash-threshold} \VAR{ int}}{\}})}
32 Make a \retval{hash table}.
35 \IT{(\FU*{HASH-TABLE-TEST} \VAR{hash-table})}
37 \retval{Test function} used in \VAR{hash-table}.
40 \IT{(\FU*{GETHASH} \VAR{key} \VAR{hash-table} \Op{\VAR{default}\DF{\NIL}})}
42 Return \retval{object} with \VAR{key} if any or \retval{\VAR{default}}
43 otherwise; and \retvalii{\T} if found, \retvalii{\NIL}
44 otherwise. \kwd{setf}able.
47 \IT{(\FU*{HASH-TABLE-COUNT} \VAR{hash-table})}
49 \retval{Number of entries} in \VAR{hash-table}.
52 \IT{(\FU*{REMHASH} \VAR{key} \DES{\VAR{hash-table}})}
54 Remove from \VAR{hash-table} entry with \VAR{key} and return
55 \retval{\T} if it existed. Return \retval{\NIL} otherwise.
58 \IT{(\FU*{CLRHASH} \DES{\VAR{hash-table}})}
60 Empty \retval{\VAR{hash-table}}.
63 \IT{(\FU*{MAPHASH} \VAR{function} \VAR{hash-table})}
65 Iterate over \VAR{hash-table} calling \VAR{function} on key
66 and value. Return \retval{\NIL}.
69 \IT{(\MC*{WITH-HASH-TABLE-ITERATOR} (\VAR{foo} \VAR{hash-table})
70 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})} \PROGN{\VAR{form}})}
72 Return \retval{values of \VAR{form}s}. In \VAR{form}s,
73 invocations of (\VAR{foo}) return: \T\ if an entry is returned;
74 its key; its value.
77 \IT{\arrGOO{(\FU*{HASH-TABLE-SIZE} \VAR{ hash-table})\\
78 (\FU*{HASH-TABLE-REHASH-SIZE} \VAR{ hash-table})\\
79 (\FU*{HASH-TABLE-REHASH-THRESHOLD} \VAR{ hash-table})}{.}}
81 Current \retval{size}, \retval{rehash-size}, or
82 \retval{rehash-threshold}, respectively, as used in \FU{make-hash-table}.
85 \IT{(\FU*{SXHASH} \VAR{foo})}
87 \retval{Hash code} unique for any argument \FU{equal} \VAR{foo}.
90 \end{LIST}