diff options
| author | Paul Pogonyshev | 2016-04-08 14:02:48 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-04-08 15:33:59 -0700 |
| commit | a4aa94d0cdffb45723786aa798174e942d509774 (patch) | |
| tree | d4a498fd0319d004ef1e42885f1f91e9bc2172a2 /doc | |
| parent | b2746dbf562dc4821bc111488b0e5b6ca5fc6061 (diff) | |
| download | emacs-a4aa94d0cdffb45723786aa798174e942d509774.tar.gz emacs-a4aa94d0cdffb45723786aa798174e942d509774.zip | |
New primitives sxhash-eq, sxhash-eql
* doc/lispref/hash.texi (Defining Hash), etc/NEWS: Document this.
* lisp/emacs-lisp/byte-opt.el (side-effect-free-fns):
Add sxhash-equal, sxhash-eq, sxhash-eql.
* lisp/subr.el (sxhash): Now an alias for sxhash-equal.
* src/fns.c (Fsxhash_eq, Fsxhash_eql): New functions.n
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/hash.texi | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/doc/lispref/hash.texi b/doc/lispref/hash.texi index 8389c214707..4607bb0a0d1 100644 --- a/doc/lispref/hash.texi +++ b/doc/lispref/hash.texi | |||
| @@ -268,18 +268,43 @@ under the property @code{hash-table-test}; the property value's form is | |||
| 268 | @code{(@var{test-fn} @var{hash-fn})}. | 268 | @code{(@var{test-fn} @var{hash-fn})}. |
| 269 | @end defun | 269 | @end defun |
| 270 | 270 | ||
| 271 | @defun sxhash obj | 271 | @defun sxhash-equal obj |
| 272 | This function returns a hash code for Lisp object @var{obj}. | 272 | This function returns a hash code for Lisp object @var{obj}. |
| 273 | This is an integer which reflects the contents of @var{obj} | 273 | This is an integer which reflects the contents of @var{obj} |
| 274 | and the other Lisp objects it points to. | 274 | and the other Lisp objects it points to. |
| 275 | 275 | ||
| 276 | If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash | 276 | If two objects @var{obj1} and @var{obj2} are @code{equal}, then |
| 277 | @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer. | 277 | @code{(sxhash-equal @var{obj1})} and @code{(sxhash-equal @var{obj2})} |
| 278 | are the same integer. | ||
| 278 | 279 | ||
| 279 | If the two objects are not equal, the values returned by @code{sxhash} | 280 | If the two objects are not @code{equal}, the values returned by |
| 280 | are usually different, but not always; once in a rare while, by luck, | 281 | @code{sxhash-equal} are usually different, but not always; once in a |
| 281 | you will encounter two distinct-looking objects that give the same | 282 | rare while, by luck, you will encounter two distinct-looking objects |
| 282 | result from @code{sxhash}. | 283 | that give the same result from @code{sxhash-equal}. |
| 284 | |||
| 285 | @b{Common Lisp note:} In Common Lisp a similar function is called | ||
| 286 | @code{sxhash}. Emacs provides this name as a compatibility alias for | ||
| 287 | @code{sxhash-equal}. | ||
| 288 | @end defun | ||
| 289 | |||
| 290 | @defun sxhash-eq obj | ||
| 291 | This function returns a hash code for Lisp object @var{obj}. Its | ||
| 292 | result reflects identity of @var{obj}, but not its contents. | ||
| 293 | |||
| 294 | If two objects @var{obj1} and @var{obj2} are @code{eq}, then | ||
| 295 | @code{(xhash @var{obj1})} and @code{(xhash @var{obj2})} are the same | ||
| 296 | integer. | ||
| 297 | @end defun | ||
| 298 | |||
| 299 | @defun sxhash-eql obj | ||
| 300 | This function returns a hash code for Lisp object @var{obj} suitable | ||
| 301 | for @code{eql} comparison. I.e. it reflects identity of @var{obj} | ||
| 302 | except for the case where the object is a float number, in which case | ||
| 303 | hash code is generated for the value. | ||
| 304 | |||
| 305 | If two objects @var{obj1} and @var{obj2} are @code{eql}, then | ||
| 306 | @code{(xhash @var{obj1})} and @code{(xhash @var{obj2})} are the same | ||
| 307 | integer. | ||
| 283 | @end defun | 308 | @end defun |
| 284 | 309 | ||
| 285 | This example creates a hash table whose keys are strings that are | 310 | This example creates a hash table whose keys are strings that are |
| @@ -289,7 +314,7 @@ compared case-insensitively. | |||
| 289 | (defun case-fold-string= (a b) | 314 | (defun case-fold-string= (a b) |
| 290 | (eq t (compare-strings a nil nil b nil nil t))) | 315 | (eq t (compare-strings a nil nil b nil nil t))) |
| 291 | (defun case-fold-string-hash (a) | 316 | (defun case-fold-string-hash (a) |
| 292 | (sxhash (upcase a))) | 317 | (sxhash-equal (upcase a))) |
| 293 | 318 | ||
| 294 | (define-hash-table-test 'case-fold | 319 | (define-hash-table-test 'case-fold |
| 295 | 'case-fold-string= 'case-fold-string-hash) | 320 | 'case-fold-string= 'case-fold-string-hash) |
| @@ -302,7 +327,7 @@ predefined test value @code{equal}. The keys can be any Lisp object, | |||
| 302 | and equal-looking objects are considered the same key. | 327 | and equal-looking objects are considered the same key. |
| 303 | 328 | ||
| 304 | @example | 329 | @example |
| 305 | (define-hash-table-test 'contents-hash 'equal 'sxhash) | 330 | (define-hash-table-test 'contents-hash 'equal 'sxhash-equal) |
| 306 | 331 | ||
| 307 | (make-hash-table :test 'contents-hash) | 332 | (make-hash-table :test 'contents-hash) |
| 308 | @end example | 333 | @end example |