caravan

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 2 Imported by: 1

README

caravan

Caravan is a generic version of the list package.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPriorityQueueEmpty = errors.New("priority queue has no elements")
)
View Source
var (
	ErrQueueEmpty = errors.New("queue has no elements")
)

Functions

This section is empty.

Types

type Element

type Element[T any] struct {

	// The value stored with this element.
	Value T
	// contains filtered or unexported fields
}

Element is an element of a linked list.

func (*Element[T]) Next

func (e *Element[T]) Next() *Element[T]

Next returns the next list element or nil.

func (*Element[T]) Prev

func (e *Element[T]) Prev() *Element[T]

Prev returns the previous list element or nil.

type GIDX added in v1.1.0

type GIDX struct {
	// contains filtered or unexported fields
}

type GIDXAllocator added in v1.1.0

type GIDXAllocator struct {
	// contains filtered or unexported fields
}

func NewGIDXAllocator added in v1.1.0

func NewGIDXAllocator() *GIDXAllocator

func (*GIDXAllocator) Allocate added in v1.1.0

func (g *GIDXAllocator) Allocate() GIDX

func (*GIDXAllocator) Deallocate added in v1.1.0

func (g *GIDXAllocator) Deallocate(i GIDX) bool

func (*GIDXAllocator) IsLive added in v1.1.0

func (g *GIDXAllocator) IsLive(i GIDX) bool

type GIDXArray added in v1.1.0

type GIDXArray[T any] []GIDXArrayEntry[T]

func NewGIDXArray added in v1.1.0

func NewGIDXArray[T any]() GIDXArray[T]

func (GIDXArray[T]) First added in v1.1.0

func (g GIDXArray[T]) First(a *GIDXAllocator) (GIDX, T)

func (GIDXArray[T]) Get added in v1.1.0

func (g GIDXArray[T]) Get(index GIDX) T

func (GIDXArray[T]) GetAll added in v1.1.0

func (g GIDXArray[T]) GetAll(a *GIDXAllocator) []T

func (GIDXArray[T]) GetAllIndices added in v1.1.0

func (g GIDXArray[T]) GetAllIndices(a *GIDXAllocator) []GIDX

func (GIDXArray[T]) Remove added in v1.1.0

func (g GIDXArray[T]) Remove(index GIDX) GIDXArray[T]

func (GIDXArray[T]) Set added in v1.1.0

func (g GIDXArray[T]) Set(index GIDX, value T) GIDXArray[T]

type GIDXArrayEntry added in v1.1.0

type GIDXArrayEntry[T any] struct {
	// contains filtered or unexported fields
}

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func NewList

func NewList[T any]() *List[T]

New returns an initialized list.

func (*List[T]) Back

func (l *List[T]) Back() *Element[T]

Back returns the last element of list l or nil if the list is empty.

func (*List[T]) Front

func (l *List[T]) Front() *Element[T]

Front returns the first element of list l or nil if the list is empty.

func (*List[T]) Init

func (l *List[T]) Init() *List[T]

Init initializes or clears list l.

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(v T, mark *Element[T]) *Element[T]

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(v T, mark *Element[T]) *Element[T]

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List[T]) Len

func (l *List[T]) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*List[T]) MoveAfter

func (l *List[T]) MoveAfter(e, mark *Element[T])

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List[T]) MoveBefore

func (l *List[T]) MoveBefore(e, mark *Element[T])

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List[T]) MoveToBack

func (l *List[T]) MoveToBack(e *Element[T])

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) MoveToFront

func (l *List[T]) MoveToFront(e *Element[T])

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) PushBack

func (l *List[T]) PushBack(v T) *Element[T]

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*List[T]) PushBackList

func (l *List[T]) PushBackList(other *List[T])

PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.

func (*List[T]) PushFront

func (l *List[T]) PushFront(v T) *Element[T]

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List[T]) PushFrontList

func (l *List[T]) PushFrontList(other *List[T])

PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.

func (*List[T]) Remove

func (l *List[T]) Remove(e *Element[T]) T

Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.

type PriorityQueue added in v1.2.0

type PriorityQueue[T any] struct {
	// contains filtered or unexported fields
}

func NewPriorityQueue added in v1.2.0

func NewPriorityQueue[T any](reverse bool) *PriorityQueue[T]

func (*PriorityQueue[T]) Dequeue added in v1.2.0

func (pq *PriorityQueue[T]) Dequeue() (T, error)

func (*PriorityQueue[T]) Enqueue added in v1.2.0

func (pq *PriorityQueue[T]) Enqueue(value T, priority int)

func (*PriorityQueue[T]) Len added in v1.2.0

func (pq *PriorityQueue[T]) Len() int

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any]() *Queue[T]

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() (T, error)

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(v T)

func (*Queue[T]) Init

func (q *Queue[T]) Init() *Queue[T]

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func NewStack

func NewStack[T any]() *Stack[T]

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

Jump to

Keyboard shortcuts

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