mirror of
https://github.com/temporalio/temporal.git
synced 2026-08-30 18:41:49 -07:00
## What changed? Add scale manager component. ## Why? Part of dynamic partitioning. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [x] added new functional test(s) - to come in future PRs ## Potential risks No behavior changes yet.
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package matching
|
|
|
|
import "math/bits"
|
|
|
|
// bitSet encapsulates simple bit manipulation functions on a uint64 slice.
|
|
type bitSet []uint64
|
|
|
|
// len returns the index of the highest set bit.
|
|
func (bs bitSet) len() int32 {
|
|
i := len(bs) - 1
|
|
if i < 0 {
|
|
return 0
|
|
}
|
|
return int32(bits.Len64(bs[i]) + i*64)
|
|
}
|
|
|
|
// get returns true if a specific bit is set.
|
|
func (bs bitSet) get(i int32) bool {
|
|
if len(bs) < int(i)/64+1 {
|
|
return false
|
|
}
|
|
return bs[i/64]&(1<<(i%64)) != 0
|
|
}
|
|
|
|
// set sets a bit, growing the slice if necessary.
|
|
// note: caller must assign the result, as with append.
|
|
func (bs bitSet) set(i int32) bitSet {
|
|
for len(bs) < int(i)/64+1 {
|
|
bs = append(bs, 0)
|
|
}
|
|
bs[i/64] |= 1 << (i % 64)
|
|
return bs
|
|
}
|
|
|
|
// clear clears a bit (and shrinks the slice to the minimum required).
|
|
// note: caller must assign the result, as with append.
|
|
func (bs bitSet) clear(i int32) bitSet {
|
|
if len(bs) < int(i)/64+1 {
|
|
return bs
|
|
}
|
|
bs[i/64] &^= 1 << (i % 64)
|
|
for len(bs) > 0 && bs[len(bs)-1] == 0 {
|
|
bs = bs[:len(bs)-1]
|
|
}
|
|
return bs
|
|
}
|