Commit f7b7714f authored by Nikita Malyavin's avatar Nikita Malyavin

optimize search in favor of erase for the embodied case

parent 274ef97e
Branches unavailable
Tags unavailable
No related merge requests found
......@@ -30,12 +30,15 @@ class Open_address_hash
public:
using Hash_value_type= typename Key_trait::Hash_value_type;
Open_address_hash()
void init()
{
first.set_mark(true);
first.set_ptr(EMPTY);
first.set(EMPTY, true);
second= EMPTY;
}
Open_address_hash()
{
init();
}
~Open_address_hash()
{
......@@ -175,11 +178,14 @@ class Open_address_hash
template <typename Func>
Value find(const Key &key, const Func &elem_suits) const
{
if (first.mark())
if (likely(first.mark()))
{
if (first.ptr() && elem_suits(first.ptr()))
return first.ptr();
if (!is_empty(second) && elem_suits(second))
if (first.ptr())
{
if (elem_suits(first.ptr()))
return first.ptr();
}
else if (!is_empty(second) && elem_suits(second))
return second;
return EMPTY;
......@@ -201,7 +207,8 @@ class Open_address_hash
{
if (!is_empty(first.ptr()) && is_equal(first.ptr(), value))
{
first.set_ptr(EMPTY);
first.set_ptr(second);
second= EMPTY;
return true;
}
else if (second && is_equal(second, value))
......@@ -219,6 +226,8 @@ class Open_address_hash
if (!erase_from_bucket(value))
return false;
_size--;
if (!_size)
init();
return true;
}
......@@ -320,6 +329,12 @@ class Open_address_hash
static constexpr uint MARK_SHIFT = 63;
static constexpr uintptr_t MARK_MASK = 1UL << MARK_SHIFT;
void set(Value ptr, bool mark)
{
uintptr_t mark_bit = static_cast<uintptr_t>(mark) << MARK_SHIFT;
p = reinterpret_cast<uintptr_t>(ptr) | mark_bit;
}
void set_ptr(Value ptr)
{
p = reinterpret_cast<uintptr_t>(ptr) | (p & MARK_MASK);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment