Fengzdadi opened a new pull request, #91: URL: https://github.com/apache/datasketches-go/pull/91
## Summary Implements `ReservoirItemsSketch[T any]` - a generic reservoir sampling sketch for the Go library. This addresses the ❌ status for sampling sketches in the README. ## Related Issue #90 ## Implementation ### Files Added | File | Description | |------|-------------| | `sampling/reservoir_items_sketch.go` | Generic reservoir sampling implementation | | `sampling/reservoir_items_union.go` | Union for merging multiple sketches | | `sampling/reservoir_items_sketch_test.go` | 13 unit tests | | `examples/reservoir_example_test.go` | Usage examples with int64, string, struct | ### Algorithm Classic Reservoir Sampling (Vitter's Algorithm R): - **Initial phase** (n < k): all items are stored - **Steady state** (n ≥ k): each new item replaces a random item with probability k/n ### API ```go // Create sketch with capacity k sketch, _ := sampling.NewReservoirItemsSketch[int64](10) // Add items sketch.Update(42) // Get uniform random sample samples := sketch.GetSamples() ``` ## Notes - **Generic implementation**: Works with any type (`int64`, `string`, custom structs) - **Serialization**: Not included in this PR due to complexity of generic type serialization - **Thread safety**: Not thread-safe; external synchronization required for concurrent use - **ResizeFactor**: Kept for API compatibility with Java, but Go's slice append handles resizing ## Testing All tests pass: ``` go test ./sampling/ ./examples/ ok github.com/apache/datasketches-go/sampling ok github.com/apache/datasketches-go/examples ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
