forked from OctaForge/libostd
use calls to bucket() to get hashes
parent
0c297af0bd
commit
0421e7b3c8
|
@ -218,7 +218,7 @@ private:
|
||||||
|
|
||||||
Chain *find(const K &key, Size &h) const {
|
Chain *find(const K &key, Size &h) const {
|
||||||
if (!p_size) return nullptr;
|
if (!p_size) return nullptr;
|
||||||
h = get_hash()(key) & (p_size - 1);
|
h = bucket(key);
|
||||||
Chain **cp = p_data.first();
|
Chain **cp = p_data.first();
|
||||||
for (Chain *c = cp[h], *e = cp[h + 1]; c != e; c = c->next)
|
for (Chain *c = cp[h], *e = cp[h + 1]; c != e; c = c->next)
|
||||||
if (get_eq()(key, B::get_key(c->value)))
|
if (get_eq()(key, B::get_key(c->value)))
|
||||||
|
@ -370,7 +370,7 @@ protected:
|
||||||
memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *));
|
memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *));
|
||||||
Chain **och = ht.p_data.first();
|
Chain **och = ht.p_data.first();
|
||||||
for (Chain *oc = *och; oc; oc = oc->next) {
|
for (Chain *oc = *och; oc; oc = oc->next) {
|
||||||
Size h = get_hash()(B::get_key(oc->value)) & (p_size - 1);
|
Size h = bucket(B::get_key(oc->value));
|
||||||
Chain *nc = insert(h);
|
Chain *nc = insert(h);
|
||||||
allocator_destroy(get_alloc(), &nc->value);
|
allocator_destroy(get_alloc(), &nc->value);
|
||||||
allocator_construct(get_alloc(), &nc->value, oc->value);
|
allocator_construct(get_alloc(), &nc->value, oc->value);
|
||||||
|
@ -409,7 +409,7 @@ protected:
|
||||||
memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *));
|
memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *));
|
||||||
Chain **och = ht.p_data.first();
|
Chain **och = ht.p_data.first();
|
||||||
for (Chain *oc = *och; oc; oc = oc->next) {
|
for (Chain *oc = *och; oc; oc = oc->next) {
|
||||||
Size h = get_hash()(B::get_key(oc->value)) & (p_size - 1);
|
Size h = bucket(B::get_key(oc->value));
|
||||||
Chain *nc = insert(h);
|
Chain *nc = insert(h);
|
||||||
B::swap_elem(oc->value, nc->value);
|
B::swap_elem(oc->value, nc->value);
|
||||||
}
|
}
|
||||||
|
@ -512,7 +512,7 @@ public:
|
||||||
Pair<Range, bool> emplace(Args &&...args) {
|
Pair<Range, bool> emplace(Args &&...args) {
|
||||||
rehash_ahead(1);
|
rehash_ahead(1);
|
||||||
E elem(forward<Args>(args)...);
|
E elem(forward<Args>(args)...);
|
||||||
Size h = get_hash()(B::get_key(elem)) & (p_size - 1);
|
Size h = bucket(B::get_key(elem));
|
||||||
if (Multihash) {
|
if (Multihash) {
|
||||||
/* multihash: always insert */
|
/* multihash: always insert */
|
||||||
Chain *ch = insert(h);
|
Chain *ch = insert(h);
|
||||||
|
@ -539,7 +539,7 @@ public:
|
||||||
Size erase(const K &key) {
|
Size erase(const K &key) {
|
||||||
if (!p_len) return 0;
|
if (!p_len) return 0;
|
||||||
Size olen = p_len;
|
Size olen = p_len;
|
||||||
Size h = get_hash()(key) & (p_size - 1);
|
Size h = bucket(key);
|
||||||
Chain **cp = p_data.first();
|
Chain **cp = p_data.first();
|
||||||
for (Chain *c = cp[h], *e = cp[h + 1]; c != e; c = c->next)
|
for (Chain *c = cp[h], *e = cp[h + 1]; c != e; c = c->next)
|
||||||
if (get_eq()(key, B::get_key(c->value))) {
|
if (get_eq()(key, B::get_key(c->value))) {
|
||||||
|
@ -602,7 +602,7 @@ public:
|
||||||
Chain *p = och ? *och : nullptr;
|
Chain *p = och ? *och : nullptr;
|
||||||
while (p) {
|
while (p) {
|
||||||
Chain *pp = p->next;
|
Chain *pp = p->next;
|
||||||
Size h = get_hash()(B::get_key(p->value)) & (p_size - 1);
|
Size h = bucket(B::get_key(p->value));
|
||||||
p->prev = p->next = nullptr;
|
p->prev = p->next = nullptr;
|
||||||
insert_node(h, p);
|
insert_node(h, p);
|
||||||
p = pp;
|
p = pp;
|
||||||
|
|
Loading…
Reference in New Issue