annotate doc/lispref/hash.texi @ 109867:7b3550d93e3a

support for fit-width
author Joakim <joakim@localhost.localdomain>
date Sun, 27 Jun 2010 02:18:55 +0200
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84072
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
3 @c Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106637
diff changeset
4 @c 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
84072
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 @c See the file elisp.texi for copying conditions.
84116
0ba80d073e27 (setfilename): Go up one more level to ../../info.
Glenn Morris <rgm@gnu.org>
parents: 84072
diff changeset
6 @setfilename ../../info/hash
84072
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 @node Hash Tables, Symbols, Sequences Arrays Vectors, Top
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 @chapter Hash Tables
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 @cindex hash tables
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 @cindex lookup tables
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 A hash table is a very fast kind of lookup table, somewhat like an
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 alist (@pxref{Association Lists}) in that it maps keys to
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14 corresponding values. It differs from an alist in these ways:
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 @itemize @bullet
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 @item
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 Lookup in a hash table is extremely fast for large tables---in fact, the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 time required is essentially @emph{independent} of how many elements are
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 stored in the table. For smaller tables (a few tens of elements)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 alists may still be faster because hash tables have a more-or-less
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 constant overhead.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 @item
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 The correspondences in a hash table are in no particular order.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 @item
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 There is no way to share structure between two hash tables,
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 the way two alists can share a common tail.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 @end itemize
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 Emacs Lisp provides a general-purpose hash table data type, along
106637
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
33 with a series of functions for operating on them. Hash tables have a
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
34 special printed representation, which consists of @samp{#s} followed
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
35 by a list specifying the hash table properties and contents.
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
36 @xref{Creating Hash}. (Note that the term ``hash notation'', which
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
37 refers to the initial @samp{#} character used in the printed
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
38 representations of objects with no read representation, has nothing to
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
39 do with the term ``hash table''. @xref{Printed Representation}.)
84072
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 Obarrays are also a kind of hash table, but they are a different type
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 of object and are used only for recording interned symbols
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 (@pxref{Creating Symbols}).
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 @menu
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 * Creating Hash:: Functions to create hash tables.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 * Hash Access:: Reading and writing the hash table contents.
103822
d4b0e49916d2 (Hash Tables): End menu description with period.
Glenn Morris <rgm@gnu.org>
parents: 100974
diff changeset
48 * Defining Hash:: Defining new comparison methods.
84072
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 * Other Hash:: Miscellaneous.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 @end menu
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 @node Creating Hash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 @section Creating Hash Tables
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 @cindex creating hash tables
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 The principal function for creating a hash table is
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 @code{make-hash-table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 @defun make-hash-table &rest keyword-args
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 This function creates a new hash table according to the specified
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 arguments. The arguments should consist of alternating keywords
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 (particular symbols recognized specially) and values corresponding to
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 them.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 Several keywords make sense in @code{make-hash-table}, but the only two
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 that you really need to know about are @code{:test} and @code{:weakness}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 @table @code
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 @item :test @var{test}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 This specifies the method of key lookup for this hash table. The
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 default is @code{eql}; @code{eq} and @code{equal} are other
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 alternatives:
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 @table @code
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 @item eql
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 Keys which are numbers are ``the same'' if they are @code{equal}, that
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 is, if they are equal in value and either both are integers or both
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 are floating point numbers; otherwise, two distinct objects are never
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 ``the same.''
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 @item eq
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 Any two distinct Lisp objects are ``different'' as keys.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 @item equal
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 Two Lisp objects are ``the same,'' as keys, if they are equal
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 according to @code{equal}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 @end table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 You can use @code{define-hash-table-test} (@pxref{Defining Hash}) to
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 define additional possibilities for @var{test}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 @item :weakness @var{weak}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 The weakness of a hash table specifies whether the presence of a key or
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 value in the hash table preserves it from garbage collection.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 The value, @var{weak}, must be one of @code{nil}, @code{key},
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 @code{value}, @code{key-or-value}, @code{key-and-value}, or @code{t}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 which is an alias for @code{key-and-value}. If @var{weak} is @code{key}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 then the hash table does not prevent its keys from being collected as
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 garbage (if they are not referenced anywhere else); if a particular key
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 does get collected, the corresponding association is removed from the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 hash table.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 If @var{weak} is @code{value}, then the hash table does not prevent
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 values from being collected as garbage (if they are not referenced
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 anywhere else); if a particular value does get collected, the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 corresponding association is removed from the hash table.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 If @var{weak} is @code{key-and-value} or @code{t}, both the key and
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 the value must be live in order to preserve the association. Thus,
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 the hash table does not protect either keys or values from garbage
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 collection; if either one is collected as garbage, that removes the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 association.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 If @var{weak} is @code{key-or-value}, either the key or
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 the value can preserve the association. Thus, associations are
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 removed from the hash table when both their key and value would be
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 collected as garbage (if not for references from weak hash tables).
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 The default for @var{weak} is @code{nil}, so that all keys and values
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 referenced in the hash table are preserved from garbage collection.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 @item :size @var{size}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 This specifies a hint for how many associations you plan to store in the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 hash table. If you know the approximate number, you can make things a
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 little more efficient by specifying it this way. If you specify too
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 small a size, the hash table will grow automatically when necessary, but
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 doing that takes some extra time.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 The default size is 65.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 @item :rehash-size @var{rehash-size}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 When you add an association to a hash table and the table is ``full,''
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 it grows automatically. This value specifies how to make the hash table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 larger, at that time.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 If @var{rehash-size} is an integer, it should be positive, and the hash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 table grows by adding that much to the nominal size. If
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 @var{rehash-size} is a floating point number, it had better be greater
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 than 1, and the hash table grows by multiplying the old size by that
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 number.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 The default value is 1.5.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 @item :rehash-threshold @var{threshold}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 This specifies the criterion for when the hash table is ``full'' (so
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 it should be made larger). The value, @var{threshold}, should be a
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 positive floating point number, no greater than 1. The hash table is
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 ``full'' whenever the actual number of entries exceeds this fraction
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 of the nominal size. The default for @var{threshold} is 0.8.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 @end table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 @defun makehash &optional test
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 This is equivalent to @code{make-hash-table}, but with a different style
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 argument list. The argument @var{test} specifies the method
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 of key lookup.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 This function is obsolete. Use @code{make-hash-table} instead.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161
106637
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
162 You can also create a new hash table using the printed representation
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
163 for hash tables. The Lisp reader can read this printed
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
164 representation, provided each element in the specified hash table has
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
165 a valid read syntax (@pxref{Printed Representation}). For instance,
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
166 the following specifies a new hash table containing the keys
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
167 @code{key1} and @code{key2} (both symbols) associated with @code{val1}
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
168 (a symbol) and @code{300} (a number) respectively.
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
169
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
170 @example
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
171 #s(hash-table size 30 data (key1 val1 key2 300))
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
172 @end example
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
173
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
174 @noindent
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
175 The printed representation for a hash table consists of @samp{#s}
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
176 followed by a list beginning with @samp{hash-table}. The rest of the
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
177 list should consist of zero or more property-value pairs specifying
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
178 the hash table's properties and initial contents. The properties and
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
179 values are read literally. Valid property names are @code{size},
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
180 @code{test}, @code{weakness}, @code{rehash-size},
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
181 @code{rehash-threshold}, and @code{data}. The @code{data} property
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
182 should be a list of key-value pairs for the initial contents; the
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
183 other properties have the same meanings as the matching
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
184 @code{make-hash-table} keywords (@code{:size}, @code{:test}, etc.),
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
185 described above.
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
186
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
187 Note that you cannot specify a hash table whose initial contents
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
188 include objects that have no read syntax, such as buffers and frames.
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
189 Such objects may be added to the hash table after it is created.
16b0f9d4c0c5 * frames.texi (Resources): Describe inhibit-x-resources.
Chong Yidong <cyd@stupidchicken.com>
parents: 103822
diff changeset
190
84072
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 @node Hash Access
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 @section Hash Table Access
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 This section describes the functions for accessing and storing
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 associations in a hash table. In general, any Lisp object can be used
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 as a hash key, unless the comparison method imposes limits. Any Lisp
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 object can also be used as the value.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 @defun gethash key table &optional default
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 This function looks up @var{key} in @var{table}, and returns its
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 associated @var{value}---or @var{default}, if @var{key} has no
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 association in @var{table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 @defun puthash key value table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 This function enters an association for @var{key} in @var{table}, with
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 value @var{value}. If @var{key} already has an association in
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 @var{table}, @var{value} replaces the old associated value.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 @defun remhash key table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 This function removes the association for @var{key} from @var{table}, if
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 there is one. If @var{key} has no association, @code{remhash} does
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 nothing.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 @b{Common Lisp note:} In Common Lisp, @code{remhash} returns
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 non-@code{nil} if it actually removed an association and @code{nil}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 otherwise. In Emacs Lisp, @code{remhash} always returns @code{nil}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 @defun clrhash table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 This function removes all the associations from hash table @var{table},
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 so that it becomes empty. This is also called @dfn{clearing} the hash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 table.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 @b{Common Lisp note:} In Common Lisp, @code{clrhash} returns the empty
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 @var{table}. In Emacs Lisp, it returns @code{nil}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230 @defun maphash function table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 @anchor{Definition of maphash}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 This function calls @var{function} once for each of the associations in
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 @var{table}. The function @var{function} should accept two
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234 arguments---a @var{key} listed in @var{table}, and its associated
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 @var{value}. @code{maphash} returns @code{nil}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238 @node Defining Hash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239 @section Defining Hash Comparisons
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 @cindex hash code
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
241 @cindex define hash comparisons
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
243 You can define new methods of key lookup by means of
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244 @code{define-hash-table-test}. In order to use this feature, you need
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 to understand how hash tables work, and what a @dfn{hash code} means.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 You can think of a hash table conceptually as a large array of many
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
248 slots, each capable of holding one association. To look up a key,
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
249 @code{gethash} first computes an integer, the hash code, from the key.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250 It reduces this integer modulo the length of the array, to produce an
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 index in the array. Then it looks in that slot, and if necessary in
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 other nearby slots, to see if it has found the key being sought.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254 Thus, to define a new method of key lookup, you need to specify both a
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 function to compute the hash code from a key, and a function to compare
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 two keys directly.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 @defun define-hash-table-test name test-fn hash-fn
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 This function defines a new hash table test, named @var{name}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 After defining @var{name} in this way, you can use it as the @var{test}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 argument in @code{make-hash-table}. When you do that, the hash table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 will use @var{test-fn} to compare key values, and @var{hash-fn} to compute
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 a ``hash code'' from a key value.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 The function @var{test-fn} should accept two arguments, two keys, and
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
267 return non-@code{nil} if they are considered ``the same.''
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269 The function @var{hash-fn} should accept one argument, a key, and return
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 an integer that is the ``hash code'' of that key. For good results, the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 function should use the whole range of integer values for hash codes,
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
272 including negative integers.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
273
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
274 The specified functions are stored in the property list of @var{name}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
275 under the property @code{hash-table-test}; the property value's form is
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
276 @code{(@var{test-fn} @var{hash-fn})}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
277 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
278
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
279 @defun sxhash obj
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
280 This function returns a hash code for Lisp object @var{obj}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
281 This is an integer which reflects the contents of @var{obj}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
282 and the other Lisp objects it points to.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
283
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
284 If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
285 @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
286
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
287 If the two objects are not equal, the values returned by @code{sxhash}
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
288 are usually different, but not always; once in a rare while, by luck,
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
289 you will encounter two distinct-looking objects that give the same
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
290 result from @code{sxhash}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
291 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
292
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
293 This example creates a hash table whose keys are strings that are
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
294 compared case-insensitively.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
295
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
296 @example
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
297 (defun case-fold-string= (a b)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
298 (compare-strings a nil nil b nil nil t))
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
299 (defun case-fold-string-hash (a)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
300 (sxhash (upcase a)))
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
301
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
302 (define-hash-table-test 'case-fold
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
303 'case-fold-string= 'case-fold-string-hash)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
304
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
305 (make-hash-table :test 'case-fold)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
306 @end example
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
307
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
308 Here is how you could define a hash table test equivalent to the
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
309 predefined test value @code{equal}. The keys can be any Lisp object,
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
310 and equal-looking objects are considered the same key.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
311
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
312 @example
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
313 (define-hash-table-test 'contents-hash 'equal 'sxhash)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
314
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
315 (make-hash-table :test 'contents-hash)
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
316 @end example
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
317
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
318 @node Other Hash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
319 @section Other Hash Table Functions
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
320
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
321 Here are some other functions for working with hash tables.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
322
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
323 @defun hash-table-p table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
324 This returns non-@code{nil} if @var{table} is a hash table object.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
325 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
326
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
327 @defun copy-hash-table table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
328 This function creates and returns a copy of @var{table}. Only the table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
329 itself is copied---the keys and values are shared.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
330 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
331
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
332 @defun hash-table-count table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
333 This function returns the actual number of entries in @var{table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
334 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
335
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
336 @defun hash-table-test table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
337 This returns the @var{test} value that was given when @var{table} was
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
338 created, to specify how to hash and compare keys. See
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
339 @code{make-hash-table} (@pxref{Creating Hash}).
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
340 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
341
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
342 @defun hash-table-weakness table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
343 This function returns the @var{weak} value that was specified for hash
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
344 table @var{table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
345 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
346
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
347 @defun hash-table-rehash-size table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
348 This returns the rehash size of @var{table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
349 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
350
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
351 @defun hash-table-rehash-threshold table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
352 This returns the rehash threshold of @var{table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
353 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
354
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
355 @defun hash-table-size table
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
356 This returns the current nominal size of @var{table}.
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
357 @end defun
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
358
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
359 @ignore
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
360 arch-tag: 3b5107f9-d2f0-47d5-ad61-3498496bea0e
2b28589bd662 Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
361 @end ignore