collections

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package collections contains custom collection types.

Package collections contains custom collection types.

Package collections contains custom collection types.

Package collections contains custom collection types.

Package collections contains custom collection types.

Package collections contains custom collection types.

Package collections contains custom collection types.

Package collections contains custom collection types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeGrid added in v0.5.2

func MakeGrid[T any](rows, cols int) [][]T

MakeGrid creates a fully allocated 2d slice of a given type and size.

Types

type LinkedList added in v0.5.2

type LinkedList[T any] struct {
	Head *ListNode[T]
	Tail *ListNode[T]
}

LinkedList is a doubly linked list.

func NewLinkedList added in v0.5.2

func NewLinkedList[T any]() *LinkedList[T]

NewLinkedList creates a new linked list.

func (*LinkedList[T]) Add added in v0.5.2

func (l *LinkedList[T]) Add(value T)

Add adds an element to the linked list. This element will be added to the top of the list for speed.

func (*LinkedList[T]) Append added in v0.5.2

func (l *LinkedList[T]) Append(value T)

Append adds an element to the linked list. This element will be added to the end of the list.

func (*LinkedList[T]) GetValueAt added in v0.5.2

func (l *LinkedList[T]) GetValueAt(index int) (T, error)

GetValueAt returns the value in the node at the specified index.

func (*LinkedList[T]) Insert added in v0.5.2

func (l *LinkedList[T]) Insert(value T, index int) error

Insert adds an element to the linked list. This element will be added at the specified index.

type List added in v0.5.2

