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 | |
| 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
| -rw-r--r-- | doc/lispref/hash.texi | 43 | ||||
| -rw-r--r-- | etc/NEWS | 11 | ||||
| -rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 5 | ||||
| -rw-r--r-- | lisp/subr.el | 1 | ||||
| -rw-r--r-- | src/fns.c | 24 |
5 files changed, 71 insertions, 13 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 |
| @@ -217,6 +217,17 @@ outermost parenthesis. | |||
| 217 | ** The function 'redirect-debugging-output' now works on platforms | 217 | ** The function 'redirect-debugging-output' now works on platforms |
| 218 | other than GNU/Linux. | 218 | other than GNU/Linux. |
| 219 | 219 | ||
| 220 | +++ | ||
| 221 | ** New functions 'sxhash-eq' and 'sxhash-eql' return hash codes of a | ||
| 222 | Lisp object suitable for use with 'eq' and 'eql' correspondingly. If | ||
| 223 | two objects are 'eq' ('eql'), then the result of 'sxhash-eq' | ||
| 224 | ('sxhash-eql') on them will be the same. | ||
| 225 | |||
| 226 | +++ | ||
| 227 | ** Function 'sxhash' has been renamed to 'sxhash-equal' for | ||
| 228 | consistency with the new functions. For compatibility, 'sxhash' | ||
| 229 | remains as an alias to 'sxhash-equal'. | ||
| 230 | |||
| 220 | 231 | ||
| 221 | * Changes in Emacs 25.2 on Non-Free Operating Systems | 232 | * Changes in Emacs 25.2 on Non-Free Operating Systems |
| 222 | 233 | ||
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index b3bf4a58849..dbaf2bc6f6a 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el | |||
| @@ -1209,8 +1209,9 @@ | |||
| 1209 | radians-to-degrees rassq rassoc read-from-string regexp-quote | 1209 | radians-to-degrees rassq rassoc read-from-string regexp-quote |
| 1210 | region-beginning region-end reverse round | 1210 | region-beginning region-end reverse round |
| 1211 | sin sqrt string string< string= string-equal string-lessp string-to-char | 1211 | sin sqrt string string< string= string-equal string-lessp string-to-char |
| 1212 | string-to-int string-to-number substring sxhash symbol-function | 1212 | string-to-int string-to-number substring |
| 1213 | symbol-name symbol-plist symbol-value string-make-unibyte | 1213 | sxhash sxhash-equal sxhash-eq sxhash-eql |
| 1214 | symbol-function symbol-name symbol-plist symbol-value string-make-unibyte | ||
| 1214 | string-make-multibyte string-as-multibyte string-as-unibyte | 1215 | string-make-multibyte string-as-multibyte string-as-unibyte |
| 1215 | string-to-multibyte | 1216 | string-to-multibyte |
| 1216 | tan truncate | 1217 | tan truncate |
diff --git a/lisp/subr.el b/lisp/subr.el index cad6319f3b2..a6d6fa44ca1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -66,6 +66,7 @@ For more information, see Info node `(elisp)Declaring Functions'." | |||
| 66 | ;;;; Basic Lisp macros. | 66 | ;;;; Basic Lisp macros. |
| 67 | 67 | ||
| 68 | (defalias 'not 'null) | 68 | (defalias 'not 'null) |
| 69 | (defalias 'sxhash 'sxhash-equal) | ||
| 69 | 70 | ||
| 70 | (defmacro noreturn (form) | 71 | (defmacro noreturn (form) |
| 71 | "Evaluate FORM, expecting it not to return. | 72 | "Evaluate FORM, expecting it not to return. |
| @@ -4447,8 +4447,26 @@ sxhash (Lisp_Object obj, int depth) | |||
| 4447 | Lisp Interface | 4447 | Lisp Interface |
| 4448 | ***********************************************************************/ | 4448 | ***********************************************************************/ |
| 4449 | 4449 | ||
| 4450 | DEFUN ("sxhash-eq", Fsxhash_eq, Ssxhash_eq, 1, 1, 0, | ||
| 4451 | doc: /* Compute identity hash code for OBJ and return it as integer. | ||
| 4452 | In other words, hash codes of two non-`eq' lists will be (most likely) | ||
| 4453 | different, even if the lists contain the same elements. */) | ||
| 4454 | (Lisp_Object obj) | ||
| 4455 | { | ||
| 4456 | return make_number (hashfn_eq (NULL, obj)); | ||
| 4457 | } | ||
| 4458 | |||
| 4459 | DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0, | ||
| 4460 | doc: /* Compute identity hash code for OBJ and return it as integer. | ||
| 4461 | In comparison to `sxhash-eq', it is also guaranteed that hash codes | ||
| 4462 | of equal float numbers will be the same, even if the numbers are not | ||
| 4463 | the same Lisp object. */) | ||
| 4464 | (Lisp_Object obj) | ||
| 4465 | { | ||
| 4466 | return make_number (hashfn_eql (NULL, obj)); | ||
| 4467 | } | ||
| 4450 | 4468 | ||
| 4451 | DEFUN ("sxhash", Fsxhash, Ssxhash, 1, 1, 0, | 4469 | DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0, |
| 4452 | doc: /* Compute a hash code for OBJ and return it as integer. */) | 4470 | doc: /* Compute a hash code for OBJ and return it as integer. */) |
| 4453 | (Lisp_Object obj) | 4471 | (Lisp_Object obj) |
| 4454 | { | 4472 | { |
| @@ -5066,7 +5084,9 @@ syms_of_fns (void) | |||
| 5066 | DEFSYM (Qkey_or_value, "key-or-value"); | 5084 | DEFSYM (Qkey_or_value, "key-or-value"); |
| 5067 | DEFSYM (Qkey_and_value, "key-and-value"); | 5085 | DEFSYM (Qkey_and_value, "key-and-value"); |
| 5068 | 5086 | ||
| 5069 | defsubr (&Ssxhash); | 5087 | defsubr (&Ssxhash_eq); |
| 5088 | defsubr (&Ssxhash_eql); | ||
| 5089 | defsubr (&Ssxhash_equal); | ||
| 5070 | defsubr (&Smake_hash_table); | 5090 | defsubr (&Smake_hash_table); |
| 5071 | defsubr (&Scopy_hash_table); | 5091 | defsubr (&Scopy_hash_table); |
| 5072 | defsubr (&Shash_table_count); | 5092 | defsubr (&Shash_table_count); |