Some fixes and improvements to hashmap, hashset and multimap
This commit is contained in:
1 parent
396066f289
commit
762b95db26
3 files changed
+46
-29
No files matched your search
+7
-4
@@ -330,7 +330,7 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
{ \
|
||||
target->key = key; \
|
||||
target->value = value; \
|
||||
target->dist = original_pos - pos; \
|
||||
target->dist = 0; \
|
||||
target->state = CMC_ES_FILLED; \
|
||||
} \
|
||||
else \
|
||||
@@ -775,7 +775,7 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
\
|
||||
static bool PFX##_impl_grow(SNAME *_map_) \
|
||||
{ \
|
||||
size_t new_size = PFX##_impl_calculate_size(_map_->capacity + _map_->capacity / 2); \
|
||||
size_t new_size = _map_->capacity + _map_->capacity / 2; \
|
||||
\
|
||||
SNAME *_new_map_ = PFX##_new(new_size, _map_->load, _map_->cmp, _map_->hash); \
|
||||
\
|
||||
@@ -795,14 +795,17 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
if (_map_->count != _new_map_->count) \
|
||||
{ \
|
||||
PFX##_free(_new_map_, NULL); \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
SNAME##_entry *tmp = _map_->buffer; \
|
||||
SNAME##_entry *tmp_b = _map_->buffer; \
|
||||
_map_->buffer = _new_map_->buffer; \
|
||||
_new_map_->buffer = tmp; \
|
||||
_new_map_->buffer = tmp_b; \
|
||||
\
|
||||
size_t tmp_c = _map_->capacity; \
|
||||
_map_->capacity = _new_map_->capacity; \
|
||||
_new_map_->capacity = tmp_c; \
|
||||
\
|
||||
PFX##_free(_new_map_, NULL); \
|
||||
\
|
||||
|
||||
+30
-24
@@ -319,7 +319,7 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
if (target->state == CMC_ES_EMPTY || target->state == CMC_ES_DELETED) \
|
||||
{ \
|
||||
target->value = element; \
|
||||
target->dist = pos - original_pos; \
|
||||
target->dist = 0; \
|
||||
target->state = CMC_ES_FILLED; \
|
||||
} \
|
||||
else \
|
||||
@@ -806,19 +806,21 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
SNAME##_entry *scan = &(iter->target->buffer[iter->cursor]); \
|
||||
\
|
||||
if (iter->cursor == iter->last) \
|
||||
iter->end = true; \
|
||||
else \
|
||||
{ \
|
||||
iter->index++; \
|
||||
iter->end = true; \
|
||||
\
|
||||
while (1) \
|
||||
{ \
|
||||
iter->cursor++; \
|
||||
scan = &(iter->target->buffer[iter->cursor]); \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (scan->state == CMC_ES_FILLED) \
|
||||
break; \
|
||||
} \
|
||||
iter->index++; \
|
||||
\
|
||||
while (1) \
|
||||
{ \
|
||||
iter->cursor++; \
|
||||
scan = &(iter->target->buffer[iter->cursor]); \
|
||||
\
|
||||
if (scan->state == CMC_ES_FILLED) \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
iter->start = PFX##_empty(iter->target); \
|
||||
@@ -834,19 +836,21 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
SNAME##_entry *scan = &(iter->target->buffer[iter->cursor]); \
|
||||
\
|
||||
if (iter->cursor == iter->first) \
|
||||
iter->start = true; \
|
||||
else \
|
||||
{ \
|
||||
iter->index--; \
|
||||
iter->start = true; \
|
||||
\
|
||||
while (1) \
|
||||
{ \
|
||||
iter->cursor--; \
|
||||
scan = &(iter->target->buffer[iter->cursor]); \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (scan->state == CMC_ES_FILLED) \
|
||||
break; \
|
||||
} \
|
||||
iter->index--; \
|
||||
\
|
||||
while (1) \
|
||||
{ \
|
||||
iter->cursor--; \
|
||||
scan = &(iter->target->buffer[iter->cursor]); \
|
||||
\
|
||||
if (scan->state == CMC_ES_FILLED) \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
iter->end = PFX##_empty(iter->target); \
|
||||
@@ -869,7 +873,7 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
\
|
||||
static bool PFX##_impl_grow(SNAME *_set_) \
|
||||
{ \
|
||||
size_t new_size = PFX##_impl_calculate_size(_set_->capacity + _set_->capacity / 2); \
|
||||
size_t new_size = _set_->capacity + _set_->capacity / 2; \
|
||||
\
|
||||
SNAME *_new_set_ = PFX##_new(new_size, _set_->load, _set_->cmp, _set_->hash); \
|
||||
\
|
||||
@@ -890,11 +894,13 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
SNAME##_entry *tmp = _set_->buffer; \
|
||||
SNAME##_entry *tmp_b = _set_->buffer; \
|
||||
_set_->buffer = _new_set_->buffer; \
|
||||
_new_set_->buffer = tmp; \
|
||||
_new_set_->buffer = tmp_b; \
|
||||
\
|
||||
size_t tmp_c = _set_->capacity; \
|
||||
_set_->capacity = _new_set_->capacity; \
|
||||
_new_set_->capacity = tmp_c; \
|
||||
\
|
||||
PFX##_free(_new_set_, NULL); \
|
||||
\
|
||||
|
||||
+9
-1
@@ -356,7 +356,8 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
\
|
||||
scan = scan->next; \
|
||||
\
|
||||
deallocator(tmp->key, tmp->value); \
|
||||
if (deallocator) \
|
||||
deallocator(tmp->key, tmp->value); \
|
||||
\
|
||||
free(tmp); \
|
||||
} \
|
||||
@@ -1020,6 +1021,13 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531,
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if (_map_->count != _new_map_->count) \
|
||||
{ \
|
||||
PFX##_free(_new_map_, NULL); \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
SNAME##_entry *(*tmp_b)[2] = _map_->buffer; \
|
||||
_map_->buffer = _new_map_->buffer; \
|
||||
_new_map_->buffer = tmp_b; \
|
||||
|
||||
Reference in new issue
Block a user