container

package
v0.0.0-...-c3901be Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FIFO

type FIFO[E any] []E

FIFO is a First-In-First-Out queue.

func (*FIFO[E]) Len

func (q *FIFO[E]) Len() int

Len returns the length of the queue.

func (*FIFO[E]) Peek

func (q *FIFO[E]) Peek() (e E)

Peek at the next element in the queue.

func (*FIFO[E]) Pop

func (q *FIFO[E]) Pop() (e E)

Pop an element from the queue.

func (*FIFO[E]) Push

func (q *FIFO[E]) Push(e E)

Push an element unto the queue.

type Heap

type Heap[E constraints.Ordered] []E

Heap implements a min-heap.

func (*Heap[E]) Fix

func (h *Heap[E]) Fix(i int)

Fix re-establishes the heap ordering after the element at index i has changed its value. Changing the value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling Remove(h, i) followed by a Push of the new value.

The complexity is O(log n) where n = h.Len().

func (*Heap[E]) Init

func (h *Heap[E]) Init()

Init establishes the heap invariants required by the other routines in this package. Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated.

The complexity is O(n) where n = h.Len().

func (*Heap[E]) Len

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

Len returns the numuüber of elements in h.

func (*Heap[E]) Pop

func (h *Heap[E]) Pop() E

Pop removes and returns the minimum element (according to Less) from the heap. Pop is equivalent to Remove(h, 0).

The complexity is O(log n) where n = h.Len().

func (*Heap[E]) Push

func (h *Heap[E]) Push(e E)

Push pushes the element e onto the heap.

The complexity is O(log n) where n = h.Len().

func (*Heap[E]) Remove

func (h *Heap[E]) Remove(i int) E

Remove removes and returns the element at index i from the heap.

The complexity is O(log n) where n = h.Len().

type HeapFunc

type HeapFunc[E any] struct {
	Elements []E
	Less     func(E, E) bool
}

HeapFunc implements a min-heap with custom comparison.

func (*HeapFunc[E]) Fix

func (h *HeapFunc[E]) Fix(i int)

Fix re-establishes the heap ordering after the element at index i has changed its value. Changing the value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling Remove(h, i) followed by a Push of the new value.

The complexity is O(log n) where n = h.Len().

func (*HeapFunc[E]) Init

func (h *HeapFunc[E]) Init()

Init establishes the heap invariants required by the other routines in this package. Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated.

The complexity is O(n) where n = h.Len().

func (*HeapFunc[E]) Len

func (h *HeapFunc[E]) Len() int

Len returns the numuüber of elements in h.

func (*HeapFunc[E]) Pop

func (h *HeapFunc[E]) Pop() E

Pop removes and returns the minimum element (according to Less) from the heap. Pop is equivalent to Remove(h, 0).

The complexity is O(log n) where n = h.Len().

func (*HeapFunc[E]) Push

func (h *HeapFunc[E]) Push(e E)

Push pushes the element e onto the heap.

The complexity is O(log n) where n = h.Len().

func (*HeapFunc[E]) Remove

func (h *HeapFunc[E]) Remove(i int) E

Remove removes and returns the element at index i from the heap.

The complexity is O(log n) where n = h.Len().

type LIFO

type LIFO[E any] []E

LIFO is a Last-In-First-Out queue (also known as a stack).

func (*LIFO[E]) Len

func (q *LIFO[E]) Len() int

Len returns the length of the queue.

func (*LIFO[E]) Peek

func (q *LIFO[E]) Peek() (e E)

func (*LIFO[E]) Pop

func (q *LIFO[E]) Pop() (e E)

Pop an element from the queue.

func (*LIFO[E]) Push

func (q *LIFO[E]) Push(e E)

Push an element unto the queue.

type RingBuffer

type RingBuffer[E any] struct {
	// contains filtered or unexported fields
}

func NewRingBuffer

func NewRingBuffer[E any](b []E) *RingBuffer[E]

NewRingBuffer uses b as a ring buffer. The capacity of the buffer is cap(b) and b[:len(b)] are the initial contents. So make([]E, 0, N) is an empty buffer of size N.

func (*RingBuffer[E]) Cap

func (b *RingBuffer[E]) Cap() int

Cap returns the capacity of the buffer.

func (*RingBuffer[E]) Len

func (b *RingBuffer[E]) Len() int

Len returns the number of elements currently in the buffer.

func (*RingBuffer[E]) Pop

func (b *RingBuffer[E]) Pop() E

Pop reads an element from the buffer.

func (*RingBuffer[E]) Push

func (b *RingBuffer[E]) Push(e E)

Push adds e to the buffer.

Jump to

Keyboard shortcuts

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