aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c68
1 files changed, 22 insertions, 46 deletions
diff --git a/src/fns.c b/src/fns.c
index da74b9cb489..617a8e873da 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3667,8 +3667,6 @@ larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t nitems_max)
3667 Low-level Functions 3667 Low-level Functions
3668 ***********************************************************************/ 3668 ***********************************************************************/
3669 3669
3670struct hash_table_test hashtest_eq, hashtest_eql, hashtest_equal;
3671
3672/* Compare KEY1 which has hash code HASH1 and KEY2 with hash code 3670/* Compare KEY1 which has hash code HASH1 and KEY2 with hash code
3673 HASH2 in hash table H using `eql'. Value is true if KEY1 and 3671 HASH2 in hash table H using `eql'. Value is true if KEY1 and
3674 KEY2 are the same. */ 3672 KEY2 are the same. */
@@ -3709,7 +3707,6 @@ cmpfn_user_defined (struct hash_table_test *ht,
3709 return !NILP (call2 (ht->user_cmp_function, key1, key2)); 3707 return !NILP (call2 (ht->user_cmp_function, key1, key2));
3710} 3708}
3711 3709
3712
3713/* Value is a hash code for KEY for use in hash table H which uses 3710/* Value is a hash code for KEY for use in hash table H which uses
3714 `eq' to compare keys. The hash code returned is guaranteed to fit 3711 `eq' to compare keys. The hash code returned is guaranteed to fit
3715 in a Lisp integer. */ 3712 in a Lisp integer. */
@@ -3717,34 +3714,27 @@ cmpfn_user_defined (struct hash_table_test *ht,
3717static EMACS_UINT 3714static EMACS_UINT
3718hashfn_eq (struct hash_table_test *ht, Lisp_Object key) 3715hashfn_eq (struct hash_table_test *ht, Lisp_Object key)
3719{ 3716{
3720 EMACS_UINT hash = XHASH (key) ^ XTYPE (key); 3717 return XHASH (key) ^ XTYPE (key);
3721 return hash;
3722} 3718}
3723 3719
3724/* Value is a hash code for KEY for use in hash table H which uses 3720/* Value is a hash code for KEY for use in hash table H which uses
3725 `eql' to compare keys. The hash code returned is guaranteed to fit 3721 `equal' to compare keys. The hash code returned is guaranteed to fit
3726 in a Lisp integer. */ 3722 in a Lisp integer. */
3727 3723
3728static EMACS_UINT 3724static EMACS_UINT
3729hashfn_eql (struct hash_table_test *ht, Lisp_Object key) 3725hashfn_equal (struct hash_table_test *ht, Lisp_Object key)
3730{ 3726{
3731 EMACS_UINT hash; 3727 return sxhash (key, 0);
3732 if (FLOATP (key))
3733 hash = sxhash (key, 0);
3734 else
3735 hash = XHASH (key) ^ XTYPE (key);
3736 return hash;
3737} 3728}
3738 3729
3739/* Value is a hash code for KEY for use in hash table H which uses 3730/* Value is a hash code for KEY for use in hash table H which uses
3740 `equal' to compare keys. The hash code returned is guaranteed to fit 3731 `eql' to compare keys. The hash code returned is guaranteed to fit
3741 in a Lisp integer. */ 3732 in a Lisp integer. */
3742 3733
3743static EMACS_UINT 3734static EMACS_UINT
3744hashfn_equal (struct hash_table_test *ht, Lisp_Object key) 3735hashfn_eql (struct hash_table_test *ht, Lisp_Object key)
3745{ 3736{
3746 EMACS_UINT hash = sxhash (key, 0); 3737 return FLOATP (key) ? hashfn_equal (ht, key) : hashfn_eq (ht, key);
3747 return hash;
3748} 3738}
3749 3739
3750/* Value is a hash code for KEY for use in hash table H which uses as 3740/* Value is a hash code for KEY for use in hash table H which uses as
@@ -3758,6 +3748,14 @@ hashfn_user_defined (struct hash_table_test *ht, Lisp_Object key)
3758 return hashfn_eq (ht, hash); 3748 return hashfn_eq (ht, hash);
3759} 3749}
3760 3750
3751struct hash_table_test const
3752 hashtest_eq = { LISPSYM_INITIALLY (Qeq), LISPSYM_INITIALLY (Qnil),
3753 LISPSYM_INITIALLY (Qnil), 0, hashfn_eq },
3754 hashtest_eql = { LISPSYM_INITIALLY (Qeql), LISPSYM_INITIALLY (Qnil),
3755 LISPSYM_INITIALLY (Qnil), cmpfn_eql, hashfn_eql },
3756 hashtest_equal = { LISPSYM_INITIALLY (Qequal), LISPSYM_INITIALLY (Qnil),
3757 LISPSYM_INITIALLY (Qnil), cmpfn_equal, hashfn_equal };
3758
3761/* Allocate basically initialized hash table. */ 3759/* Allocate basically initialized hash table. */
3762 3760
3763static struct Lisp_Hash_Table * 3761static struct Lisp_Hash_Table *
@@ -4448,33 +4446,29 @@ sxhash (Lisp_Object obj, int depth)
4448 ***********************************************************************/ 4446 ***********************************************************************/
4449 4447
4450DEFUN ("sxhash-eq", Fsxhash_eq, Ssxhash_eq, 1, 1, 0, 4448DEFUN ("sxhash-eq", Fsxhash_eq, Ssxhash_eq, 1, 1, 0,
4451 doc: /* Compute identity hash code for OBJ and return it as integer. 4449 doc: /* Return an integer hash code for OBJ suitable for `eq'.
4452In other words, hash codes of two non-`eq' lists will be (most likely) 4450If (eq A B), then (= (sxhash-eq A) (sxhash-eq B)). */)
4453different, even if the lists contain the same elements. */)
4454 (Lisp_Object obj) 4451 (Lisp_Object obj)
4455{ 4452{
4456 return make_number (hashfn_eq (NULL, obj)); 4453 return make_number (hashfn_eq (NULL, obj));
4457} 4454}
4458 4455
4459DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0, 4456DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0,
4460 doc: /* Compute identity hash code for OBJ and return it as integer. 4457 doc: /* Return an integer hash code for OBJ suitable for `eql'.
4461In comparison to `sxhash-eq', it is also guaranteed that hash codes 4458If (eql A B), then (= (sxhash-eql A) (sxhash-eql B)). */)
4462of equal float numbers will be the same, even if the numbers are not
4463the same Lisp object. */)
4464 (Lisp_Object obj) 4459 (Lisp_Object obj)
4465{ 4460{
4466 return make_number (hashfn_eql (NULL, obj)); 4461 return make_number (hashfn_eql (NULL, obj));
4467} 4462}
4468 4463
4469DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0, 4464DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0,
4470 doc: /* Compute a hash code for OBJ and return it as integer. */) 4465 doc: /* Return an integer hash code for OBJ suitable for `equal'.
4466If (equal A B), then (= (sxhash-equal A) (sxhash-equal B)). */)
4471 (Lisp_Object obj) 4467 (Lisp_Object obj)
4472{ 4468{
4473 EMACS_UINT hash = sxhash (obj, 0); 4469 return make_number (hashfn_equal (NULL, obj));
4474 return make_number (hash);
4475} 4470}
4476 4471
4477
4478DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0, 4472DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0,
4479 doc: /* Create and return a new hash table. 4473 doc: /* Create and return a new hash table.
4480 4474
@@ -5220,22 +5214,4 @@ this variable. */);
5220 defsubr (&Ssecure_hash); 5214 defsubr (&Ssecure_hash);
5221 defsubr (&Sbuffer_hash); 5215 defsubr (&Sbuffer_hash);
5222 defsubr (&Slocale_info); 5216 defsubr (&Slocale_info);
5223
5224 hashtest_eq.name = Qeq;
5225 hashtest_eq.user_hash_function = Qnil;
5226 hashtest_eq.user_cmp_function = Qnil;
5227 hashtest_eq.cmpfn = 0;
5228 hashtest_eq.hashfn = hashfn_eq;
5229
5230 hashtest_eql.name = Qeql;
5231 hashtest_eql.user_hash_function = Qnil;
5232 hashtest_eql.user_cmp_function = Qnil;
5233 hashtest_eql.cmpfn = cmpfn_eql;
5234 hashtest_eql.hashfn = hashfn_eql;
5235
5236 hashtest_equal.name = Qequal;
5237 hashtest_equal.user_hash_function = Qnil;
5238 hashtest_equal.user_cmp_function = Qnil;
5239 hashtest_equal.cmpfn = cmpfn_equal;
5240 hashtest_equal.hashfn = hashfn_equal;
5241} 5217}