Skip to content

Commit 0da5bcc

Browse files
author
Dan Laine
authored
Remove method CappedList from set.Set (#2395)
1 parent c5169a3 commit 0da5bcc

File tree

3 files changed

+1
-52
lines changed

3 files changed

+1
-52
lines changed

snow/engine/avalanche/bootstrap/bootstrapper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ func (b *bootstrapper) HealthCheck(ctx context.Context) (interface{}, error) {
401401
func (b *bootstrapper) fetch(ctx context.Context, vtxIDs ...ids.ID) error {
402402
b.needToFetch.Add(vtxIDs...)
403403
for b.needToFetch.Len() > 0 && b.outstandingRequests.Len() < maxOutstandingGetAncestorsRequests {
404-
vtxID := b.needToFetch.CappedList(1)[0]
405-
b.needToFetch.Remove(vtxID)
404+
vtxID, _ := b.needToFetch.Pop() // Length checked in predicate above
406405

407406
// Make sure we haven't already requested this vertex
408407
if b.outstandingRequests.HasValue(vtxID) {

utils/set/set.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,27 +118,6 @@ func (s Set[T]) List() []T {
118118
return maps.Keys(s)
119119
}
120120

121-
// CappedList returns a list of length at most [size].
122-
// Size should be >= 0. If size < 0, returns nil.
123-
func (s Set[T]) CappedList(size int) []T {
124-
if size < 0 {
125-
return nil
126-
}
127-
if l := s.Len(); l < size {
128-
size = l
129-
}
130-
i := 0
131-
elts := make([]T, size)
132-
for elt := range s {
133-
if i >= size {
134-
break
135-
}
136-
elts[i] = elt
137-
i++
138-
}
139-
return elts
140-
}
141-
142121
// Equals returns true if the sets contain the same elements
143122
func (s Set[T]) Equals(other Set[T]) bool {
144123
return maps.Equal(s, other)

utils/set/set_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,35 +87,6 @@ func TestOf(t *testing.T) {
8787
}
8888
}
8989

90-
func TestSetCappedList(t *testing.T) {
91-
require := require.New(t)
92-
s := Set[int]{}
93-
94-
id := 0
95-
96-
require.Empty(s.CappedList(0))
97-
98-
s.Add(id)
99-
100-
require.Empty(s.CappedList(0))
101-
require.Len(s.CappedList(1), 1)
102-
require.Equal(s.CappedList(1)[0], id)
103-
require.Len(s.CappedList(2), 1)
104-
require.Equal(s.CappedList(2)[0], id)
105-
106-
id2 := 1
107-
s.Add(id2)
108-
109-
require.Empty(s.CappedList(0))
110-
require.Len(s.CappedList(1), 1)
111-
require.Len(s.CappedList(2), 2)
112-
require.Len(s.CappedList(3), 2)
113-
gotList := s.CappedList(2)
114-
require.Contains(gotList, id)
115-
require.Contains(gotList, id2)
116-
require.NotEqual(gotList[0], gotList[1])
117-
}
118-
11990
func TestSetClear(t *testing.T) {
12091
require := require.New(t)
12192

0 commit comments

Comments
 (0)