collection

package
v2.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEmptyListError

func NewEmptyListError() errors.TracerError

NewEmptyListError instantiates a EmptyListError with a stack trace

func NewListNonEmptyError

func NewListNonEmptyError() errors.TracerError

NewListNonEmptyError instantiates a ListNonEmptyError with a stack trace

func NewNoElementError

func NewNoElementError() errors.TracerError

NewNoElementError instantiates a NoElementError with a stack trace

func NewNoMemberError

func NewNoMemberError() errors.TracerError

NewNoMemberError instantiates a NoMemberError with a stack trace

Types

type DList

type DList[T any] interface {
	// Size of the this dlist as a count of the elements in it.
	Size() int
	// Head of the list.
	Head() *DListElement[T]
	// IsHead of the list.
	IsHead(element *DListElement[T]) bool
	// Tail of the list.
	Tail() *DListElement[T]
	// IsTail of the list.
	IsTail(element *DListElement[T]) bool
	// InsertNext inserts the passed data after the passed element. If the list is empty a 'nil' element is allowed
	// otherwise an error will be returned.
	InsertNext(element *DListElement[T], data T) (*DListElement[T], error)
	// InsertPrevious inserts the passed data before the passed element in the list. If the list is empty a 'nil' element
	// is allowed, otherwise an error will be returned.
	InsertPrevious(element *DListElement[T], data T) (*DListElement[T], error)
	// Remove the element from the list.
	Remove(element *DListElement[T]) (data T, err error)
}

DList is an implementation of a doubly linked list data structure.

func NewDList

func NewDList[T any]() DList[T]

NewDList returns a new initialized empty DList

type DListElement

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

DListElement is the primary element for use inside of a DList

func (DListElement[T]) Data

func (element DListElement[T]) Data() T

Data in this DListElement[T]

func (DListElement[T]) Next

func (element DListElement[T]) Next() *DListElement[T]

Next element in the DList.

func (DListElement[T]) Previous

func (element DListElement[T]) Previous() *DListElement[T]

Previous element in the Dlist

type EmptyListError

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

EmptyListError is returned when a operation is called on an empty list that requires at least one element in the list.

func (*EmptyListError) Error

func (err *EmptyListError) Error() string

func (*EmptyListError) Trace

func (err *EmptyListError) Trace() []string

Trace returns the stack trace for the error

type GetPivotKeys added in v2.2.0

type GetPivotKeys[T, Y comparable] func(obj T) []Y

GetPivotKeys type Y for the object T

type List

type List[T any] interface {
	// Head (first element) of the list.
	Head() *ListElement[T]
	// Tail (last element) of the list.
	Tail() (element *ListElement[T])
	// IsHead returns a boolean indicating whether the passed element is the first element in the list.
	IsHead(element *ListElement[T]) bool
	// IsTail returns a boolean indicating if the passed element is the last element in the list.
	IsTail(element *ListElement[T]) bool
	// Size of the list (number of elements).
	Size() int
	// InsertNext data into the list after the passed element. If the element is nil, the data will be inserted at
	// the head of the list.
	InsertNext(element *ListElement[T], data T) *ListElement[T]
	// RemoveNext element from the list and return it's data. If passed element is 'nil' the head will be removed
	// from the list.
	RemoveNext(element *ListElement[T]) (data T, err error)
}

List is a singly linked list implementation

func NewList

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

NewList returns a new initialized list.

type ListElement

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

ListElement is a singly linked node in a list.

func (ListElement[T]) Data

func (listElement ListElement[T]) Data() T

Data returns the data contained in this element.

func (ListElement[T]) Next

func (listElement ListElement[T]) Next() (element *ListElement[T])

Next returns the element the follows this element.

type ListNonEmptyError

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

ListNonEmptyError is returned when a empty list is required for the operation.

func (*ListNonEmptyError) Error

func (err *ListNonEmptyError) Error() string

func (*ListNonEmptyError) Trace

func (err *ListNonEmptyError) Trace() []string

Trace returns the stack trace for the error

type NoElementError

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

NoElementError is returned when an operation that requires an element is called when no element is present at that position.

func (*NoElementError) Error

func (err *NoElementError) Error() string

func (*NoElementError) Trace

func (err *NoElementError) Trace() []string

Trace returns the stack trace for the error

type NoMemberError

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

NoMemberError is returned when an element is passed that is not a member of a list.

func (*NoMemberError) Error

func (err *NoMemberError) Error() string

func (*NoMemberError) Trace

func (err *NoMemberError) Trace() []string

Trace returns the stack trace for the error

type Pivot added in v2.2.0

type Pivot[T, Y comparable] interface {
	// Add the passed comparables to the pivot
	Add(...T)
	// Get comparables who share a pivot key
	Get(Y) []T
	// Remove the passed comparable from the index
	Remove(T)
	// Len is the cardinality of the set of keys Y
	Len() int
}

Pivot for a field comparable field of type Y that is a member of objects of type T

func NewPivot added in v2.2.0

func NewPivot[T, Y comparable](getter GetPivotKeys[T, Y], init ...T) Pivot[T, Y]

NewPivot for the field of type Y that is a member of type T

type Queue

type Queue[T any] interface {
	// Size of the queue represented as a count of the elements in the queue.
	Size() int
	// Push a new data element onto the queue.
	Push(data T)
	// Pop the most recently pushed data element off the queue.
	Pop() (T, error)
	// Peek returns the most recently pushed element without modifying the queue
	Peek() (T, error)
}

Queue is an implementation of a queue (fifo) data structure

func NewQueue

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

NewQueue that is empty.

type Set

type Set[T comparable] interface {
	// Add the passed objects to the set
	Add(objs ...T) Set[T]
	// Remove the passed objects from the set
	Remove(objs ...T) Set[T]
	// Contains the passed object
	Contains(T) bool
	// Elements in this set
	Elements() []T
	// Size of this set (number of elements)
	Size() int
	// New set of the same type as this set
	New() Set[T]
}

Set data structure methods.

func Disjunction

func Disjunction[T comparable](a, b Set[T]) Set[T]

Disjunction of sets a and b as a new set of the same type as a.

func Intersection

func Intersection[T comparable](a, b Set[T]) Set[T]

Intersection of sets a and b as a new set of the same type as a.

func NewSet

func NewSet[T comparable](objs ...T) Set[T]

NewSet instance.

func Union

func Union[T comparable](a, b Set[T]) Set[T]

Union of sets a and b as a new set of the same type as a.

type Stack

type Stack[T any] interface {
	// Size of the stack represented as a count of the elements in the stack.
	Size() int
	// Push a new data element onto the stack.
	Push(data T)
	// Pop the most recently pushed data element off the stack.
	Pop() (T, error)
	// Peek returns the most recently pushed element without modifying the stack
	Peek() (T, error)
}

Stack is an implementation of a stack (filo/lifo) datastructure

func NewStack

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

NewStack that is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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