mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #80315 from klueska/upstream-cleanup-socketmask
Cleanup the TopologyManager socketmask abstraction
This commit is contained in:
commit
5b496fe8f5
@ -39,6 +39,12 @@ type SocketMask interface {
|
||||
|
||||
type socketMask uint64
|
||||
|
||||
// NewEmptySocketMask creates a new, empty SocketMask
|
||||
func NewEmptySocketMask() SocketMask {
|
||||
s := socketMask(0)
|
||||
return &s
|
||||
}
|
||||
|
||||
// NewSocketMask creates a new SocketMask
|
||||
func NewSocketMask(sockets ...int) (SocketMask, error) {
|
||||
s := socketMask(0)
|
||||
@ -165,3 +171,17 @@ func (s *socketMask) GetSockets() []int {
|
||||
}
|
||||
return sockets
|
||||
}
|
||||
|
||||
// And is a package level implementation of 'and' between first and masks
|
||||
func And(first SocketMask, masks ...SocketMask) SocketMask {
|
||||
s := *first.(*socketMask)
|
||||
s.And(masks...)
|
||||
return &s
|
||||
}
|
||||
|
||||
// Or is a package level implementation of 'or' between first and masks
|
||||
func Or(first SocketMask, masks ...SocketMask) SocketMask {
|
||||
s := *first.(*socketMask)
|
||||
s.Or(masks...)
|
||||
return &s
|
||||
}
|
||||
|
@ -106,6 +106,12 @@ func TestAnd(t *testing.T) {
|
||||
for _, tc := range tcases {
|
||||
firstMask, _ := NewSocketMask(tc.firstMaskBit)
|
||||
secondMask, _ := NewSocketMask(tc.secondMaskBit)
|
||||
|
||||
result := And(firstMask, secondMask)
|
||||
if result.String() != string(tc.andMask) {
|
||||
t.Errorf("Expected mask to be %v, got %v", tc.andMask, result)
|
||||
}
|
||||
|
||||
firstMask.And(secondMask)
|
||||
if firstMask.String() != string(tc.andMask) {
|
||||
t.Errorf("Expected mask to be %v, got %v", tc.andMask, firstMask)
|
||||
@ -130,6 +136,12 @@ func TestOr(t *testing.T) {
|
||||
for _, tc := range tcases {
|
||||
firstMask, _ := NewSocketMask(tc.firstMaskBit)
|
||||
secondMask, _ := NewSocketMask(tc.secondMaskBit)
|
||||
|
||||
result := Or(firstMask, secondMask)
|
||||
if result.String() != string(tc.orMask) {
|
||||
t.Errorf("Expected mask to be %v, got %v", tc.orMask, result)
|
||||
}
|
||||
|
||||
firstMask.Or(secondMask)
|
||||
if firstMask.String() != string(tc.orMask) {
|
||||
t.Errorf("Expected mask to be %v, got %v", tc.orMask, firstMask)
|
||||
|
Loading…
Reference in New Issue
Block a user