aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pogonyshev2016-04-08 14:02:48 -0700
committerPaul Eggert2016-04-08 15:33:59 -0700
commita4aa94d0cdffb45723786aa798174e942d509774 (patch)
treed4a498fd0319d004ef1e42885f1f91e9bc2172a2
parentb2746dbf562dc4821bc111488b0e5b6ca5fc6061 (diff)
downloademacs-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.texi43
-rw-r--r--etc/NEWS11
-rw-r--r--lisp/emacs-lisp/byte-opt.el5
-rw-r--r--lisp/subr.el1
-rw-r--r--src/fns.c24
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
272This function returns a hash code for Lisp object @var{obj}. 272This function returns a hash code for Lisp object @var{obj}.
273This is an integer which reflects the contents of @var{obj} 273This is an integer which reflects the contents of @var{obj}
274and the other Lisp objects it points to. 274and the other Lisp objects it points to.
275 275
276If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash 276If 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})}
278are the same integer.
278 279
279If the two objects are not equal, the values returned by @code{sxhash} 280If the two objects are not @code{equal}, the values returned by
280are 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
281you will encounter two distinct-looking objects that give the same 282rare while, by luck, you will encounter two distinct-looking objects
282result from @code{sxhash}. 283that 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
291This function returns a hash code for Lisp object @var{obj}. Its
292result reflects identity of @var{obj}, but not its contents.
293
294If two objects @var{obj1} and @var{obj2} are @code{eq}, then
295@code{(xhash @var{obj1})} and @code{(xhash @var{obj2})} are the same
296integer.
297@end defun
298
299@defun sxhash-eql obj
300This function returns a hash code for Lisp object @var{obj} suitable
301for @code{eql} comparison. I.e. it reflects identity of @var{obj}
302except for the case where the object is a float number, in which case
303hash code is generated for the value.
304
305If two objects @var{obj1} and @var{obj2} are @code{eql}, then
306@code{(xhash @var{obj1})} and @code{(xhash @var{obj2})} are the same
307integer.
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,
302and equal-looking objects are considered the same key. 327and 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
diff --git a/etc/NEWS b/etc/NEWS
index d38bc3d9099..6ec82f8333c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
218other than GNU/Linux. 218other than GNU/Linux.
219 219
220+++
221** New functions 'sxhash-eq' and 'sxhash-eql' return hash codes of a
222Lisp object suitable for use with 'eq' and 'eql' correspondingly. If
223two 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
228consistency with the new functions. For compatibility, 'sxhash'
229remains 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.
diff --git a/src/fns.c b/src/fns.c
index 1ace3bb888e..da74b9cb489 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4447,8 +4447,26 @@ sxhash (Lisp_Object obj, int depth)
4447 Lisp Interface 4447 Lisp Interface
4448 ***********************************************************************/ 4448 ***********************************************************************/
4449 4449
4450DEFUN ("sxhash-eq", Fsxhash_eq, Ssxhash_eq, 1, 1, 0,
4451 doc: /* Compute identity hash code for OBJ and return it as integer.
4452In other words, hash codes of two non-`eq' lists will be (most likely)
4453different, even if the lists contain the same elements. */)
4454 (Lisp_Object obj)
4455{
4456 return make_number (hashfn_eq (NULL, obj));
4457}
4458
4459DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0,
4460 doc: /* Compute identity hash code for OBJ and return it as integer.
4461In comparison to `sxhash-eq', it is also guaranteed that hash codes
4462of equal float numbers will be the same, even if the numbers are not
4463the same Lisp object. */)
4464 (Lisp_Object obj)
4465{
4466 return make_number (hashfn_eql (NULL, obj));
4467}
4450 4468
4451DEFUN ("sxhash", Fsxhash, Ssxhash, 1, 1, 0, 4469DEFUN ("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);