From 0e85e8b0c38af01364e45dc2a1a23c540b9fd1a4 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 11 Jun 2012 14:59:04 +0200 Subject: [PATCH] Revert "Backport rth's" This reverts commit 159065b1e5c430d77e14b76212304593bbd0eb65. --- hashtab.c | 74 ++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/hashtab.c b/hashtab.c index e5d53a3..8a14c09 100644 --- a/hashtab.c +++ b/hashtab.c @@ -69,6 +69,7 @@ higher_prime_number (n) /* These are primes that are near, but slightly smaller than, a power of two. */ static unsigned long primes[] = { + (unsigned long) 2, (unsigned long) 7, (unsigned long) 13, (unsigned long) 31, @@ -228,27 +229,21 @@ find_empty_slot_for_expand (htab, hash) hashval_t hash; { size_t size = htab->size; + hashval_t hash2 = 1 + hash % (size - 2); unsigned int index = hash % size; - void **slot = htab->entries + index; - hashval_t hash2; - if (*slot == EMPTY_ENTRY) - return slot; - else if (*slot == DELETED_ENTRY) - abort (); - - hash2 = 1 + hash % (size - 2); for (;;) { - index += hash2; - if (index >= size) - index -= size; + void **slot = htab->entries + index; - slot = htab->entries + index; if (*slot == EMPTY_ENTRY) return slot; else if (*slot == DELETED_ENTRY) abort (); + + index += hash2; + if (index >= size) + index -= size; } } @@ -373,59 +368,50 @@ htab_find_slot_with_hash (htab, element, hash, insert) unsigned int index; hashval_t hash2; size_t size; - void * entry; if (insert == INSERT && htab->size * 3 <= htab->n_elements * 4 && htab_expand (htab) == 0) return NULL; size = htab->size; + hash2 = 1 + hash % (size - 2); index = hash % size; htab->searches++; first_deleted_slot = NULL; - entry = htab->entries[index]; - if (entry == EMPTY_ENTRY) - goto empty_entry; - else if (entry == DELETED_ENTRY) - first_deleted_slot = &htab->entries[index]; - else if ((*htab->eq_f) (entry, element)) - return &htab->entries[index]; - - hash2 = 1 + hash % (size - 2); for (;;) { - htab->collisions++; - index += hash2; - if (index >= size) - index -= size; - - entry = htab->entries[index]; + void * entry = htab->entries[index]; if (entry == EMPTY_ENTRY) - goto empty_entry; - else if (entry == DELETED_ENTRY) + { + if (insert == NO_INSERT) + return NULL; + + htab->n_elements++; + + if (first_deleted_slot) + { + *first_deleted_slot = EMPTY_ENTRY; + return first_deleted_slot; + } + + return &htab->entries[index]; + } + + if (entry == DELETED_ENTRY) { if (!first_deleted_slot) first_deleted_slot = &htab->entries[index]; } - else if ((*htab->eq_f) (entry, element)) + else if ((*htab->eq_f) (entry, element)) return &htab->entries[index]; - } - empty_entry: - if (insert == NO_INSERT) - return NULL; - - htab->n_elements++; - - if (first_deleted_slot) - { - *first_deleted_slot = EMPTY_ENTRY; - return first_deleted_slot; + htab->collisions++; + index += hash2; + if (index >= size) + index -= size; } - - return &htab->entries[index]; } /* Like htab_find_slot_with_hash, but compute the hash value from the -- 2.43.5