Merge pull request #80315 from klueska/upstream-cleanup-socketmask

Cleanup the TopologyManager socketmask abstraction
This commit is contained in:
Kubernetes Prow Robot 2019-07-23 11:40:28 -07:00 committed by GitHub
commit 5b496fe8f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 14 deletions

View File

@ -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
}

View File

@ -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)