mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Add AnySet() to topologymanager bitmask API
This commit is contained in:
parent
d9c3d15018
commit
9f5f401d60
@ -33,6 +33,7 @@ type BitMask interface {
|
|||||||
IsEqual(mask BitMask) bool
|
IsEqual(mask BitMask) bool
|
||||||
IsEmpty() bool
|
IsEmpty() bool
|
||||||
IsSet(bit int) bool
|
IsSet(bit int) bool
|
||||||
|
AnySet(bits []int) bool
|
||||||
IsNarrowerThan(mask BitMask) bool
|
IsNarrowerThan(mask BitMask) bool
|
||||||
String() string
|
String() string
|
||||||
Count() int
|
Count() int
|
||||||
@ -120,6 +121,16 @@ func (s *bitMask) IsSet(bit int) bool {
|
|||||||
return (*s & (1 << uint64(bit))) > 0
|
return (*s & (1 << uint64(bit))) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AnySet checks bit in mask to see if any provided bit is set to one
|
||||||
|
func (s *bitMask) AnySet(bits []int) bool {
|
||||||
|
for _, b := range bits {
|
||||||
|
if s.IsSet(b) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// IsEqual checks if masks are equal
|
// IsEqual checks if masks are equal
|
||||||
func (s *bitMask) IsEqual(mask BitMask) bool {
|
func (s *bitMask) IsEqual(mask BitMask) bool {
|
||||||
return *s == *mask.(*bitMask)
|
return *s == *mask.(*bitMask)
|
||||||
|
@ -381,6 +381,53 @@ func TestIsSet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAnySet(t *testing.T) {
|
||||||
|
tcases := []struct {
|
||||||
|
name string
|
||||||
|
mask []int
|
||||||
|
checkBits []int
|
||||||
|
expectedSet bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Check if any bits from 11 in mask 00 is set",
|
||||||
|
mask: nil,
|
||||||
|
checkBits: []int{0, 1},
|
||||||
|
expectedSet: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Check if any bits from 11 in mask 01 is set",
|
||||||
|
mask: []int{0},
|
||||||
|
checkBits: []int{0, 1},
|
||||||
|
expectedSet: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Check if any bits from 11 in mask 11 is set",
|
||||||
|
mask: []int{0, 1},
|
||||||
|
checkBits: []int{0, 1},
|
||||||
|
expectedSet: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Check if any bit outside range 0-63 is set",
|
||||||
|
mask: []int{0, 1},
|
||||||
|
checkBits: []int{64, 65},
|
||||||
|
expectedSet: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Check if any bits from 1001 in mask 0110 is set",
|
||||||
|
mask: []int{1, 2},
|
||||||
|
checkBits: []int{0, 3},
|
||||||
|
expectedSet: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range tcases {
|
||||||
|
mask, _ := NewBitMask(tc.mask...)
|
||||||
|
set := mask.AnySet(tc.checkBits)
|
||||||
|
if set != tc.expectedSet {
|
||||||
|
t.Errorf("Expected value to be %v, got %v", tc.expectedSet, set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIsEqual(t *testing.T) {
|
func TestIsEqual(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
|
Loading…
Reference in New Issue
Block a user