fx.collections: hashtable: fix index calculation issues
This commit is contained in:
@@ -68,9 +68,14 @@ static fx_status convert_key_to_index(
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t index = hash % table_size, i = 1;
|
||||
size_t base_index = hash % table_size;
|
||||
size_t index = base_index, i = 0;
|
||||
bool index_found = false;
|
||||
while (table[index].i_item && i <= table_size) {
|
||||
while (i <= table_size) {
|
||||
if (!table[index].i_item) {
|
||||
goto skip;
|
||||
}
|
||||
|
||||
const struct fx_hashtable_item_p *item = fx_object_get_private(
|
||||
table[index].i_item,
|
||||
FX_TYPE_HASHTABLE_ITEM);
|
||||
@@ -80,7 +85,8 @@ static fx_status convert_key_to_index(
|
||||
break;
|
||||
}
|
||||
|
||||
index = (index + (i * i)) % table_size;
|
||||
skip:
|
||||
index = (base_index + (i * i)) % table_size;
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -108,7 +114,7 @@ static fx_status allocate_index_for_key(
|
||||
size_t index = hash % table_size;
|
||||
bool ok = false;
|
||||
|
||||
for (size_t i = 1; i < table_size; i++) {
|
||||
for (size_t i = 0; i < table_size; i++) {
|
||||
if (!table[index].i_item) {
|
||||
ok = true;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user