Skip to content

Commit

Permalink
Update set.go
Browse files Browse the repository at this point in the history
  • Loading branch information
dboehm-avalabs committed Oct 6, 2023
1 parent 24a853c commit d568664
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions utils/heap/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@ package heap
// NewSet returns a heap without duplicates ordered by its values
func NewSet[T comparable](less func(a, b T) bool) Set[T] {
return Set[T]{
set: Map[T, struct{}]{
queue: &indexedQueue[T, struct{}]{
entries: make([]entry[T, struct{}], 0),
index: make(map[T]int),
less: func(a, b entry[T, struct{}]) bool {
return less(a.k, b.k)
},
},
},
set: NewMap[T, T](less),
}
}

type Set[T comparable] struct {
set Map[T, struct{}]
set Map[T, T]
}

// Push returns if a value was overwritten
func (s Set[T]) Push(t T) bool {
_, ok := s.set.Push(t, struct{}{})
_, ok := s.set.Push(t, t)
return ok
}

Expand Down

0 comments on commit d568664

Please sign in to comment.