Documentation ¶
Index ¶
- func Remove[T comparable](slice *[]T, item T) (removed bool)
- type BlockingHeap
- func (h *BlockingHeap[T]) Clear() (cleared []T)
- func (h *BlockingHeap[T]) Len() int
- func (h *BlockingHeap[T]) Peek() (item T)
- func (h *BlockingHeap[T]) Pop() (item T)
- func (h *BlockingHeap[T]) Push(item T)
- func (h *BlockingHeap[T]) Remove(item T) bool
- func (h *BlockingHeap[T]) Slice() (slice []T)
- func (h *BlockingHeap[T]) Wait()
- type Heap
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Remove ¶
func Remove[T comparable](slice *[]T, item T) (removed bool)
Remove removes the given item from the given slice, or returns false if it's not found.
Types ¶
type BlockingHeap ¶
type BlockingHeap[T comparable] struct { // contains filtered or unexported fields }
BlockingHeap implements a min-heap for values of type T. It is identical to Heap, but also maintains a sync.WaitGroup that unblocks when the heap has no members.
This type isn't being used at the moment, but could be used to replace eon.Scheduler.running if we need to wait for all its running jobs to complete.
A zero BlockingHeap is not valid. Use NewBlockingHeap instead.
func NewBlockingHeap ¶
func NewBlockingHeap[T comparable](less func(a, b T) bool) *BlockingHeap[T]
NewBlockingHeap creates a new BlockingHeap using the given less function for sort comparisons.
func (*BlockingHeap[T]) Clear ¶
func (h *BlockingHeap[T]) Clear() (cleared []T)
Clear removes all items from the receiver.
func (*BlockingHeap[T]) Len ¶
func (h *BlockingHeap[T]) Len() int
Len returns the number of items in the receiver.
func (*BlockingHeap[T]) Peek ¶
func (h *BlockingHeap[T]) Peek() (item T)
Peek returns the item at the top of the receiver without removing it. If the receiver is empty, a zero value of the receiver's type T is returned instead.
func (*BlockingHeap[T]) Pop ¶
func (h *BlockingHeap[T]) Pop() (item T)
Pop removes and returns the item at the top of the receiver.
func (*BlockingHeap[T]) Push ¶
func (h *BlockingHeap[T]) Push(item T)
Push adds an item to the receiver.
func (*BlockingHeap[T]) Remove ¶
func (h *BlockingHeap[T]) Remove(item T) bool
Remove removes the given item from the receiver.
func (*BlockingHeap[T]) Slice ¶
func (h *BlockingHeap[T]) Slice() (slice []T)
Slice returns a slice of all items in the receiver. The item at the top of the receiver will be at the end of the slice. The order of all other items should be considered random.
func (*BlockingHeap[T]) Wait ¶
func (h *BlockingHeap[T]) Wait()
Wait blocks while the receiver is not empty.
type Heap ¶
type Heap[T comparable] struct { // contains filtered or unexported fields }
Heap implements a min-heap for values of type T.
A zero Heap is not valid. Use NewHeap instead.
func NewHeap ¶
func NewHeap[T comparable](less func(a, b T) bool) *Heap[T]
NewHeap creates a new Heap using the given less function for sort comparisons.
func (*Heap[T]) Clear ¶
func (h *Heap[T]) Clear() (cleared []T)
Clear removes all items from the receiver.
func (*Heap[T]) Peek ¶
func (h *Heap[T]) Peek() (item T)
Peek returns the item at the top of the receiver without removing it. If the receiver is empty, a zero value of the receiver's type T is returned instead.
func (*Heap[T]) Pop ¶
func (h *Heap[T]) Pop() (item T)
Pop removes and returns the item at the top of the receiver.
type Set ¶
type Set[T comparable] map[T]struct{}
Set is a generic set implementation backed by a map.
A zero Set, like a zero map, is not valid. Use NewSet or make(Set[T]) instead.
func NewSet ¶
func NewSet[T comparable](items ...T) (result Set[T])
NewSet creates a new Set containing the given items.
func (Set[T]) Add ¶
func (s Set[T]) Add(item T)
Add adds the given item to the receiver, if it is not already a member.