Skip to content

Frequent items: sample at most the capacity in purge, as Java, Go and Rust do - #605

Draft
stojkomilos wants to merge 1 commit into
apache:masterfrom
stojkomilos:milosh-stojko/fi-purge-sample-size
Draft

stojkomilos wants to merge 1 commit into
apache:masterfrom
stojkomilos:milosh-stojko/fi-purge-sample-size

Conversation

@stojkomilos

Copy link
Copy Markdown
Contributor

purge() takes its median over one count too many. A purge runs when the map is one item over capacity, so num_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

What users see

  • Only maps of 1024 slots or fewer change. For the same stream, a purge can give a different offset and different surviving items.
  • The error bounds still hold. The serialized format does not change.

Out of scope: Java also sizes its sample from the requested lgMaxMapSize before it clamps it to 3. So Java samples 1 or 3 counts at lg 1 or 2. This change does not copy that. It is a Java bug.

Checks

  • fi_test passes, and passes under -fsanitize=address,undefined.
  • The 8-slot test fails on master (offset 30, expected 40) and passes with this change. The expected values come from datasketches-java 028462110.
  • The 2048-slot test passes on master and with this change.

This pull request and its description were written by Isaac.

… 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 <no-reply@databricks.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant