fix(hash table): fixed duplicate inserts for hash table
This commit is contained in:
parent
91e07ff6d0
commit
ecbffdc112
1 changed files with 12 additions and 3 deletions
|
|
@ -119,12 +119,21 @@ FledastyError fledasty_hash_table_##name##_insert(FledastyHashTable_##name *curr
|
|||
hallocy_free(previous_table); \
|
||||
} \
|
||||
\
|
||||
const size_t index = current_hash_table->hash_function(key) % current_hash_table->capacity; \
|
||||
\
|
||||
FledastyHashTablePair_##name pair = { .key = key, .value = value }; \
|
||||
fledasty_dynamic_array_fledasty_internal_pair_append(¤t_hash_table->Table[index], pair); \
|
||||
const size_t index = current_hash_table->hash_function(key) % current_hash_table->capacity; \
|
||||
if (fledasty_dynamic_array_fledasty_internal_pair_has_value(¤t_hash_table->Table[index], pair)) { \
|
||||
size_t key_index = 0; \
|
||||
while (!compare_key_function(current_hash_table->Table[index].buffer[key_index].key, key)) { \
|
||||
key_index += 1; \
|
||||
} \
|
||||
\
|
||||
current_hash_table->Table[index].buffer[key_index].value = value; \
|
||||
return FLEDASTY_ERROR_VALUE_REPLACED; \
|
||||
} \
|
||||
\
|
||||
fledasty_dynamic_array_fledasty_internal_pair_append(¤t_hash_table->Table[index], pair); \
|
||||
current_hash_table->size += 1; \
|
||||
\
|
||||
return FLEDASTY_ERROR_NONE; \
|
||||
} \
|
||||
\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue