Repository navigation
Frequent items: start the map iterator at slot 0, as Java, Go and Rust do - #607
Draft
stojkomilos wants to merge 2 commits into
Draft
stojkomilos wants to merge 2 commits into
stojkomilos wants to merge 2 commits into
Conversation
Java, Go and Rust walk the map from slot 0 with the golden-ratio stride. C++ started at the first occupied slot, so merge inserted items in a different order and a purge could keep other items. Co-authored-by: Isaac <[email protected]>
Co-authored-by: Isaac <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOT READY FOR REVIEW YET
frequent_items_sketchwalks its map with a golden-ratio stride. Java, Go and Rust start that walk at slot 0. C++ started at the first occupied slot, so its walk order could differ when slot 0 was empty.merge()inserts items in walk order, so a merge that purges could keep different items than Java does.Changes
reverse_purge_hash_map::begin()starts at slot 0 and steps by the iterator's stride until it reaches an occupied slot. An empty map returnsbegin() == end().i_ = -stride_,next()steps first)i_: -stride)0usize.wrapping_sub(stride))operator++is unchanged.Side effects:
serialize()writes items in iterator order, so the C++ bytes change. The format does not change, and readers accept the bytes and get the same items and counts. The slot layout a reader rebuilds follows the byte order, as on master, so a later merge that purges can differ. The bytes still differ from Java, which writes in slot order. That is a separate difference, not part of this PR.get_frequent_items()andto_string(true)changes. Their tie order still comes fromstd::sort, which is not stable.Checks
fi/test/reverse_purge_hash_map_test.cpp:{1, 3, 4, 2}fi/test/frequent_items_sketch_test.cpp:FrequentItemsSketch.merge. The same values hold with Frequent items: sample at most the capacity in purge, as Java, Go and Rust do #605's purge sample cap, so this PR does not depend on Frequent items: sample at most the capacity in purge, as Java, Go and Rust do #605.fi_testpasses: 34 test cases, 186 assertions.fi_testpasses under ASan and UBSan.This pull request and its description were written by Isaac.