comparison lispref/hash.texi @ 89910:548375b6b1f8

Update unicode branch
author Miles Bader <miles@gnu.org>
date Mon, 19 Apr 2004 07:01:43 +0000
parents 375f2633d815
children 59dcbfe97385
comparison
equal deleted inserted replaced
89909:68c22ea6027c 89910:548375b6b1f8
74 default is @code{eql}; @code{eq} and @code{equal} are other 74 default is @code{eql}; @code{eq} and @code{equal} are other
75 alternatives: 75 alternatives:
76 76
77 @table @code 77 @table @code
78 @item eql 78 @item eql
79 Keys which are numbers are ``the same'' if they are equal in value; 79 Keys which are numbers are ``the same'' if they are @code{equal}, that
80 otherwise, two distinct objects are never ``the same''. 80 is, if they are equal in value and either both are integers or both
81 are floating point numbers; otherwise, two distinct objects are never
82 ``the same''.
81 83
82 @item eq 84 @item eq
83 Any two distinct Lisp objects are ``different'' as keys. 85 Any two distinct Lisp objects are ``different'' as keys.
84 86
85 @item equal 87 @item equal
94 The weakness of a hash table specifies whether the presence of a key or 96 The weakness of a hash table specifies whether the presence of a key or
95 value in the hash table preserves it from garbage collection. 97 value in the hash table preserves it from garbage collection.
96 98
97 The value, @var{weak}, must be one of @code{nil}, @code{key}, 99 The value, @var{weak}, must be one of @code{nil}, @code{key},
98 @code{value}, @code{key-or-value}, @code{key-and-value}, or @code{t} 100 @code{value}, @code{key-or-value}, @code{key-and-value}, or @code{t}
99 which is an alias for @code{key-or-value}. If @var{weak} is @code{key} 101 which is an alias for @code{key-and-value}. If @var{weak} is @code{key}
100 then the hash table does not prevent its keys from being collected as 102 then the hash table does not prevent its keys from being collected as
101 garbage (if they are not referenced anywhere else); if a particular key 103 garbage (if they are not referenced anywhere else); if a particular key
102 does get collected, the corresponding association is removed from the 104 does get collected, the corresponding association is removed from the
103 hash table. 105 hash table.
104 106
105 If @var{weak} is @code{value}, then the hash table does not prevent 107 If @var{weak} is @code{value}, then the hash table does not prevent
106 values from being collected as garbage (if they are not referenced 108 values from being collected as garbage (if they are not referenced
107 anywhere else); if a particular value does get collected, the 109 anywhere else); if a particular value does get collected, the
108 corresponding association is removed from the hash table. 110 corresponding association is removed from the hash table.
109 111
110 If @var{weak} is @code{key-or-value} or @code{t}, the hash table does 112 If @var{weak} is @code{key-and-value} or @code{t}, both the key and
111 not protect either keys or values from garbage collection; if either 113 the value must be live in order to preserve the association. Thus,
112 one is collected as garbage, the association is removed. 114 the hash table does not protect either keys or values from garbage
113 115 collection; if either one is collected as garbage, that removes the
114 If @var{weak} is @code{key-and-value}, associations are removed from 116 association.
115 the hash table when both their key and value would be collected as 117
116 garbage, again not considering references to the key and value from 118 If @var{weak} is @code{key-or-value}, either the key or
117 weak hash tables. 119 the value can preserve the association. Thus, associations are
120 removed from the hash table when both their key and value would be
121 collected as garbage (if not for references from weak hash tables).
118 122
119 The default for @var{weak} is @code{nil}, so that all keys and values 123 The default for @var{weak} is @code{nil}, so that all keys and values
120 referenced in the hash table are preserved from garbage collection. If 124 referenced in the hash table are preserved from garbage collection.
121 @var{weak} is @code{t}, neither keys nor values are protected (that is,
122 both are weak).
123 125
124 @item :size @var{size} 126 @item :size @var{size}
125 This specifies a hint for how many associations you plan to store in the 127 This specifies a hint for how many associations you plan to store in the
126 hash table. If you know the approximate number, you can make things a 128 hash table. If you know the approximate number, you can make things a
127 little more efficient by specifying it this way. If you specify too 129 little more efficient by specifying it this way. If you specify too
156 @defun makehash &optional test 158 @defun makehash &optional test
157 This is equivalent to @code{make-hash-table}, but with a different style 159 This is equivalent to @code{make-hash-table}, but with a different style
158 argument list. The argument @var{test} specifies the method 160 argument list. The argument @var{test} specifies the method
159 of key lookup. 161 of key lookup.
160 162
161 If you want to specify other parameters, you should use 163 This function is obsolete. Use @code{make-hash-table} instead.
162 @code{make-hash-table}.
163 @end defun 164 @end defun
164 165
165 @node Hash Access 166 @node Hash Access
166 @section Hash Table Access 167 @section Hash Table Access
167 168
185 @tindex remhash 186 @tindex remhash
186 @defun remhash key table 187 @defun remhash key table
187 This function removes the association for @var{key} from @var{table}, if 188 This function removes the association for @var{key} from @var{table}, if
188 there is one. If @var{key} has no association, @code{remhash} does 189 there is one. If @var{key} has no association, @code{remhash} does
189 nothing. 190 nothing.
191
192 @b{Common Lisp note:} In Common Lisp, @code{remhash} returns
193 non-@code{nil} if it actually removed an association and @code{nil}
194 otherwise. In Emacs Lisp, @code{remhash} always returns @code{nil}.
190 @end defun 195 @end defun
191 196
192 @tindex clrhash 197 @tindex clrhash
193 @defun clrhash table 198 @defun clrhash table
194 This function removes all the associations from hash table @var{table}, 199 This function removes all the associations from hash table @var{table},
195 so that it becomes empty. This is also called @dfn{clearing} the hash 200 so that it becomes empty. This is also called @dfn{clearing} the hash
196 table. 201 table.
202
203 @b{Common Lisp note:} In Common Lisp, @code{clrhash} returns the empty
204 @var{table}. In Emacs Lisp, it returns @code{nil}.
197 @end defun 205 @end defun
198 206
199 @tindex maphash 207 @tindex maphash
208 @anchor{Definition of maphash}
200 @defun maphash function table 209 @defun maphash function table
201 This function calls @var{function} once for each of the associations in 210 This function calls @var{function} once for each of the associations in
202 @var{table}. The function @var{function} should accept two 211 @var{table}. The function @var{function} should accept two
203 arguments---a @var{key} listed in @var{table}, and its associated 212 arguments---a @var{key} listed in @var{table}, and its associated
204 @var{value}. 213 @var{value}.
253 262
254 If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash 263 If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash
255 @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer. 264 @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer.
256 265
257 If the two objects are not equal, the values returned by @code{sxhash} 266 If the two objects are not equal, the values returned by @code{sxhash}
258 are usually different, but not always; but once in a rare while, by 267 are usually different, but not always; once in a rare while, by luck,
259 luck, you will encounter two distinct-looking objects that give the same 268 you will encounter two distinct-looking objects that give the same
260 result from @code{sxhash}. 269 result from @code{sxhash}.
261 @end defun 270 @end defun
262 271
263 This example creates a hash table whose keys are strings that are 272 This example creates a hash table whose keys are strings that are
264 compared case-insensitively. 273 compared case-insensitively.
332 341
333 @tindex hash-table-size 342 @tindex hash-table-size
334 @defun hash-table-size table 343 @defun hash-table-size table
335 This returns the current nominal size of @var{table}. 344 This returns the current nominal size of @var{table}.
336 @end defun 345 @end defun
346
347 @ignore
348 arch-tag: 3b5107f9-d2f0-47d5-ad61-3498496bea0e
349 @end ignore