freakyzoidberg commented on code in PR #42: URL: https://github.com/apache/datasketches-go/pull/42#discussion_r2068511299
########## count/count_min_sketch.go: ########## @@ -0,0 +1,344 @@ +package count + +import ( + "bytes" + "encoding/binary" + "errors" + "io" + "math" + "math/rand" + + "github.com/apache/datasketches-go/internal" +) + +type CountMinSketch struct { + numBuckets int32 // counter array size for each of the hashing function + numHashes int8 // number of hashing functions + sketchSlice []int64 + seed int64 + totalWeight int64 + hashSeeds []int64 +} + +func NewCountMinSketch(numHashes int8, numBuckets int32, seed int64) (*CountMinSketch, error) { Review Comment: some comments for the public method would be nice :) ########## count/utils.go: ########## @@ -0,0 +1,43 @@ +package count + +import ( + "errors" + "math" + + "golang.org/x/exp/constraints" +) + +func Min[T constraints.Ordered](a, b T) T { + if a < b { + return a + } + return b +} + +func SuggestNumBuckets(relativeError float64) (int32, error) { + if relativeError <= 0 { + return 0, errors.New("relative error must be greater than 0.0") + } + return int32(math.Ceil(math.Exp(1.0) / relativeError)), nil +} + +func SuggestNumHashes(confidence float64) (int8, error) { + if confidence < 0 || confidence > 1.0 { + return 0, errors.New("confidence must be between 0 and 1.0 (inclusive)") + } + return Min(int8(math.Ceil(math.Log(1.0/(1.0-confidence)))), int8(math.MaxInt8)), nil +} + +func checkHeaderValidity(preamble, serVer, familyID, flagsByte byte) error { + return nil +} + +const ( + PreambleLongsShort = 2 + SerialVersion1 = 1 + FamilyId = 18 Review Comment: Can you move that familyId in https://github.com/apache/datasketches-go/blob/04e51ea1586a0a87371baee010dcaeb8a3f1a62b/internal/family.go ? thanks -- 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