case Lisp_Cons: case Lisp_Vectorlike:
{
struct Lisp_Hash_Table *h = XHASH_TABLE (ht);
- EMACS_UINT hash;
+ Lisp_Object hash;
ptrdiff_t i = hash_lookup (h, o1, &hash);
if (i >= 0)
{ /* `o1' was seen already. */
/* Ignore HT and compare KEY1 and KEY2 using 'eql'.
Value is true if KEY1 and KEY2 are the same. */
-static bool
-cmpfn_eql (struct hash_table_test *ht,
- Lisp_Object key1,
- Lisp_Object key2)
+static Lisp_Object
+cmpfn_eql (Lisp_Object key1, Lisp_Object key2, struct hash_table_test *ht)
{
- return !NILP (Feql (key1, key2));
+ return Feql (key1, key2);
}
/* Ignore HT and compare KEY1 and KEY2 using 'equal'.
Value is true if KEY1 and KEY2 are the same. */
-static bool
-cmpfn_equal (struct hash_table_test *ht,
- Lisp_Object key1,
- Lisp_Object key2)
+static Lisp_Object
+cmpfn_equal (Lisp_Object key1, Lisp_Object key2, struct hash_table_test *ht)
{
- return !NILP (Fequal (key1, key2));
+ return Fequal (key1, key2);
}
/* Given HT, compare KEY1 and KEY2 using HT->user_cmp_function.
Value is true if KEY1 and KEY2 are the same. */
-static bool
-cmpfn_user_defined (struct hash_table_test *ht,
- Lisp_Object key1,
- Lisp_Object key2)
+static Lisp_Object
+cmpfn_user_defined (Lisp_Object key1, Lisp_Object key2,
+ struct hash_table_test *ht)
{
- return !NILP (call2 (ht->user_cmp_function, key1, key2));
+ return call2 (ht->user_cmp_function, key1, key2);
}
-/* Ignore HT and return a hash code for KEY which uses 'eq' to compare keys.
- The hash code is at most INTMASK. */
+/* Ignore HT and return a hash code for KEY which uses 'eq' to compare
+ keys. */
-static EMACS_UINT
-hashfn_eq (struct hash_table_test *ht, Lisp_Object key)
+static Lisp_Object
+hashfn_eq (Lisp_Object key, struct hash_table_test *ht)
{
- return XHASH (key) ^ XTYPE (key);
+ return make_fixnum (XHASH (key) ^ XTYPE (key));
}
/* Ignore HT and return a hash code for KEY which uses 'equal' to compare keys.
The hash code is at most INTMASK. */
-EMACS_UINT
-hashfn_equal (struct hash_table_test *ht, Lisp_Object key)
+Lisp_Object
+hashfn_equal (Lisp_Object key, struct hash_table_test *ht)
{
- return sxhash (key, 0);
+ return make_fixnum (sxhash (key, 0));
}
/* Ignore HT and return a hash code for KEY which uses 'eql' to compare keys.
The hash code is at most INTMASK. */
-EMACS_UINT
-hashfn_eql (struct hash_table_test *ht, Lisp_Object key)
+Lisp_Object
+hashfn_eql (Lisp_Object key, struct hash_table_test *ht)
{
- return ((FLOATP (key) || BIGNUMP (key))
- ? hashfn_equal (ht, key)
- : hashfn_eq (ht, key));
+ return (FLOATP (key) || BIGNUMP (key) ? hashfn_equal : hashfn_eq) (key, ht);
}
/* Given HT, return a hash code for KEY which uses a user-defined
- function to compare keys. The hash code is at most INTMASK. */
+ function to compare keys. */
-static EMACS_UINT
-hashfn_user_defined (struct hash_table_test *ht, Lisp_Object key)
+static Lisp_Object
+hashfn_user_defined (Lisp_Object key, struct hash_table_test *ht)
{
Lisp_Object hash = call1 (ht->user_hash_function, key);
- return hashfn_eq (ht, hash);
+ return hashfn_eq (hash, ht);
}
struct hash_table_test const
if (!NILP (HASH_HASH (h, i)))
{
Lisp_Object key = HASH_KEY (h, i);
- EMACS_UINT hash_code = h->test.hashfn (&h->test, key);
- set_hash_hash_slot (h, i, make_fixnum (hash_code));
+ Lisp_Object hash_code = h->test.hashfn (key, &h->test);
+ set_hash_hash_slot (h, i, hash_code);
}
/* Reset the index so that any slot we don't fill below is marked
matching KEY, or -1 if not found. */
ptrdiff_t
-hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash)
+hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object *hash)
{
- EMACS_UINT hash_code;
ptrdiff_t start_of_bucket, i;
hash_rehash_if_needed (h);
- hash_code = h->test.hashfn (&h->test, key);
- eassert ((hash_code & ~INTMASK) == 0);
+ Lisp_Object hash_code = h->test.hashfn (key, &h->test);
if (hash)
*hash = hash_code;
- start_of_bucket = hash_code % ASIZE (h->index);
+ start_of_bucket = XUFIXNUM (hash_code) % ASIZE (h->index);
for (i = HASH_INDEX (h, start_of_bucket); 0 <= i; i = HASH_NEXT (h, i))
if (EQ (key, HASH_KEY (h, i))
|| (h->test.cmpfn
- && hash_code == XUFIXNUM (HASH_HASH (h, i))
- && h->test.cmpfn (&h->test, key, HASH_KEY (h, i))))
+ && EQ (hash_code, HASH_HASH (h, i))
+ && !NILP (h->test.cmpfn (key, HASH_KEY (h, i), &h->test))))
break;
return i;
ptrdiff_t
hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value,
- EMACS_UINT hash)
+ Lisp_Object hash)
{
ptrdiff_t start_of_bucket, i;
hash_rehash_if_needed (h);
- eassert ((hash & ~INTMASK) == 0);
-
/* Increment count after resizing because resizing may fail. */
maybe_resize_hash_table (h);
h->count++;
set_hash_value_slot (h, i, value);
/* Remember its hash code. */
- set_hash_hash_slot (h, i, make_fixnum (hash));
+ set_hash_hash_slot (h, i, hash);
/* Add new entry to its collision chain. */
- start_of_bucket = hash % ASIZE (h->index);
+ start_of_bucket = XUFIXNUM (hash) % ASIZE (h->index);
set_hash_next_slot (h, i, HASH_INDEX (h, start_of_bucket));
set_hash_index_slot (h, start_of_bucket, i);
return i;
void
hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key)
{
- EMACS_UINT hash_code = h->test.hashfn (&h->test, key);
- eassert ((hash_code & ~INTMASK) == 0);
- ptrdiff_t start_of_bucket = hash_code % ASIZE (h->index);
+ Lisp_Object hash_code = h->test.hashfn (key, &h->test);
+ ptrdiff_t start_of_bucket = XUFIXNUM (hash_code) % ASIZE (h->index);
ptrdiff_t prev = -1;
hash_rehash_if_needed (h);
{
if (EQ (key, HASH_KEY (h, i))
|| (h->test.cmpfn
- && hash_code == XUFIXNUM (HASH_HASH (h, i))
- && h->test.cmpfn (&h->test, key, HASH_KEY (h, i))))
+ && EQ (hash_code, HASH_HASH (h, i))
+ && !NILP (h->test.cmpfn (key, HASH_KEY (h, i), &h->test))))
{
/* Take entry out of collision chain. */
if (prev < 0)
Hash codes are not guaranteed to be preserved across Emacs sessions. */)
(Lisp_Object obj)
{
- return make_fixnum (hashfn_eq (NULL, obj));
+ return hashfn_eq (obj, NULL);
}
DEFUN ("sxhash-eql", Fsxhash_eql, Ssxhash_eql, 1, 1, 0,
Hash codes are not guaranteed to be preserved across Emacs sessions. */)
(Lisp_Object obj)
{
- return make_fixnum (hashfn_eql (NULL, obj));
+ return hashfn_eql (obj, NULL);
}
DEFUN ("sxhash-equal", Fsxhash_equal, Ssxhash_equal, 1, 1, 0,
Hash codes are not guaranteed to be preserved across Emacs sessions. */)
(Lisp_Object obj)
{
- return make_fixnum (hashfn_equal (NULL, obj));
+ return hashfn_equal (obj, NULL);
}
DEFUN ("make-hash-table", Fmake_hash_table, Smake_hash_table, 0, MANY, 0,
struct Lisp_Hash_Table *h = check_hash_table (table);
CHECK_IMPURE (table, h);
- ptrdiff_t i;
- EMACS_UINT hash;
- i = hash_lookup (h, key, &hash);
+ Lisp_Object hash;
+ ptrdiff_t i = hash_lookup (h, key, &hash);
if (i >= 0)
set_hash_value_slot (h, i, value);
else
Lisp_Object user_cmp_function;
/* C function to compare two keys. */
- bool (*cmpfn) (struct hash_table_test *t, Lisp_Object, Lisp_Object);
+ Lisp_Object (*cmpfn) (Lisp_Object, Lisp_Object, struct hash_table_test *t);
/* C function to compute hash code. */
- EMACS_UINT (*hashfn) (struct hash_table_test *t, Lisp_Object);
+ Lisp_Object (*hashfn) (Lisp_Object, struct hash_table_test *t);
};
struct Lisp_Hash_Table
extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *);
EMACS_UINT hash_string (char const *, ptrdiff_t);
EMACS_UINT sxhash (Lisp_Object, int);
-EMACS_UINT hashfn_eql (struct hash_table_test *ht, Lisp_Object key);
-EMACS_UINT hashfn_equal (struct hash_table_test *ht, Lisp_Object key);
+Lisp_Object hashfn_eql (Lisp_Object, struct hash_table_test *);
+Lisp_Object hashfn_equal (Lisp_Object, struct hash_table_test *);
Lisp_Object make_hash_table (struct hash_table_test, EMACS_INT, float, float,
Lisp_Object, bool);
-ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
+ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object *);
ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
- EMACS_UINT);
+ Lisp_Object);
void hash_remove_from_table (struct Lisp_Hash_Table *, Lisp_Object);
extern struct hash_table_test const hashtest_eq, hashtest_eql, hashtest_equal;
extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
typedef struct Lisp_Hash_Table log_t;
-static bool cmpfn_profiler (
- struct hash_table_test *, Lisp_Object, Lisp_Object);
-
-static EMACS_UINT hashfn_profiler (
- struct hash_table_test *, Lisp_Object);
+static Lisp_Object cmpfn_profiler (Lisp_Object, Lisp_Object,
+ struct hash_table_test *);
+static Lisp_Object hashfn_profiler (Lisp_Object, struct hash_table_test *);
static const struct hash_table_test hashtest_profiler =
{
careful to avoid memory allocation since we're in a signal
handler, and we optimize the code to try and avoid computing the
hash+lookup twice. See fns.c:Fputhash for reference. */
- EMACS_UINT hash;
+ Lisp_Object hash;
ptrdiff_t j = hash_lookup (log, backtrace, &hash);
if (j >= 0)
{
return res ? Qt : Qnil;
}
-static bool
-cmpfn_profiler (struct hash_table_test *t,
- Lisp_Object bt1, Lisp_Object bt2)
+static Lisp_Object
+cmpfn_profiler (Lisp_Object bt1, Lisp_Object bt2, struct hash_table_test *t)
{
if (VECTORP (bt1) && VECTORP (bt2))
{
ptrdiff_t l = ASIZE (bt1);
if (l != ASIZE (bt2))
- return false;
+ return Qnil;
for (ptrdiff_t i = 0; i < l; i++)
if (NILP (Ffunction_equal (AREF (bt1, i), AREF (bt2, i))))
- return false;
- return true;
+ return Qnil;
+ return Qt;
}
else
- return EQ (bt1, bt2);
+ return EQ (bt1, bt2) ? Qt : Qnil;
}
-static EMACS_UINT
-hashfn_profiler (struct hash_table_test *ht, Lisp_Object bt)
+static Lisp_Object
+hashfn_profiler (Lisp_Object bt, struct hash_table_test *ht)
{
+ EMACS_UINT hash;
if (VECTORP (bt))
{
- EMACS_UINT hash = 0;
+ hash = 0;
ptrdiff_t l = ASIZE (bt);
for (ptrdiff_t i = 0; i < l; i++)
{
? XHASH (XCDR (XCDR (f))) : XHASH (f));
hash = sxhash_combine (hash, hash1);
}
- return SXHASH_REDUCE (hash);
}
else
- return XHASH (bt);
+ hash = XHASH (bt);
+ return make_fixnum (SXHASH_REDUCE (hash));
}
static void syms_of_profiler_for_pdumper (void);