Add update_theta_sketch::get_result() to trim to k in one pass - #515
Open
stojkomilos wants to merge 2 commits into
Open
Add update_theta_sketch::get_result() to trim to k in one pass#515stojkomilos wants to merge 2 commits into
stojkomilos wants to merge 2 commits into
Conversation
added 2 commits
August 20, 2026 13:49
Returns a compact_theta_sketch bounded to the nominal size k (2^lg_k), matching the at-most-k guarantee of theta_union::get_result(). It does the nth_element/erase cutback directly on the output vector compact() already allocates, avoiding the throwaway 2k rehash of trim()+compact(). Co-authored-by: Isaac
Matches the ordered = true parameter of theta_union::get_result() and theta_intersection::get_result(); sorts only when ordered is requested. Co-authored-by: Isaac
stojkomilos
force-pushed
the
milosh-stojko/theta-update-get-result
branch
from
August 20, 2026 13:53
301e495 to
c174f89
Compare
stojkomilos
marked this pull request as ready for review
August 20, 2026 13:54
SavicStefan
approved these changes
Aug 20, 2026
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.
What changed
Add
get_result()toupdate_theta_sketch_alloc. It returns acompact_theta_sketchtrimmed to at most the nominal sizek(2^lg_k) in a single pass, without rebuilding the hash table.Background: an update sketch's hash table retains up to
~15/16 * 2kentries between rebuilds, andcompact()intentionally keeps all of them (extra entries below theta improve the estimate). To trim a result onktoday, a caller doestrim()thencompact(), this is too slow and inneificent (does malloc, dealloc).I named this function
get_result()in reference to theta union (and likely intersectino) which gurantee to return a already trimmed result.How tested
get_result trims to k in one pass: builds an 8000-item sketch (retains more thank); asserts the defaultget_result()returns exactlykordered entries matchingtrim()+compact(true)(same theta and retained set), and thatget_result(false)returns the same trimmed set unordered.get_result on empty and below-k sketches: empty stays empty and ordered; a 100-item exact-mode sketch returns untrimmed with all entries, ordered by default.Local run: