Mercurial > emacs
comparison src/fns.c @ 25349:ee30c32ea191
(hash_lookup): Test with EQ before calling key comparion
function.
(hash_remove): Ditto.
(cmpfn_eq): Removed.
(cmpfn_eql): Don't test with EQ.
(cmpfn_equal): Ditto.
(make_hash_table): Set comparison function for `eq' to null.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sat, 21 Aug 1999 19:29:32 +0000 |
parents | ee483f870bde |
children | f32071216123 |
comparison
equal
deleted
inserted
replaced
25348:5c1dc7109bb8 | 25349:ee30c32ea191 |
---|---|
3303 static struct Lisp_Hash_Table *check_hash_table P_ ((Lisp_Object)); | 3303 static struct Lisp_Hash_Table *check_hash_table P_ ((Lisp_Object)); |
3304 static int next_almost_prime P_ ((int)); | 3304 static int next_almost_prime P_ ((int)); |
3305 static int get_key_arg P_ ((Lisp_Object, int, Lisp_Object *, char *)); | 3305 static int get_key_arg P_ ((Lisp_Object, int, Lisp_Object *, char *)); |
3306 static Lisp_Object larger_vector P_ ((Lisp_Object, int, Lisp_Object)); | 3306 static Lisp_Object larger_vector P_ ((Lisp_Object, int, Lisp_Object)); |
3307 static void maybe_resize_hash_table P_ ((struct Lisp_Hash_Table *)); | 3307 static void maybe_resize_hash_table P_ ((struct Lisp_Hash_Table *)); |
3308 static int cmpfn_eq P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned, | |
3309 Lisp_Object, unsigned)); | |
3310 static int cmpfn_eql P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned, | 3308 static int cmpfn_eql P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned, |
3311 Lisp_Object, unsigned)); | 3309 Lisp_Object, unsigned)); |
3312 static int cmpfn_equal P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned, | 3310 static int cmpfn_equal P_ ((struct Lisp_Hash_Table *, Lisp_Object, unsigned, |
3313 Lisp_Object, unsigned)); | 3311 Lisp_Object, unsigned)); |
3314 static int cmpfn_user_defined P_ ((struct Lisp_Hash_Table *, Lisp_Object, | 3312 static int cmpfn_user_defined P_ ((struct Lisp_Hash_Table *, Lisp_Object, |
3420 /*********************************************************************** | 3418 /*********************************************************************** |
3421 Low-level Functions | 3419 Low-level Functions |
3422 ***********************************************************************/ | 3420 ***********************************************************************/ |
3423 | 3421 |
3424 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code | 3422 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code |
3425 HASH2 in hash table H using `eq'. Value is non-zero if KEY1 and | |
3426 KEY2 are the same. */ | |
3427 | |
3428 static int | |
3429 cmpfn_eq (h, key1, hash1, key2, hash2) | |
3430 struct Lisp_Hash_Table *h; | |
3431 Lisp_Object key1, key2; | |
3432 unsigned hash1, hash2; | |
3433 { | |
3434 return EQ (key1, key2); | |
3435 } | |
3436 | |
3437 | |
3438 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code | |
3439 HASH2 in hash table H using `eql'. Value is non-zero if KEY1 and | 3423 HASH2 in hash table H using `eql'. Value is non-zero if KEY1 and |
3440 KEY2 are the same. */ | 3424 KEY2 are the same. */ |
3441 | 3425 |
3442 static int | 3426 static int |
3443 cmpfn_eql (h, key1, hash1, key2, hash2) | 3427 cmpfn_eql (h, key1, hash1, key2, hash2) |
3444 struct Lisp_Hash_Table *h; | 3428 struct Lisp_Hash_Table *h; |
3445 Lisp_Object key1, key2; | 3429 Lisp_Object key1, key2; |
3446 unsigned hash1, hash2; | 3430 unsigned hash1, hash2; |
3447 { | 3431 { |
3448 return (EQ (key1, key2) | 3432 return (FLOATP (key1) |
3449 || (FLOATP (key1) | 3433 && FLOATP (key2) |
3450 && FLOATP (key2) | 3434 && XFLOAT (key1)->data == XFLOAT (key2)->data); |
3451 && XFLOAT (key1)->data == XFLOAT (key2)->data)); | |
3452 } | 3435 } |
3453 | 3436 |
3454 | 3437 |
3455 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code | 3438 /* Compare KEY1 which has hash code HASH1 and KEY2 with hash code |
3456 HASH2 in hash table H using `equal'. Value is non-zero if KEY1 and | 3439 HASH2 in hash table H using `equal'. Value is non-zero if KEY1 and |
3460 cmpfn_equal (h, key1, hash1, key2, hash2) | 3443 cmpfn_equal (h, key1, hash1, key2, hash2) |
3461 struct Lisp_Hash_Table *h; | 3444 struct Lisp_Hash_Table *h; |
3462 Lisp_Object key1, key2; | 3445 Lisp_Object key1, key2; |
3463 unsigned hash1, hash2; | 3446 unsigned hash1, hash2; |
3464 { | 3447 { |
3465 return (EQ (key1, key2) | 3448 return hash1 == hash2 && !NILP (Fequal (key1, key2)); |
3466 || (hash1 == hash2 | |
3467 && !NILP (Fequal (key1, key2)))); | |
3468 } | 3449 } |
3469 | 3450 |
3470 | 3451 |
3471 /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code | 3452 /* Compare KEY1 which has hash code HASH1, and KEY2 with hash code |
3472 HASH2 in hash table H using H->user_cmp_function. Value is non-zero | 3453 HASH2 in hash table H using H->user_cmp_function. Value is non-zero |
3625 h->cmpfn = cmpfn_eql; | 3606 h->cmpfn = cmpfn_eql; |
3626 h->hashfn = hashfn_eql; | 3607 h->hashfn = hashfn_eql; |
3627 } | 3608 } |
3628 else if (EQ (test, Qeq)) | 3609 else if (EQ (test, Qeq)) |
3629 { | 3610 { |
3630 h->cmpfn = cmpfn_eq; | 3611 h->cmpfn = NULL; |
3631 h->hashfn = hashfn_eq; | 3612 h->hashfn = hashfn_eq; |
3632 } | 3613 } |
3633 else if (EQ (test, Qequal)) | 3614 else if (EQ (test, Qequal)) |
3634 { | 3615 { |
3635 h->cmpfn = cmpfn_equal; | 3616 h->cmpfn = cmpfn_equal; |
3756 idx = HASH_INDEX (h, start_of_bucket); | 3737 idx = HASH_INDEX (h, start_of_bucket); |
3757 | 3738 |
3758 while (!NILP (idx)) | 3739 while (!NILP (idx)) |
3759 { | 3740 { |
3760 int i = XFASTINT (idx); | 3741 int i = XFASTINT (idx); |
3761 if (h->cmpfn (h, key, hash_code, HASH_KEY (h, i), HASH_HASH (h, i))) | 3742 if (EQ (key, HASH_KEY (h, i)) |
3743 || (h->cmpfn | |
3744 && h->cmpfn (h, key, hash_code, | |
3745 HASH_KEY (h, i), HASH_HASH (h, i)))) | |
3762 break; | 3746 break; |
3763 idx = HASH_NEXT (h, i); | 3747 idx = HASH_NEXT (h, i); |
3764 } | 3748 } |
3765 | 3749 |
3766 return NILP (idx) ? -1 : XFASTINT (idx); | 3750 return NILP (idx) ? -1 : XFASTINT (idx); |
3818 | 3802 |
3819 while (!NILP (idx)) | 3803 while (!NILP (idx)) |
3820 { | 3804 { |
3821 int i = XFASTINT (idx); | 3805 int i = XFASTINT (idx); |
3822 | 3806 |
3823 if (h->cmpfn (h, key, hash_code, HASH_KEY (h, i), HASH_HASH (h, i))) | 3807 if (EQ (key, HASH_KEY (h, i)) |
3808 || (h->cmpfn | |
3809 && h->cmpfn (h, key, hash_code, | |
3810 HASH_KEY (h, i), HASH_HASH (h, i)))) | |
3824 { | 3811 { |
3825 /* Take entry out of collision chain. */ | 3812 /* Take entry out of collision chain. */ |
3826 if (NILP (prev)) | 3813 if (NILP (prev)) |
3827 HASH_INDEX (h, start_of_bucket) = HASH_NEXT (h, i); | 3814 HASH_INDEX (h, start_of_bucket) = HASH_NEXT (h, i); |
3828 else | 3815 else |