Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return value of erase in bytell_hash_* #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions bytell_hash_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ class sherwood_v8_table : private ByteAlloc, private Hasher, private Equal
AllocatorTraits::destroy(*this, std::addressof(*next));
next.set_metadata(Constants::magic_for_empty);
previous.clear_next();
// The iteration order in the map after erase is changed for future iterations over the map
// But it only changed in the portion of the map before `const_iterator to_erase` (indexes greater than current.index)
// We didn't touch the order of the elements after `const_iterator to_erase` (indexes smaller than current.index)
// so we can just return convertible_to_iterator{ to_erase.current, to_erase.index },
// which will advance to the next element upon conversion to iterator
}
else
{
Expand Down Expand Up @@ -1019,19 +1024,16 @@ class sherwood_v8_table : private ByteAlloc, private Hasher, private Equal
BlockPointer it;
size_t index;

// We always have to move to the next element upon conversion,
// because if it's not empty it's something that we already
// visited and moved to the current position
operator iterator()
{
if (it->control_bytes[index % BlockSize] == Constants::magic_for_empty)
return ++iterator{it, index};
else
return { it, index };
return ++iterator{it, index};
}
operator const_iterator()
{
if (it->control_bytes[index % BlockSize] == Constants::magic_for_empty)
return ++iterator{it, index};
else
return { it, index };
return ++iterator{it, index};
}
};
};
Expand Down