Published in <sxs8zqd9x1g.fsf@florida.arsdigita.de>.
+2000-11-21 Hrvoje Niksic <hniksic@arsdigita.com>
+
+ * hash.c (hash_table_put): Don't overwrite deleted mappings.
+
2000-11-21 Hrvoje Niksic <hniksic@arsdigita.com>
* hash.c (find_mapping): New function.
2000-11-21 Hrvoje Niksic <hniksic@arsdigita.com>
* hash.c (find_mapping): New function.
void
hash_table_put (struct hash_table *ht, const void *key, void *value)
{
void
hash_table_put (struct hash_table *ht, const void *key, void *value)
{
- /* Cannot use find_mapping here because we treat deleted entries
- specially. */
+ /* Cannot use find_mapping here because we're actually looking for
+ an *empty* entry. */
struct mapping *mappings = ht->mappings;
int size = ht->size;
struct mapping *mappings = ht->mappings;
int size = ht->size;
mp->value = value;
break;
}
mp->value = value;
break;
}
- else if (DELETED_ENTRY_P (mp_key))
+ else if (DELETED_ENTRY_P (mp_key)
+ || !ht->test_function (key, mp_key))
- /* We're replacing a deleteed entry, so ht->count gets
- increased, but ht->fullness remains unchanged. */
- ++ht->count;
- goto just_insert;
+ if (++location == size)
+ location = 0;
- else if (ht->test_function (key, mp_key))
+ else /* equal to key and not deleted */
{
/* We're replacing an existing entry, so ht->count and
ht->fullness remain unchanged. */
goto just_insert;
}
{
/* We're replacing an existing entry, so ht->count and
ht->fullness remain unchanged. */
goto just_insert;
}
- else
- {
- if (++location == size)
- location = 0;
- }
}
if (ht->fullness * 4 > ht->size * 3)
/* When fullness exceeds 75% of size, regrow the table. */
}
if (ht->fullness * 4 > ht->size * 3)
/* When fullness exceeds 75% of size, regrow the table. */