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 method CappedList from set.Set #2395

Merged
merged 1 commit into from
Nov 29, 2023
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
3 changes: 1 addition & 2 deletions snow/engine/avalanche/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ func (b *bootstrapper) HealthCheck(ctx context.Context) (interface{}, error) {
func (b *bootstrapper) fetch(ctx context.Context, vtxIDs ...ids.ID) error {
b.needToFetch.Add(vtxIDs...)
for b.needToFetch.Len() > 0 && b.outstandingRequests.Len() < maxOutstandingGetAncestorsRequests {
vtxID := b.needToFetch.CappedList(1)[0]
b.needToFetch.Remove(vtxID)
vtxID, _ := b.needToFetch.Pop() // Length checked in predicate above

// Make sure we haven't already requested this vertex
if b.outstandingRequests.HasValue(vtxID) {
Expand Down
21 changes: 0 additions & 21 deletions utils/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,6 @@ func (s Set[T]) List() []T {
return maps.Keys(s)
}

// CappedList returns a list of length at most [size].
// Size should be >= 0. If size < 0, returns nil.
func (s Set[T]) CappedList(size int) []T {
if size < 0 {
return nil
}
if l := s.Len(); l < size {
size = l
}
i := 0
elts := make([]T, size)
for elt := range s {
if i >= size {
break
}
elts[i] = elt
i++
}
return elts
}

// Equals returns true if the sets contain the same elements
func (s Set[T]) Equals(other Set[T]) bool {
return maps.Equal(s, other)
Expand Down
29 changes: 0 additions & 29 deletions utils/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,6 @@ func TestOf(t *testing.T) {
}
}

func TestSetCappedList(t *testing.T) {
require := require.New(t)
s := Set[int]{}

id := 0

require.Empty(s.CappedList(0))

s.Add(id)

require.Empty(s.CappedList(0))
require.Len(s.CappedList(1), 1)
require.Equal(s.CappedList(1)[0], id)
require.Len(s.CappedList(2), 1)
require.Equal(s.CappedList(2)[0], id)

id2 := 1
s.Add(id2)

require.Empty(s.CappedList(0))
require.Len(s.CappedList(1), 1)
require.Len(s.CappedList(2), 2)
require.Len(s.CappedList(3), 2)
gotList := s.CappedList(2)
require.Contains(gotList, id)
require.Contains(gotList, id2)
require.NotEqual(gotList[0], gotList[1])
}

func TestSetClear(t *testing.T) {
require := require.New(t)

Expand Down
Loading