Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unmaintained github.com/golang-collections/collections dependency #9469

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions felix/idalloc/index_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"errors"
"sort"

"github.com/golang-collections/collections/stack"

"github.com/projectcalico/calico/libcalico-go/lib/set"
)

Expand All @@ -45,7 +43,7 @@ func (i ByMaxIndex) Less(a, b int) bool { return i[a].Max < i[b].Max }
func (i ByMaxIndex) Swap(a, b int) { i[a], i[b] = i[b], i[a] }

type IndexAllocator struct {
indexStack *stack.Stack
indexStack *stack
exclusions []IndexRange
}

Expand All @@ -58,7 +56,7 @@ func NewIndexAllocator(indexRanges []IndexRange, exclusions []IndexRange) *Index
}

r := &IndexAllocator{
indexStack: stack.New(),
indexStack: &stack{},
exclusions: exclusions,
}

Expand Down Expand Up @@ -91,10 +89,10 @@ func NewIndexAllocator(indexRanges []IndexRange, exclusions []IndexRange) *Index
}

func (r *IndexAllocator) GrabIndex() (int, error) {
if r.indexStack.Len() == 0 {
if r.indexStack.IsEmpty() {
return 0, errors.New("no more indices available")
}
return r.indexStack.Pop().(int), nil
return r.indexStack.Pop(), nil
}

func (r *IndexAllocator) ReleaseIndex(index int) {
Expand All @@ -113,3 +111,36 @@ func (r *IndexAllocator) GrabBlock(len int) (set.Set[int], error) {
}
return indices, nil
}

type (
// stack is an implementation of the stack data structure.
// Adapted from https://github.com/golang-collections/collections/blob/604e922904d35e97f98a774db7881f049cd8d970/stack/stack.go.
stack struct {
top *node
}
node struct {
value int
prev *node
}
)

// IsEmpty returns true if the stack is empty.
func (s *stack) IsEmpty() bool {
return s.top == nil
}

// Pop the top item of the stack and return it
func (s *stack) Pop() int {
if s.IsEmpty() {
return 0
}

n := s.top
s.top = n.prev
return n.value
}

// Push a value onto the top of the stack
func (s *stack) Push(value int) {
s.top = &node{value, s.top}
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ require (
github.com/gofrs/flock v0.8.1
github.com/gogo/googleapis v1.4.1
github.com/gogo/protobuf v1.3.2
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.5.4
github.com/golang/snappy v0.0.4
github.com/google/btree v1.1.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4=
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3/go.mod h1:nPpo7qLxd6XL3hWJG/O60sR8ZKfMCiIoNap5GvD12KU=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down
Loading