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 ¶ added in v0.5.2
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
List is a general purpose List class based on slices.
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
Contains returns whether or not the list contains the specified value.
func (*List[T]) Filter ¶ added in v0.5.2
Filter returns a new list with the elements that pass the filter function.
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
IndexOf returns the index of the speified value if it is in the list, or -1 if not.
func (*List[T]) Map ¶ added in v0.5.2
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
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]) Shuffle ¶ added in v0.5.2
func (l *List[T]) Shuffle()
Shuffle randomly shuffles the list.
type ListNode ¶ added in v0.5.2
ListNode represents a single element in a linked list.
func NewListNode ¶ added in v0.5.2
NewListNode creates a new ListNode.
type MaxPQ ¶ added in v0.5.2
MaxPQ is a priority queue that allows getting the maximum value in the queue.
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
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.
type MinPQ ¶ added in v0.5.2
MinPQ is a priority queue that allows getting the minimum value in the queue.
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
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.
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 ¶ added in v0.5.2
type Stack[T any] []T
Stack is a LIFO stack of items.
func (Stack[T]) HasItems ¶ added in v0.5.2
HasItems returns whether or not this stack has items. Is the opposite of IsEmpty.
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.