mirror of https://github.com/rui314/chibicc
Hashmap: Do not insert duplicate keys
While looking into the table for a spot for the new key, search until an empty one is found and do not overwrite tombstones. Signed-off-by: Kristiyan Stoimenov <kristoimenov@gmail.com>
This commit is contained in:
parent
90d1f7f199
commit
2c523ff895
|
@ -23,7 +23,7 @@ static uint64_t fnv_hash(char *s, int len) {
|
|||
return hash;
|
||||
}
|
||||
|
||||
// Make room for new entires in a given hashmap by removing
|
||||
// Make room for new entries in a given hashmap by removing
|
||||
// tombstones and possibly extending the bucket size.
|
||||
static void rehash(HashMap *map) {
|
||||
// Compute the size of the new hashmap.
|
||||
|
@ -89,11 +89,6 @@ static HashEntry *get_or_insert_entry(HashMap *map, char *key, int keylen) {
|
|||
if (match(ent, key, keylen))
|
||||
return ent;
|
||||
|
||||
if (ent->key == TOMBSTONE) {
|
||||
ent->key = key;
|
||||
ent->keylen = keylen;
|
||||
return ent;
|
||||
}
|
||||
|
||||
if (ent->key == NULL) {
|
||||
ent->key = key;
|
||||
|
|
Loading…
Reference in New Issue