util

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

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]) Len

func (h *Heap[T]) Len() int

Len returns the number of items in 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.

func (*Heap[T]) Push

func (h *Heap[T]) Push(item T)

Push adds an item to the receiver.

func (*Heap[T]) Remove

func (h *Heap[T]) Remove(item T) bool

Remove removes the given item from the receiver.

func (*Heap[T]) Slice

func (h *Heap[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.

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.

func (Set[T]) Contains

func (s Set[T]) Contains(item T) (found bool)

Contains returns true if the given item is a member of the receiver.

func (Set[T]) Remove

func (s Set[T]) Remove(item T)

Remove removes the given item from the receiver, if it is a member.

func (Set[T]) Slice

func (s Set[T]) Slice() (result []T)

Slice returns members of the receiver in a slice, in unspecified order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL