You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@datasketches.apache.org by "Fengzdadi (via GitHub)" <gi...@apache.org> on 2026/01/04 02:51:44 UTC

[I] [Feat] Implement ReservoirLongsSketch for sampling package [datasketches-go]

Fengzdadi opened a new issue, #90:
URL: https://github.com/apache/datasketches-go/issues/90

   ### Description
   
   I'd like to contribute an implementation of `ReservoirLongsSketch` to the Go library. This would address the ❌ status for "ReservoirLongsSketch" in the README.
   
   ### Proposed Implementation
   
   Based on the Java reference implementation, I've created:
   
   | File | Description |
   |------|-------------|
   | `sampling/reservoir_longs_sketch.go` | Core reservoir sampling for `int64` values |
   | `sampling/reservoir_longs_union.go` | Union for merging multiple sketches |
   | `sampling/reservoir_longs_sketch_test.go` | Unit tests (11 tests) |
   | `examples/reservoir_example_test.go` | Usage examples |
   
   ### Algorithm
   
   The classic **Reservoir Sampling** algorithm (Vitter's Algorithm R):
   
   1. **Initial Phase** (n < k): Store all items
   2. **Steady State** (n ≥ k): Replace random item with probability k/n
   
   ### API
   
   ```go
   // Create sketch with capacity k
   sketch, _ := sampling.NewReservoirLongsSketch(10)
   
   // Add items
   sketch.Update(42)
   
   // Get uniform random sample
   samples := sketch.GetSamples()
   
   // Serialization
   bytes, _ := sketch.ToByteArray()
   restored, _ := sampling.NewReservoirLongsSketchFromSlice(bytes)
   ```
   
   ### Feedback Requested
   
   I have a working implementation ready. Before submitting a PR, I'd appreciate feedback on:
   
   1. **Serialization Format**: I followed the general pattern from `PreambleUtil.java`. Should I verify cross-language compatibility with specific test cases?
   2. **Scope**: Should I include `ReservoirItemsSketch<T>` (generic version) in the same PR, or keep it as a separate contribution?
   3. **Any design concerns** with the current approach?
   
   ### Testing
   
   All tests pass locally:
   ```
   go test -v ./sampling/ ./examples/
   # 13 tests pass
   ```
   
   I'm happy to adjust the implementation based on your feedback!


-- 
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: dev-unsubscribe@datasketches.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [I] [Feat] Implement ReservoirLongsSketch for sampling package [datasketches-go]

Posted by "Fengzdadi (via GitHub)" <gi...@apache.org>.
Fengzdadi commented on issue #90:
URL: https://github.com/apache/datasketches-go/issues/90#issuecomment-3707566502

   > There's no need for the longs sketch if there's a generic version. It was just done in java to ensure everything was working correctly prior to making a generic sampling sketch.
   > 
   > For c++ there's only a templatized version since you can use that with primitives. And we had a known-working version to compare against by then.
   
   Got it, thanks for the explanation! I'll refactor to a generic `ReservoirItemsSketch[T]` instead. Will update the PR when ready.


-- 
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: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [I] [Feat] Implement ReservoirLongsSketch for sampling package [datasketches-go]

Posted by "Fengzdadi (via GitHub)" <gi...@apache.org>.
Fengzdadi closed issue #90: [Feat] Implement ReservoirLongsSketch for sampling package
URL: https://github.com/apache/datasketches-go/issues/90


-- 
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: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [I] [Feat] Implement ReservoirLongsSketch for sampling package [datasketches-go]

Posted by "jmalkin (via GitHub)" <gi...@apache.org>.
jmalkin commented on issue #90:
URL: https://github.com/apache/datasketches-go/issues/90#issuecomment-3707563495

   There's no need for the longs sketch if there's a generic version. It was just done in java to ensure everything was working correctly prior to making a generic sampling sketch. 
   
   For c++ there's only a templatized version since you can use that with primitives. And we had a known-working version to compare against by then.


-- 
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: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [I] [Feat] Implement ReservoirLongsSketch for sampling package [datasketches-go]

Posted by "Fengzdadi (via GitHub)" <gi...@apache.org>.
Fengzdadi commented on issue #90:
URL: https://github.com/apache/datasketches-go/issues/90#issuecomment-3756089682

   I'm closing this issue because it's already been completed!


-- 
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: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org


Re: [I] [Feat] Implement ReservoirLongsSketch for sampling package [datasketches-go]

Posted by "Fengzdadi (via GitHub)" <gi...@apache.org>.
Fengzdadi commented on issue #90:
URL: https://github.com/apache/datasketches-go/issues/90#issuecomment-3707737146

   Serialization is deferred to a follow-up PR as generic type serialization needs some design consideration.


-- 
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: dev-unsubscribe@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@datasketches.apache.org
For additional commands, e-mail: dev-help@datasketches.apache.org