Skip to content

Commit

Permalink
statistics: use slices.BinarySearchFunc to simple TopN.FindTopN (#46996)
Browse files Browse the repository at this point in the history
ref #45933
  • Loading branch information
hawkingrei authored Sep 15, 2023
1 parent 331ae3d commit 9ec7872
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions statistics/cmsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,8 @@ func (c *TopN) FindTopN(d []byte) int {
if c == nil {
return -1
}
match := false
idx := sort.Search(len(c.TopN), func(i int) bool {
cmpRst := bytes.Compare(c.TopN[i].Encoded, d)
if cmpRst == 0 {
match = true
}
return cmpRst >= 0
idx, match := slices.BinarySearchFunc(c.TopN, d, func(a TopNMeta, b []byte) int {
return bytes.Compare(a.Encoded, b)
})
if !match {
return -1
Expand Down

0 comments on commit 9ec7872

Please sign in to comment.