proost commented on code in PR #108:
URL: https://github.com/apache/datasketches-go/pull/108#discussion_r2723790034


##########
sampling/varopt_items_sketch.go:
##########
@@ -524,3 +529,256 @@ func (s *VarOptItemsSketch[T]) adjustedSize(maxSize, 
resizeTarget int) int {
        }
        return maxSize
 }
+
+// VarOptItemsSketchEncoder writes a Java-compatible VarOpt sketch to an 
io.Writer.
+type VarOptItemsSketchEncoder[T any] struct {
+       w     io.Writer
+       serde ItemsSerDe[T]
+}
+
+// NewVarOptItemsSketchEncoder creates an encoder with the provided writer and 
serde.
+func NewVarOptItemsSketchEncoder[T any](w io.Writer, serde ItemsSerDe[T]) 
*VarOptItemsSketchEncoder[T] {

Review Comment:
   Can you return value not pointer? returning pointer can be allocated in 
heap. Encoder is used once to encoding. I don't think long life cycle. So 
avoiding allocated in heap is good. 
   
   ``` 
   sampling/varopt_items_sketch.go:541:9: 
&VarOptItemsSketchEncoder[go.shape.string]{...} escapes to heap in 
NewVarOptItemsSketchEncoder[go.shape.string]:
   ```



##########
sampling/varopt_items_sketch.go:
##########
@@ -524,3 +529,256 @@ func (s *VarOptItemsSketch[T]) adjustedSize(maxSize, 
resizeTarget int) int {
        }
        return maxSize
 }
+
+// VarOptItemsSketchEncoder writes a Java-compatible VarOpt sketch to an 
io.Writer.
+type VarOptItemsSketchEncoder[T any] struct {
+       w     io.Writer
+       serde ItemsSerDe[T]
+}
+
+// NewVarOptItemsSketchEncoder creates an encoder with the provided writer and 
serde.
+func NewVarOptItemsSketchEncoder[T any](w io.Writer, serde ItemsSerDe[T]) 
*VarOptItemsSketchEncoder[T] {
+       return &VarOptItemsSketchEncoder[T]{w: w, serde: serde}
+}
+
+// Encode writes the serialized sketch to the encoder's writer.
+func (e *VarOptItemsSketchEncoder[T]) Encode(sketch *VarOptItemsSketch[T]) 
error {
+       if e == nil || e.w == nil {
+               return errors.New("nil writer")
+       }
+       data, err := encodeVarOptItemsSketch(sketch, e.serde)
+       if err != nil {
+               return err
+       }
+       _, err = e.w.Write(data)
+       return err
+}
+
+// VarOptItemsSketchDecoder reads a Java-compatible VarOpt sketch from an 
io.Reader.
+type VarOptItemsSketchDecoder[T any] struct {
+       r     io.Reader
+       serde ItemsSerDe[T]
+}
+
+// NewVarOptItemsSketchDecoder creates a decoder with the provided reader and 
serde.
+func NewVarOptItemsSketchDecoder[T any](r io.Reader, serde ItemsSerDe[T]) 
*VarOptItemsSketchDecoder[T] {

Review Comment:
   Also can you return value?



-- 
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]

Reply via email to