fix(sampling): align resize-factor behavior and replace reservoir panics with errors#120
Open
Fengzdadi wants to merge 2 commits intoapache:mainfrom
Open
fix(sampling): align resize-factor behavior and replace reservoir panics with errors#120Fengzdadi wants to merge 2 commits intoapache:mainfrom
Fengzdadi wants to merge 2 commits intoapache:mainfrom
Conversation
proost
requested changes
Feb 9, 2026
| minLgArrItems = 4 | ||
| ) | ||
|
|
||
| func resizeFactorLg(rf ResizeFactor) (int, error) { |
Member
There was a problem hiding this comment.
You can define ResizeFactor using iota. so, verbose case syntax doesn't need.
|
|
||
| ceilingLgK, _ := internal.ExactLog2(common.CeilingPowerOf2(k)) | ||
| initialLgSize := startingSubMultiple( | ||
| ceilingLgK, int(math.Log2(float64(options.resizeFactor))), minLgArrItems, |
Member
There was a problem hiding this comment.
using ResizeFactor itself is ok , right?
| if targetCap <= cap(s.data) { | ||
| return nil | ||
| } | ||
| newData := make([]T, len(s.data), targetCap) |
Member
There was a problem hiding this comment.
L162 ~ L164 is too expensive. that is why i use Grow
|
|
||
| // forceIncrementItemsSeen adds delta to the items seen count. | ||
| func (s *ReservoirItemsSketch[T]) forceIncrementItemsSeen(delta int64) { | ||
| func (s *ReservoirItemsSketch[T]) forceIncrementItemsSeen(delta int64) error { |
Member
There was a problem hiding this comment.
If you add delta to s.n first, it already change state. so guarding not to above maxItemsSeen is correct.
Member
There was a problem hiding this comment.
You are right. I was wrong. chaning state first is correct. sketch's state is gone wrong already.
| assert.Equal(t, ResizeX8, sketch.rf) | ||
| } | ||
|
|
||
| func TestReservoirItemsSketchUpdateReturnsErrorAtMaxItemsSeen(t *testing.T) { |
Member
There was a problem hiding this comment.
I think this case is included already defined test function as nest case.
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.
ResizeFactorhandling with Java semantics (lg-based growth) inReservoirItemsSketchandVarOptItemsSketch.ReservoirItemsSketch.EstimateSubsetSumwith Java by returning stream-level estimates andTotalSketchWeight = N.panicpaths with returnederrorin sketch/union update flows.go test ./...passes.