Repository navigation
Frequent items: sample at most the capacity in purge, as Java, Go and Rust do - #605
Draft
stojkomilos wants to merge 5 commits into
Draft
stojkomilos wants to merge 5 commits into
stojkomilos wants to merge 5 commits into
Conversation
… Rust do Purge sampled capacity + 1 counts for the median, so for maps of 1024 slots or fewer the median and offset differed from Java, Go and Rust. Co-authored-by: Isaac <[email protected]>
Add a case where one count fewer than the capacity gives another offset. Make the 2048-slot test depend on the 1024-count sample size. Co-authored-by: Isaac <[email protected]>
The old weights only caught a cap above 1024. Split by home slot, the median is 10 with 1024 samples and 1 with 512 or 1536. Co-authored-by: Isaac <[email protected]>
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
purge()takes its median over one count too many. A purge runs when the map is one item over capacity, sonum_active_is capacity + 1. For an 8-slot map (capacity 6), C++ takes the median of 7 counts. Java, Go and Rust take it of 6. The median can then differ, and so can the offset and the items that survive.Changes
purge()samplesmin(1024, capacity)counts instead ofmin(1024, num_active_). This makes C++ match the other libraries, which samplemin(1024, capacity)too:purge median samples at most the capacity, as java(8 slots).purge median over exactly the capacity counts, as java(8 slots, one item raised to 100). Catches a sample one count short of the capacity.purge at 2048 slots samples 1024 counts. Maps above 1024 slots sample 1024 counts before and after this change.What users see
3.5 / max_map_sizetimes the total weight, and every item's bounds contain its true count. The serialized format does not change.Out of scope: Java and Go also size their sample from the requested
lgMaxMapSizebefore they clamp it to 3. So they sample 0, 1 or 3 counts at lg 0, 1 or 2. At lg 0, Java throws on the first purge and Go panics. This change does not copy that. It is a bug in Java and Go.Checks
fi_testpasses, and passes under-fsanitize=address,undefined.FrequentItemsSketch<Long>(8)with the seven updates of the first test gives offset 40 and 2 active items; with item 3 at 100 (the second test) it gives offset 50 and 2 active items.FrequentItemsSketch<Long>(2048)with items 1 to 1537, weight(fmix64(i) >>> 20) % 1000 + 1, gives offset 517, 758 active items and total 784431.This pull request and its description were written by Isaac.