mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +00:00
lib/uint64set: optimize bucket16.add and bucket16.addMulti a bit
This commit is contained in:
parent
fb935e6e2c
commit
43504ebd14
1 changed files with 10 additions and 8 deletions
|
@ -835,19 +835,22 @@ func (b *bucket16) copyTo(dst *bucket16) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bucket16) add(x uint16) bool {
|
func (b *bucket16) add(x uint16) bool {
|
||||||
if b.bits == nil {
|
bits := b.bits
|
||||||
|
if bits == nil {
|
||||||
return b.addToSmallPool(x)
|
return b.addToSmallPool(x)
|
||||||
}
|
}
|
||||||
wordNum, bitMask := getWordNumBitMask(x)
|
wordNum, bitMask := getWordNumBitMask(x)
|
||||||
word := &b.bits[wordNum]
|
ok := bits[wordNum]&bitMask == 0
|
||||||
ok := *word&bitMask == 0
|
if ok {
|
||||||
*word |= bitMask
|
bits[wordNum] |= bitMask
|
||||||
|
}
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bucket16) addMulti(a []uint64) int {
|
func (b *bucket16) addMulti(a []uint64) int {
|
||||||
count := 0
|
count := 0
|
||||||
if b.bits == nil {
|
bits := b.bits
|
||||||
|
if bits == nil {
|
||||||
// Slow path
|
// Slow path
|
||||||
for _, x := range a {
|
for _, x := range a {
|
||||||
if b.add(uint16(x)) {
|
if b.add(uint16(x)) {
|
||||||
|
@ -858,11 +861,10 @@ func (b *bucket16) addMulti(a []uint64) int {
|
||||||
// Fast path
|
// Fast path
|
||||||
for _, x := range a {
|
for _, x := range a {
|
||||||
wordNum, bitMask := getWordNumBitMask(uint16(x))
|
wordNum, bitMask := getWordNumBitMask(uint16(x))
|
||||||
word := &b.bits[wordNum]
|
if bits[wordNum]&bitMask == 0 {
|
||||||
if *word&bitMask == 0 {
|
bits[wordNum] |= bitMask
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
*word |= bitMask
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
|
|
Loading…
Reference in a new issue