Skip to content

Commit

Permalink
perf(algo): single memory allocation in NewCountMinSketch
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Melanchyk <arturmelanchyk@imail.name>
  • Loading branch information
arturmelanchyk committed Jan 18, 2025
1 parent 053a440 commit ac982f9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion algo/cm-sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ func NewCountMinSketch(epsilon, delta float64) *CountMinSketch {
matrix = make([][]uint64, depth)
)

flatMatrix := make([]uint64, width*depth)
for i := uint(0); i < depth; i++ {
matrix[i] = make([]uint64, width)
matrix[i] = flatMatrix[i*width : (i+1)*width : (i+1)*width]
}

return &CountMinSketch{
Expand Down

0 comments on commit ac982f9

Please # to comment.