Skip to content

Commit

Permalink
Fix return value of erase in bytell_hash_*
Browse files Browse the repository at this point in the history
This is a fix for issue: skarupke#41
  • Loading branch information
alex-budkar-amplitude authored Sep 27, 2023
1 parent 2c46874 commit d02fe6b
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit d02fe6b

Please sign in to comment.