type List[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

List is a general purpose List class based on slices.

func NewList added in v0.5.2

func NewList[T cmp.Ordered]() *List[T]

NewList creates a new list.

func (*List[T]) Append added in v0.5.2

func (l *List[T]) Append(value T)

Append appends a value to the end of the list.

func (*List[T]) Clear added in v0.5.2

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

Clear removes all elements from the list.

func (*List[T]) Contains added in v0.5.2

func (l *List[T]) Contains(value T) bool

Contains returns whether or not the list contains the specified value.

func (*List[T]) Filter added in v0.5.2

func (l *List[T]) Filter(filterFunc func(T) bool) *List[T]

Filter returns a new list with the elements that pass the filter function.

func (*List[T]) Get added in v0.5.2

func (l *List[T]) Get(index int) (T, error)

Get returns the indexed value from the list.

func (*List[T]) GetFirst added in v0.5.2

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

GetFirst returns the first element in the list.

func (*List[T]) GetLast added in v0.5.2

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

GetLast returns the last element in the list.

func (*List[T]) GetRandom added in v0.5.2

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

GetRandom returns a random element from the list.

func (*List[T]) IndexOf added in v0.5.2

func (l *List[T]) IndexOf(value T) int

IndexOf returns the index of the speified value if it is in the list, or -1 if not.

func (*List[T]) Insert added in v0.5.2

func (l *List[T]) Insert(index int, value T) error

Insert inserts a value at the given index.

func (*List[T]) Length added in v0.5.2

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

Length returns the number of elements in the list.

func (*List[T]) Map added in v0.5.2

func (l *List[T]) Map(mapFunc func(T) T) *List[T]

Map returns a new list with elements obtained by applying the map function to each element.

func (*List[T]) Prepend added in v0.5.2

func (l *List[T]) Prepend(value T)

Prepend prepends a value to the start of the list.

func (*List[T]) Remove added in v0.5.2

func (l *List[T]) Remove(index int) (T, error)

Remove removes and returns the indexed value from the list.

func (*List[T]) RemoveFirst added in v0.5.2

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

RemoveFirst removes and returns the first value on the list.

func (*List[T]) RemoveLast added in v0.5.2

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

RemoveLast removes and returns the last value on the list.

func (*List[T]) Reverse added in v0.5.2

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

Reverse reverses the list.

func (*List[T]) Shuffle added in v0.5.2

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

Shuffle randomly shuffles the list.

func (*List[T]) Slice added in v0.5.2

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

Slice returns a slice containing all the values in this list.

func (*List[T]) Sort added in v0.5.2

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

Sort sorts the list.

func (*List[T]) String added in v0.5.2

func (l *List[T]) String() string

String returns a string representation of the list.

type ListNode added in v0.5.2

type ListNode[T any] struct {
	Value T
	Next  *ListNode[T]
	Prev  *ListNode[T]
}

ListNode represents a single element in a linked list.

func NewListNode added in v0.5.2

func NewListNode[T any](value T) *ListNode[T]

NewListNode creates a new ListNode.

type MaxPQ added in v0.5.2

type MaxPQ[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

MaxPQ is a priority queue that allows getting the maximum value in the queue.

func NewMaxPQ added in v0.5.2

func NewMaxPQ[T cmp.Ordered]() *MaxPQ[T]

NewMaxPQ creates a new MaxPQ.

func (*MaxPQ[T]) DelMax added in v0.5.2

func (m *MaxPQ[T]) DelMax() T

DelMax removes and returns the maximum value in the queue.

func (*MaxPQ[T]) Insert added in v0.5.2

func (m *MaxPQ[T]) Insert(value T)

Insert inserts a new value into the queue.

func (*MaxPQ[T]) IsEmpty added in v0.5.2

func (m *MaxPQ[T]) IsEmpty() bool

IsEmpty returns whether or not there are any items in the queue.

func (*MaxPQ[T]) Max added in v0.5.2

func (m *MaxPQ[T]) Max() T

Max returns the maximum value in the queue, but does not remove it.

func (*MaxPQ[T]) Size added in v0.5.2

func (m *MaxPQ[T]) Size() int

Size returns the number of items in the queue.

func (*MaxPQ[T]) String added in v0.5.2

func (m *MaxPQ[T]) String() string

type MinPQ added in v0.5.2

type MinPQ[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

MinPQ is a priority queue that allows getting the minimum value in the queue.

func NewMinPQ added in v0.5.2

func NewMinPQ[T cmp.Ordered]() *MinPQ[T]

NewMinPQ creates a new MinPQ.

func (*MinPQ[T]) DelMin added in v0.5.2

func (m *MinPQ[T]) DelMin() T

DelMin removes and returns the minimum value in the queue.

func (*MinPQ[T]) Insert added in v0.5.2

func (m *MinPQ[T]) Insert(value T)

Insert inserts a new value into the queue.

func (*MinPQ[T]) IsEmpty added in v0.5.2

func (m *MinPQ[T]) IsEmpty() bool

IsEmpty returns whether or not there are any items in the queue.

func (*MinPQ[T]) Min added in v0.5.2

func (m *MinPQ[T]) Min() T

Min returns the minimum value in the queue, but does not remove it.

func (*MinPQ[T]) Size added in v0.5.2

func (m *MinPQ[T]) Size() int

Size returns the number of items in the queue.

func (*MinPQ[T]) String added in v0.5.2

func (m *MinPQ[T]) String() string

type Queue

type Queue[T any] []T

Queue is a FIFO queue of items.

func NewQueue

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

NewQueue creates a new queue.

func (*Queue[T]) Dequeue

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

Dequeue dequeues the next item on the list.

func (*Queue[T]) Enqueue

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

Enqueue enqueues a single item.

func (*Queue[T]) EnqueueAll

func (q *Queue[T]) EnqueueAll(items []T)

EnqueueAll enqueues a list of items.

func (Queue[T]) HasItems

func (q Queue[T]) HasItems() bool

HasItems returns whether or not this queue has items. Is the opposite of IsEmpty.

func (Queue[T]) IsEmpty

func (q Queue[T]) IsEmpty() bool

IsEmpty returns whether or not this queue is empty

func (Queue[T]) Size

func (q Queue[T]) Size() int

Size returns the size of the queue.

type Set

type Set[T comparable] map[T]bool

Set is a set of unique items.

func NewSet

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

NewSet creates a new set.

func (Set[T]) Add

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

Add adds an item to a set.

func (Set[T]) Delete

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

Delete adds an item to a set.

func (Set[T]) Has

func (s Set[T]) Has(item T) bool

Has checks if a set has an item.

func (Set[T]) HasItems

func (s Set[T]) HasItems() bool

HasItems returns whether or not this set has items. Is the opposite of IsEmpty.

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty returns whether or not this set is empty.

func (Set[T]) Items

func (s Set[T]) Items() []T

Items returns all the items in this set.

func (Set[T]) Size

func (s Set[T]) Size() int

Size returns the size of this set.

type Stack added in v0.5.2

type Stack[T any] []T

Stack is a LIFO stack of items.

func NewStack added in v0.5.2

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

NewStack creates a new stack.

func (Stack[T]) HasItems added in v0.5.2

func (q Stack[T]) HasItems() bool

HasItems returns whether or not this stack has items. Is the opposite of IsEmpty.

func (Stack[T]) IsEmpty added in v0.5.2

func (q Stack[T]) IsEmpty() bool

IsEmpty returns whether or not this stack is empty

func (*Stack[T]) Pop added in v0.5.2

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

Pop pops an item off of the stack.

func (*Stack[T]) Push added in v0.5.2

func (q *Stack[T]) Push(item T)

Push pushes a single item onto the stack.

func (*Stack[T]) PushAll added in v0.5.2

func (q *Stack[T]) PushAll(items []T)

PushAll pushes a list of items onto the stack.

func (Stack[T]) Size added in v0.5.2

func (q Stack[T]) Size() int

Size returns the size of the stack.

Jump to

Keyboard shortcuts

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