freakyzoidberg commented on code in PR #29:
URL: https://github.com/apache/datasketches-go/pull/29#discussion_r2001706905


##########
cpc/cpc_sketch.go:
##########
@@ -513,3 +535,149 @@ func (c *CpcSketch) ToCompactSlice() ([]byte, error) {
     return (byte[]) wmem.getArray();
   }
 */
+
+// GetFamily returns the CPC family identifier.
+func (c *CpcSketch) GetFamily() internal.Family {
+       return internal.FamilyEnum.CPC
+}
+
+// GetLgK returns the log-base-2 of K.
+func (c *CpcSketch) GetLgK() int {
+       return c.lgK
+}
+
+// IsEmpty returns true if no coupons have been collected.
+func (c *CpcSketch) IsEmpty() bool {
+       return c.numCoupons == 0
+}
+
+// Validate recomputes the coupon count from the bit matrix and returns true 
if it matches the sketch's numCoupons.
+func (c *CpcSketch) Validate() bool {
+       bitMatrix := c.bitMatrixOfSketch()
+       matrixCoupons := countBitsSetInMatrix(bitMatrix)
+       return matrixCoupons == c.numCoupons
+}
+
+// Copy creates and returns a deep copy of the CpcSketch.
+func (c *CpcSketch) Copy() *CpcSketch {
+       // Create a new sketch with the same lgK and seed.
+       copySketch, err := NewCpcSketch(c.lgK, c.seed)
+       if err != nil {
+               // This should never happen if the current sketch is valid.
+               panic(err)
+       }
+       // Copy basic fields.
+       copySketch.numCoupons = c.numCoupons
+       copySketch.mergeFlag = c.mergeFlag
+       copySketch.fiCol = c.fiCol
+       copySketch.windowOffset = c.windowOffset
+
+       // Clone the slidingWindow slice if present.
+       if c.slidingWindow != nil {
+               copySketch.slidingWindow = make([]byte, len(c.slidingWindow))
+               copy(copySketch.slidingWindow, c.slidingWindow)
+       } else {
+               copySketch.slidingWindow = nil
+       }
+
+       // Copy the pair table if present.
+       if c.pairTable != nil {
+               copySketch.pairTable = c.pairTable.Copy() // Assumes pairTable 
has a Copy() method.
+       } else {
+               copySketch.pairTable = nil
+       }
+
+       // Copy floating-point accumulators.
+       copySketch.kxp = c.kxp
+       copySketch.hipEstAccum = c.hipEstAccum
+
+       /*
+               Added the copy of the scratch buffer to ensure that every 
field, even temporary ones, in the struct is duplicated,
+               so that the copy is entirely independent of the original. Since 
the scratch buffer is part of the struct, we copy it too.
+       */
+       copy(copySketch.scratch[:], c.scratch[:])
+
+       return copySketch
+}
+
+// RefreshKXP recalculates the KXP register of the sketch from the given 
bitMatrix.
+// It improves numerical accuracy by summing the contributions of each byte 
separately.
+func (c *CpcSketch) RefreshKXP(bitMatrix []uint64) error {

Review Comment:
   refreshKXP (no need to make that public)



-- 
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-unsubscr...@datasketches.apache.org

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


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

Reply via email to