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 ¶
- func MakeGrid[T any](rows, cols int) [][]T
- type LinkedList
- type List
- func (l *List[T]) Append(value T)
- func (l *List[T]) Clear()
- func (l *List[T]) Contains(value T) bool
- func (l *List[T]) Filter(filterFunc func(T) bool) *List[T]
- func (l *List[T]) Get(index int) (T, error)
- func (l *List[T]) GetFirst() T
- func (l *List[T]) GetLast() T
- func (l *List[T]) GetRandom() T
- func (l *List[T]) IndexOf(value T) int
- func (l *List[T]) Insert(index int, value T) error
- func (l *List[T]) Length() int
- func (l *List[T]) Map(mapFunc func(T) T) *List[T]
- func (l *List[T]) Prepend(value T)
- func (l *List[T]) Remove(index int) (T, error)
- func (l *List[T]) RemoveFirst() T
- func (l *List[T]) RemoveLast() T
- func (l *List[T]) Reverse()
- func (l *List[T]) Shuffle()
- func (l *List[T]) Slice() []T
- func (l *List[T]) Sort()
- func (l *List[T]) String() string
- type ListNode
- type MaxPQ
- type MinPQ
- type Queue
- type Set
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LinkedList ¶
LinkedList is a doubly linked list.
func NewLinkedList ¶
func NewLinkedList[T any]() *LinkedList[T]
NewLinkedList creates a new linked list.
func (*LinkedList[T]) Add ¶
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 ¶
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 ¶
func (l *LinkedList[T]) GetValueAt(index int) (T, error)
GetValueAt returns the value in the node at the specified index.
func (*LinkedList[T]) Insert ¶
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 ¶
List is a general purpose List class based on slices.
func (*List[T]) Append ¶
func (l *List[T]) Append(value T)
Append appends a value to the end of the list.
func (*List[T]) GetFirst ¶
func (l *List[T]) GetFirst() T
GetFirst returns the first element in the list.
func (*List[T]) GetLast ¶
func (l *List[T]) GetLast() T
GetLast returns the last element in the list.
func (*List[T]) GetRandom ¶
func (l *List[T]) GetRandom() T
GetRandom returns a random element from the list.
func (*List[T]) IndexOf ¶
IndexOf returns the index of the speified value if it is in the list, or -1 if not.
func (*List[T]) Map ¶
Map returns a new list with elements obtained by applying the map function to each element.
func (*List[T]) Prepend ¶
func (l *List[T]) Prepend(value T)
Prepend prepends a value to the start of the list.
func (*List[T]) RemoveFirst ¶
func (l *List[T]) RemoveFirst() T
RemoveFirst removes and returns the first value on the list.
func (*List[T]) RemoveLast ¶
func (l *List[T]) RemoveLast() T
RemoveLast removes and returns the last value on the list.
type ListNode ¶
ListNode represents a single element in a linked list.
func NewListNode ¶
NewListNode creates a new ListNode.
type MaxPQ ¶
MaxPQ is a priority queue that allows getting the maximum value in the queue.
func (*MaxPQ[T]) DelMax ¶
func (m *MaxPQ[T]) DelMax() T
DelMax removes and returns the maximum value in the queue.
func (*MaxPQ[T]) Insert ¶
func (m *MaxPQ[T]) Insert(value T)
Insert inserts a new value into the queue.
func (*MaxPQ[T]) Max ¶
func (m *MaxPQ[T]) Max() T
Max returns the maximum value in the queue, but does not remove it.
type MinPQ ¶
MinPQ is a priority queue that allows getting the minimum value in the queue.
func (*MinPQ[T]) DelMin ¶
func (m *MinPQ[T]) DelMin() T
DelMin removes and returns the minimum value in the queue.
func (*MinPQ[T]) Insert ¶
func (m *MinPQ[T]) Insert(value T)
Insert inserts a new value into the queue.
func (*MinPQ[T]) Min ¶
func (m *MinPQ[T]) Min() T
Min returns the minimum value in the queue, but does not remove it.
type Queue ¶
type Queue[T any] []T
Queue is a FIFO queue of items.
func (*Queue[T]) Dequeue ¶
func (q *Queue[T]) Dequeue() T
Dequeue dequeues the next item on the list.
func (*Queue[T]) EnqueueAll ¶
func (q *Queue[T]) EnqueueAll(items []T)
EnqueueAll enqueues a list of items.
func (Queue[T]) HasItems ¶
HasItems returns whether or not this queue has items. Is the opposite of IsEmpty.
type Set ¶
type Set[T comparable] map[T]bool
Set is a set of unique items.
func (Set[T]) HasItems ¶
HasItems returns whether or not this set has items. Is the opposite of IsEmpty.
type Stack ¶
type Stack[T any] []T
Stack is a LIFO stack of items.
func (Stack[T]) HasItems ¶
HasItems returns whether or not this stack has items. Is the opposite of IsEmpty.