annotate lispref/hash.texi @ 47576:b31c8ab7336a

Sync with version 2.0.20. Lengthy ChangeLog follows: 2002-09-22 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> Version 2.0.20 released. 2002-09-20 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> * net/tramp.el (tramp-completion-function-alist): Escape open paren in docstring. (tramp-user-regexp, tramp-host-regexp): Allow empty strings. (tramp-handle-insert-file-contents): Call tramp-message-for-buffer instead of tramp-message. (tramp-open-connection-rsh): Handle empty string as user name. (tramp-open-connection-su): Handle empty string as host name. Handle nil user name. (tramp-handle-file-local-copy, tramp-handle-write-region) (tramp-completion-handle-file-name-all-completions) (tramp-open-connection-telnet, tramp-open-connection-rsh) (tramp-open-connection-su, tramp-post-connection) (tramp-maybe-open-connection, tramp-method-out-of-band-p) (tramp-get-connection-function, tramp-get-remote-sh) (tramp-get-rsh-program, tramp-get-rsh-args) (tramp-get-rcp-program, tramp-get-rcp-args) (tramp-get-rcp-keep-date-arg, tramp-get-su-program) (tramp-get-su-args, tramp-get-telnet-program) (tramp-get-telnet-args): Use `tramp-find-method', perhaps require additional args USER, HOST. (tramp-action-password, tramp-open-connection-telnet) (tramp-open-connection-su, tramp-open-connection-multi) (tramp-method-out-of-band-p): `tramp-method-out-of-band-p' now takes USER and HOST arguments, to be able to use `tramp-find-method'. Update callers. (tramp-find-method): New function. 2002-09-20 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-insert-directory): Handle "--dired" in SWITCHES (by removing it). 2002-09-18 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-file-name-handler): Add `file-remote-p' property. 2002-09-17 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (top-level): Maybe autoload uudecode-decode-region. 2002-09-16 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-bug): Add tramp-methods. 2002-09-16 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-methods): Update docstring: tramp-encoding-command, tramp-decoding-command, tramp-encoding-function and tramp-decoding-function are not parameters anymore. (tramp-uuencode-region): Autoload it. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> Version 2.0.19 released. * net/tramp-uu.el: New file, implements uuencode in Lisp. * net/tramp.el (tramp-coding-commands): Use `tramp-uuencode-region' as local encoder for the uuencode based entries. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-write-region): Wrong parens. 2002-09-13 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> Version 2.0.18 released. * net/tramp.el (tramp-perl-decode): Perl changes to accomodate older versions of Perl. Now tested with 5.004. Suggestion from Michael Albinus. 2002-09-12 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-find-inline-encoding): Call tramp-call-local-coding-command with nil for INPUT and OUTPUT. (tramp-call-local-coding-command): OUTPUT equals nil means to discard the output. INPUT equals nil means /dev/null. 2002-09-12 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-encoding-shell): Default to environment variable COMSPEC on Windows. (tramp-handle-write-region): More debugging output. (tramp-find-inline-encoding): Ditto. 2002-09-11 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-handle-file-name-all-completions): Define `result1'. (tramp-parse-hosts-group): Discard IPv6 entries. 2002-09-11 Kai Gro?ohann <grossjoh@ls6.informatik.uni-dortmund.de> * net/tramp.el (tramp-post-connection): Only send Perl mime-encode/decode implementations when using inline method. (tramp-handle-file-local-copy) (tramp-handle-write-region, tramp-post-connection) (tramp-coding-commands, tramp-find-inline-encoding): For the inline encodings, distinguish between local and remote commands, instead of between commands and functions. (The local commands can be functions, too.) If the local host is a Windows machine, we can't expect the same commands to work there as on the remote host. (tramp-call-local-coding-command): New function for calling local encoding and decoding commands. (tramp-set-remote-encoding, tramp-get-remote-encoding) (tramp-set-remote-decoding, tramp-get-remote-decoding) (tramp-set-local-encoding, tramp-get-local-encoding) (tramp-set-local-decoding, tramp-get-local-decoding): New functions. (tramp-get-encoding-command, tramp-set-encoding-command) (tramp-get-decoding-command, tramp-set-decoding-command) (tramp-get-encoding-function, tramp-set-encoding-function) (tramp-get-decoding-function, tramp-set-decoding-function): Old functions, removed. 2002-09-10 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-open-connection-setup-interactive-shell): Change command to invoke /bin/sh slightly to make it compatible with the `rc' shell. Suggested by Daniel Pittman. 2002-09-10 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-handle-write-region): Added missing `)'. Hope it's the right place. 2002-09-09 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-open-connection-setup-interactive-shell): Do "exec env PS1='$ ' /bin/sh" instead of just "exec /bin/sh" in order to get a sane shell prompt. If people have ${CWD}, say, in their shell prompt, then the default login shell might display something harmless, but the /bin/sh will display a dollar sign which confused the subsequent prompt recognition. (tramp-multi-action-password): More debugging output. (tramp-encoding-shell): Renamed from tramp-sh-program. More documentation. Default to cmd.exe on Windows NT. (tramp-encoding-command-switch): New variable. Use instead of hard-wired "-c" which is only good for /bin/sh. (tramp-encoding-reads-stdin): New variable. If t, commands are called like "/bin/sh -c COMMAND <INPUT", if nil, they are called like "/bin/sh -c COMMAND INPUT", ie the input file is the last argument. (tramp-multi-sh-program): Always default to tramp-encoding-shell. (tramp-handle-file-local-copy, tramp-handle-write-region): Respect tramp-encoding-shell and friends. (tramp-find-inline-encoding): Use new-style calls for checking if the local commands work. 2002-09-07 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-methods): Remove `tramp-completion-function' entries. They are handled now by `tramp-completion-function-alist'. (tramp-completion-function): Defvar removed. I've never used it. Hmm. (tramp-get-completion-function) (tramp-get-completion-rsh, tramp-get-completion-ssh) (tramp-get-completion-telnet, tramp-get-completion-su): Functions removed as well. Not necessary any longer due to extended customization means. (tramp-completion-function-alist): New defcustom. Holds all FUNCTION FILE pairs used for user and host name completion relevant for METHOD. (tramp-completion-function-alist-rsh) (tramp-completion-function-alist-ssh) (tramp-completion-function-alist-telnet) (tramp-completion-function-alist-su): Defconst for initializing `tramp-completion-function-alist'. Unfortunately, mainly UNIX-like values are known for me until now. Needs to be completed for at least VMS++ like operating systems. (tramp-set-completion-function) (tramp-get-completion-function): New functions for configuration of `tramp-completion-function-alist'. The old definition of `tramp-get-completion-function' has been discarded. (tramp-completion-handle-file-name-all-completions): Change function call for user/host completion according to definition in `tramp-completion-function-alist'. (tramp-parse-passwd): Added exception handling for "root", because `tramp-get-completion-su' (the previous place for this stuff) doesn't exist any longer. 2002-09-07 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-enter-password): Use `tramp-password-end-of-line' to terminate the line. (tramp-bug): Include new variable `tramp-password-end-of-line'. (tramp-password-end-of-line): New variable. People who use plink under Windows might have to issue "\r\n" after the password, but they need to send just "\n" after the other commands. So this variable was introduced to complement `tramp-rsh-end-of-line'. (tramp-wait-for-output, tramp-post-connection): Allow "\r" at end of line of the output delimiter. 2002-09-06 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-file-local-copy, tramp-find-shell) (tramp-open-connection-setup-interactive-shell): Add some comments about Douglas Grey Stephen's suggestions to make Tramp work better with plink under Windows. I'm not sure what to think of them, but now I have a guinea pig to try it out on. Said guinea pig is having other problems, though... Also remove some commented-out code. 2002-09-06 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods): Algorithm slightly tuned. (tramp-get-completion-user-host): Accept user names as they are if typed until "@". (tramp-completion-mode): Replace `last-input-char' by modern `last-input-event'. Check for `event-modifiers'. 2002-09-06 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (file-expand-wildcards): Corrected check to see if advising is necessary. 2002-09-05 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-postfix-single-method-format) (tramp-postfix-multi-method-format) (tramp-postfix-multi-hop-format) (tramp-postfix-user-format): New format strings. (tramp-postfix-single-method-regexp) (tramp-postfix-multi-method-regexp) (tramp-postfix-multi-hop-regexp) (tramp-postfix-user-regexp) (tramp-make-multi-tramp-file-format) (tramp-make-tramp-file-name): Apply them. (tramp-completion-handle-file-name-all-completions): Fix for invoking ange-ftp in case of "/ftp:xxx" file names. 2002-09-04 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-prefix-format) (tramp-postfix-host-format): New format strings. (tramp-prefix-regexp, tramp-method-regexp) (tramp-postfix-single-method-regexp) (tramp-postfix-multi-method-regexp) (tramp-postfix-multi-hop-regexp) (tramp-user-regexp, tramp-postfix-user-regexp) (tramp-host-regexp, tramp-postfix-host-regexp) (tramp-path-regexp): New atomar regular expressions. If corresponding format strings exist, derived from them. (tramp-file-name-structure) (tramp-multi-file-name-structure) (tramp-multi-file-name-hop-structure) (tramp-make-multi-tramp-file-format) (tramp-completion-mode) (tramp-completion-dissect-file-name) (tramp-parse-rhosts-group) (tramp-parse-shosts-group) (tramp-parse-hosts-group) (tramp-parse-passwd-group): Apply these expressions. (tramp-file-name-structure-unified) (tramp-file-name-structure-separate) (tramp-make-tramp-file-format-unified) (tramp-make-tramp-file-format-separate) (tramp-make-tramp-file-format) (tramp-make-tramp-file-user-nil-format-unified) (tramp-make-tramp-file-user-nil-format-separate) (tramp-make-tramp-file-user-nil-format) (tramp-multi-file-name-structure-unified) (tramp-multi-file-name-structure-separate) (tramp-multi-file-name-hop-structure-unified) (tramp-multi-file-name-hop-structure-separate) (tramp-make-multi-tramp-file-format-unified) (tramp-make-multi-tramp-file-format-separate): Removed. (tramp-make-tramp-file-name): Allow partial tramp file names. Generate tramp file format on-the-fly depending on parameters. Apply atomar format strings resp expressions. (tramp-get-completion-methods) (tramp-get-completion-user-host): Apply `tramp-make-tramp-file-name'. (tramp-parse-hosts-group): Take all host names and IP addresses into account. (tramp-bug): Remove `tramp-make-tramp-file-format'. 2002-09-01 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-methods): Add `tramp-completion-function' for "su" and "sudo". (tramp-get-completion-telnet): Implement it. (tramp-parse-hosts) (tramp-parse-hosts-group) (tramp-get-completion-su) (tramp-parse-passwd) (tramp-parse-passwd-group): New functions. 2002-08-31 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): Check for `last-input-char'. (tramp-completion-file-name-handler-alist): Add handler for `file-exists-p. (tramp-completion-handle-file-exists-p): New function. (tramp-completion-handle-file-name-completion): Simplified. (tramp-completion-dissect-file-name): Regexp's reorganised. (tramp-completion-handle-file-name-all-completions): Call completion-function only if `user' or `host' is given. (tramp-get-completion-user-host): New function. (tramp-get-completion-rsh) (tramp-get-completion-ssh): Apply it. 2002-08-29 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-handler-alist): Add handler for `expand-file-name'. (tramp-completion-handle-expand-file-name): New function. 2002-08-26 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): New function. (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-all-completions): Apply it. (tramp-methods): Remove double definition of `ssh1-old' and `ssh2-old'. (tramp-point-at-eol): New defalias. (tramp-parse-rhosts-group) (tramp-parse-shosts-group):: Apply it. 2002-08-25 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods) (tramp-get-completion-rsh) (tramp-get-completion-ssh): Add "[" for Xemacs. (tramp-completion-file-name-regexp-separate): Expression adapted. (tramp-completion-file-name-handler-alist): Add handler for `file-name-directory' and `file-name-nondirectory'. (tramp-completion-handle-file-name-directory) (tramp-completion-handle-file-name-nondirectory) (tramp-completion-run-real-handler): New functions. (tramp-completion-file-name-handler) (tramp-completion-handle-file-name-all-completions): Apply `tramp-completion-run-real-handler'. (tramp-parse-rhosts) (tramp-parse-shosts): Use `with-temp-buffer'. `result? renamed to `res' (otherwise side effects in XEmacs). 2002-08-24 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-regexp) (tramp-completion-file-name-handler-alist) (tramp-flatten-list) (tramp-completion-dissect-file-name) (tramp-get-completion-rsh) (tramp-parse-rhosts) (tramp-parse-rhosts-group) (tramp-get-completion-ssh): Doc string tuned. (tramp-methods): Doc string and custom type extended for `tramp-completion-function'. (tramp-completion-function): Variable added. Is it really used? Other variables like `tramp-completion-function' aren't used. (tramp-completion-file-name-handler-alist): Add handler for `file-name-completion'. (tramp-completion-handle-file-name-completion): New function. 2002-08-18 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-parse-rhosts) (tramp-parse-rhosts-group) (tramp-parse-shosts) (tramp-parse-shosts-group): New functions. 2002-08-17 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-dissect-file-name) (tramp-completion-dissect-file-name1): New functions. 2002-08-16 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-function) (tramp-get-completion-rsh) (tramp-get-completion-ssh) (tramp-get-completion-telnet): New functions. (tramp-methods): Add `tramp-completion-function' for all methods. 2002-08-15 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-completion-methods): New function. (tramp-find-default-method): Allow host to be nil (like user). 2002-08-14 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-file-name-regexp-unified) (tramp-completion-file-name-regexp-separate) (tramp-completion-file-name-regexp) (tramp-completion-file-name-handler-alist): New defcustoms. (tramp-completion-file-name-handler): New function. Add `tramp-completion-file-name-handler' to `file-name-handler-alist'. (tramp-run-real-handler): Add `tramp-completion-file-name-handler' to `inhibit-file-name-handlers'. (tramp-completion-handle-file-name-all-completions) (tramp-completion-handle-file-name-completion): New functions. 2002-08-12 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-invoke-ange-ftp): `tramp-disable-ange-ftp' must be called again after activating `ange-ftp'. (tramp-ange-ftp-file-name-p): Check for Xemacs. 2002-08-08 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-do-copy-or-rename-file): Don't pass KEEP-DATE to tramp-invoke-ange-ftp 'rename. (tramp-handle-write-region): Don't pass LOCKNAME and CONFIRM to tramp-invoke-ange-ftp 'write-region. (tramp-handle-set-file-modes): Change order of FILENAME and MODE passing to tramp-invoke-ange-ftp 'set-file-modes. (tramp-flatten-list): New function. Maybe this functionality does exist already elsewhere in the libraries. (tramp-invoke-ange-ftp): Apply `tramp-flatten-list' to parameter list in order to avoid nested lists, f.e. when invoked from `tramp-handle-dired-call-process'. 2002-09-05 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-chunksize): New kluge variable. (tramp-send-region): If tramp-chunksize is non-nil, send region in parts and sleep 0.1 seconds between chunks. 2002-09-03 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-handle-insert-directory): Use `insert-buffer-substring' instead of `insert-buffer', which is not supposed to be used from Lisp. Remember old point in a variable instead of using `mark'. Suggestion from Stefan Monnier. (tramp-unified-filenames): New variable. Use it in default value of other filename variables. (file-expand-wildcards): Don't advise unless "[" and "]" are used in the filename format. 2002-09-01 Kai Gro?ohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> * net/tramp.el (tramp-methods): Remove duplicate definition of ssh1-old and ssh2-old.
author Kai Großjohann <kgrossjo@eu.uu.net>
date Sun, 22 Sep 2002 13:23:36 +0000
parents 4d3fd773cd30
children 23a1cea22d13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 @c -*-texinfo-*-
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 @c This is part of the GNU Emacs Lisp Reference Manual.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 @c Copyright (C) 1999 Free Software Foundation, Inc.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 @c See the file elisp.texi for copying conditions.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 @setfilename ../info/hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 @node Hash Tables, Symbols, Sequences Arrays Vectors, Top
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 @chapter Hash Tables
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 @cindex hash tables
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 A hash table is a very fast kind of lookup table, somewhat like
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 an alist in that it maps keys to corresponding values. It differs
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 from an alist in these ways:
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 @itemize @bullet
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 @item
26710
ed440ffea308 (Hash Tables): Note that alists win for small tables.
Dave Love <fx@gnu.org>
parents: 26303
diff changeset
16 Lookup in a hash table is extremely fast for large tables---in fact, the
ed440ffea308 (Hash Tables): Note that alists win for small tables.
Dave Love <fx@gnu.org>
parents: 26303
diff changeset
17 time required is essentially @emph{independent} of how many elements are
ed440ffea308 (Hash Tables): Note that alists win for small tables.
Dave Love <fx@gnu.org>
parents: 26303
diff changeset
18 stored in the table. For smaller tables (a few tens of elements)
ed440ffea308 (Hash Tables): Note that alists win for small tables.
Dave Love <fx@gnu.org>
parents: 26303
diff changeset
19 alists may still be faster because hash tables have a more-or-less
ed440ffea308 (Hash Tables): Note that alists win for small tables.
Dave Love <fx@gnu.org>
parents: 26303
diff changeset
20 constant overhead.
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 @item
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 The correspondences in a hash table are in no particular order.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 @item
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 There is no way to share structure between two hash tables,
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 the way two alists can share a common tail.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 @end itemize
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 Emacs Lisp (starting with Emacs 21) provides a general-purpose hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 table data type, along with a series of functions for operating on them.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 Hash tables have no read syntax, and print in hash notation, like this:
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 @example
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (make-hash-table)
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 @result{} #<hash-table 'eql nil 0/65 0x83af980>
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 @end example
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
26303
9b25d0ffe4ec Patch from rms.
Gerd Moellmann <gerd@gnu.org>
parents: 26182
diff changeset
39 @noindent
9b25d0ffe4ec Patch from rms.
Gerd Moellmann <gerd@gnu.org>
parents: 26182
diff changeset
40 (The term ``hash notation'' refers to the initial @samp{#}
9b25d0ffe4ec Patch from rms.
Gerd Moellmann <gerd@gnu.org>
parents: 26182
diff changeset
41 character---@pxref{Printed Representation}---and has nothing to do with
9b25d0ffe4ec Patch from rms.
Gerd Moellmann <gerd@gnu.org>
parents: 26182
diff changeset
42 the term ``hash table.'')
9b25d0ffe4ec Patch from rms.
Gerd Moellmann <gerd@gnu.org>
parents: 26182
diff changeset
43
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 Obarrays are also a kind of hash table, but they are a different type
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 of object and are used only for recording interned symbols
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (@pxref{Creating Symbols}).
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 @menu
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 * Creating Hash::
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 * Hash Access::
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 * Defining Hash::
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 * Other Hash::
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 @end menu
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 @node Creating Hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 @section Creating Hash Tables
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 The principal function for creating a hash table is
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 @code{make-hash-table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 @tindex make-hash-table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 @defun make-hash-table &rest keyword-args
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 This function creates a new hash table according to the specified
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 arguments. The arguments should consist of alternating keywords
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (particular symbols recognized specially) and values corresponding to
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 them.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 Several keywords make sense in @code{make-hash-table}, but the only two
26182
3264a26ae355 Fix some typos.
Gerd Moellmann <gerd@gnu.org>
parents: 25875
diff changeset
69 that you really need to know about are @code{:test} and @code{:weakness}.
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 @table @code
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 @item :test @var{test}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 This specifies the method of key lookup for this hash table. The
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 default is @code{eql}; @code{eq} and @code{equal} are other
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 alternatives:
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 @table @code
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 @item eql
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 Keys which are numbers are ``the same'' if they are equal in value;
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 otherwise, two distinct objects are never ``the same''.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 @item eq
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 Any two distinct Lisp objects are ``different'' as keys.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 @item equal
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 Two Lisp objects are ``the same'', as keys, if they are equal
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 according to @code{equal}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 @end table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 You can use @code{define-hash-table-test} (@pxref{Defining Hash}) to
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 define additional possibilities for @var{test}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 @item :weakness @var{weak}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 The weakness of a hash table specifies whether the presence of a key or
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 value in the hash table preserves it from garbage collection.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 The value, @var{weak}, must be one of @code{nil}, @code{key},
30524
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
98 @code{value}, @code{key-or-value}, @code{key-and-value}, or @code{t}
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
99 which is an alias for @code{key-and-value}. If @var{weak} is @code{key}
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
100 then the hash table does not prevent its keys from being collected as
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
101 garbage (if they are not referenced anywhere else); if a particular key
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
102 does get collected, the corresponding association is removed from the
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
103 hash table.
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
30524
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
105 If @var{weak} is @code{value}, then the hash table does not prevent
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
106 values from being collected as garbage (if they are not referenced
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
107 anywhere else); if a particular value does get collected, the
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 corresponding association is removed from the hash table.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
38786
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
110 If @var{weak} is @code{key-or-value} or @code{t}, the hash table does
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
111 not protect either keys or values from garbage collection; if either
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
112 one is collected as garbage, the association is removed.
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
113
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
114 If @var{weak} is @code{key-and-value}, associations are removed from
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
115 the hash table when both their key and value would be collected as
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
116 garbage, again not considering references to the key and value from
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
117 weak hash tables.
30524
62ed067637af *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents: 26710
diff changeset
118
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 The default for @var{weak} is @code{nil}, so that all keys and values
25875
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
120 referenced in the hash table are preserved from garbage collection. If
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
121 @var{weak} is @code{t}, neither keys nor values are protected (that is,
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
122 both are weak).
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 @item :size @var{size}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 This specifies a hint for how many associations you plan to store in the
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 hash table. If you know the approximate number, you can make things a
26182
3264a26ae355 Fix some typos.
Gerd Moellmann <gerd@gnu.org>
parents: 25875
diff changeset
127 little more efficient by specifying it this way. If you specify too
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 small a size, the hash table will grow automatically when necessary, but
26303
9b25d0ffe4ec Patch from rms.
Gerd Moellmann <gerd@gnu.org>
parents: 26182
diff changeset
129 doing that takes some extra time.
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 The default size is 65.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 @item :rehash-size @var{rehash-size}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 When you add an association to a hash table and the table is ``full,''
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 it grows automatically. This value specifies how to make the hash table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 larger, at that time.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
25875
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
138 If @var{rehash-size} is an integer, it should be positive, and the hash
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
139 table grows by adding that much to the nominal size. If
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
140 @var{rehash-size} is a floating point number, it had better be greater
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
141 than 1, and the hash table grows by multiplying the old size by that
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
142 number.
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 The default value is 1.5.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 @item :rehash-threshold @var{threshold}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 This specifies the criterion for when the hash table is ``full.'' The
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 value, @var{threshold}, should be a positive floating point number, no
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 greater than 1. The hash table is ``full'' whenever the actual number of
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 entries exceeds this fraction of the nominal size. The default for
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 @var{threshold} is 0.8.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 @end table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 @tindex makehash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 @defun makehash &optional test
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 This is equivalent to @code{make-hash-table}, but with a different style
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 argument list. The argument @var{test} specifies the method
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 of key lookup.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 If you want to specify other parameters, you should use
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 @code{make-hash-table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 @node Hash Access
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 @section Hash Table Access
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 This section describes the functions for accessing and storing
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 associations in a hash table.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 @tindex gethash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 @defun gethash key table &optional default
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 This function looks up @var{key} in @var{table}, and returns its
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 associated @var{value}---or @var{default}, if @var{key} has no
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 association in @var{table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 @tindex puthash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 @defun puthash key value table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 This function enters an association for @var{key} in @var{table}, with
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 value @var{value}. If @var{key} already has an association in
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 @var{table}, @var{value} replaces the old associated value.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 @tindex remhash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 @defun remhash key table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 This function removes the association for @var{key} from @var{table}, if
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 there is one. If @var{key} has no association, @code{remhash} does
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 nothing.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 @tindex clrhash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 @defun clrhash table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 This function removes all the associations from hash table @var{table},
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 so that it becomes empty. This is also called @dfn{clearing} the hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 table.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 @tindex maphash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 @defun maphash function table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 This function calls @var{function} once for each of the associations in
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 @var{table}. The function @var{function} should accept two
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 arguments---a @var{key} listed in @var{table}, and its associated
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 @var{value}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 @node Defining Hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 @section Defining Hash Comparisons
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 @cindex hash code
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 You can define new methods of key lookup by means of
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 @code{define-hash-table-test}. In order to use this feature, you need
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 to understand how hash tables work, and what a @dfn{hash code} means.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 You can think of a hash table conceptually as a large array of many
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 slots, each capable of holding one association. To look up a key,
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 @code{gethash} first computes an integer, the hash code, from the key.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 It reduces this integer modulo the length of the array, to produce an
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 index in the array. Then it looks in that slot, and if necessary in
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 other nearby slots, to see if it has found the key being sought.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 Thus, to define a new method of key lookup, you need to specify both a
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 function to compute the hash code from a key, and a function to compare
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 two keys directly.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 @tindex define-hash-table-test
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 @defun define-hash-table-test name test-fn hash-fn
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 This function defines a new hash table test, named @var{name}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 After defining @var{name} in this way, you can use it as the @var{test}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 argument in @code{make-hash-table}. When you do that, the hash table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 will use @var{test-fn} to compare key values, and @var{hash-fn} to compute
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 a ``hash code'' from a key value.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 The function @var{test-fn} should accept two arguments, two keys, and
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 return non-@code{nil} if they are considered ``the same.''
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 The function @var{hash-fn} should accept one argument, a key, and return
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 an integer that is the ``hash code'' of that key. For good results, the
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 function should use the whole range of integer values for hash codes,
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 including negative integers.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 The specified functions are stored in the property list of @var{name}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 under the property @code{hash-table-test}; the property value's form is
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 @code{(@var{test-fn} @var{hash-fn})}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 @tindex sxhash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 @defun sxhash obj
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 This function returns a hash code for Lisp object @var{obj}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 This is an integer which reflects the contents of @var{obj}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 and the other Lisp objects it points to.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 If the two objects are not equal, the values returned by @code{sxhash}
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 are usually different, but not always; but once in a rare while, by
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 luck, you will encounter two distinct-looking objects that give the same
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 result from @code{sxhash}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
38786
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
263 This example creates a hash table whose keys are strings that are
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
264 compared case-insensitively.
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
265
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
266 @example
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
267 (defun case-fold-string= (a b)
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
268 (compare-strings a nil nil b nil nil t))
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
269
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
270 (defun case-fold-string-hash (a)
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
271 (sxhash (upcase a)))
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
272
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
273 (define-hash-table-test 'case-fold 'case-fold-string=
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
274 'case-fold-string-hash))
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
275
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
276 (make-hash-table :test 'case-fold)
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
277 @end example
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
278
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
279 Here is how you could define a hash table test equivalent to the
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
280 predefined test value @code{equal}. The keys can be any Lisp object,
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
281 and equal-looking objects are considered the same key.
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
282
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
283 @example
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
284 (define-hash-table-test 'contents-hash 'equal 'sxhash)
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
285
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
286 (make-hash-table :test 'contents-hash)
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
287 @end example
4d3fd773cd30 Minor cleanups.
Richard M. Stallman <rms@gnu.org>
parents: 30524
diff changeset
288
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 @node Other Hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 @section Other Hash Table Functions
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 Here are some other functions for working with hash tables.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 @tindex hash-table-p
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 @defun hash-table-p table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 This returns non-@code{nil} if @var{table} is a hash table object.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 @tindex copy-hash-table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 @defun copy-hash-table table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 This function creates and returns a copy of @var{table}. Only the table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 itself is copied---the keys and values are shared.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 @tindex hash-table-count
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 @defun hash-table-count table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 This function returns the actual number of entries in @var{table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
26182
3264a26ae355 Fix some typos.
Gerd Moellmann <gerd@gnu.org>
parents: 25875
diff changeset
310 @tindex hash-table-test
3264a26ae355 Fix some typos.
Gerd Moellmann <gerd@gnu.org>
parents: 25875
diff changeset
311 @defun hash-table-test table
25875
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
312 This returns the @var{test} value that was given when @var{table} was
6a17c48b52ef *** empty log message ***
Phillip Rulon <pjr@gnu.org>
parents: 25634
diff changeset
313 created, to specify how to hash and compare keys. See
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 @code{make-hash-table} (@pxref{Creating Hash}).
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 @tindex hash-table-weakness
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 @defun hash-table-weakness table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 This function returns the @var{weak} value that was specified for hash
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 table @var{table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 @tindex hash-table-rehash-size
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 @defun hash-table-rehash-size table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 This returns the rehash size of @var{table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 @tindex hash-table-rehash-threshold
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 @defun hash-table-rehash-threshold table
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 This returns the rehash threshold of @var{table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 @end defun
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332
26182
3264a26ae355 Fix some typos.
Gerd Moellmann <gerd@gnu.org>
parents: 25875
diff changeset
333 @tindex hash-table-size
3264a26ae355 Fix some typos.
Gerd Moellmann <gerd@gnu.org>
parents: 25875
diff changeset
334 @defun hash-table-size table
25634
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 This returns the current nominal size of @var{table}.
0d3bc0a437c4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 @end defun