Documentation
¶
Index ¶
- func GrowAdd[K any](slice []K, idx int, val K) []K
- func SafeGet[K any](slice []K, idx int) (K, bool)
- type ArrayConstraint
- type ArrayMap
- type IndexMap
- type Item
- type MiniSlice
- func (s *MiniSlice[A, T]) All() iter.Seq2[int, T]
- func (s *MiniSlice[A, T]) Append(val T)
- func (s *MiniSlice[A, T]) Clear()
- func (s *MiniSlice[A, T]) Delete(idx int)
- func (s *MiniSlice[A, T]) Find(searchVal T) int
- func (s *MiniSlice[A, T]) Get(idx int) T
- func (s *MiniSlice[A, T]) Len() int
- func (s *MiniSlice[A, T]) Set(idx int, val T)
- func (s *MiniSlice[A, T]) SliceLast()
- type PriorityMap
- type PriorityQueue
- type Queue
- type RingBuffer
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArrayConstraint ¶
type ArrayConstraint[T any] interface { [1]T | [2]T | [3]T | [4]T | [5]T | [6]T | [7]T | [8]T | [9]T | [10]T | [11]T | [12]T | [13]T | [14]T | [15]T | [16]T }
type ArrayMap ¶
type ArrayMap[K comparable, V any] struct { // contains filtered or unexported fields }
Acts like a map, but is backed by an array. Can provide better iteration speed at the cost of slower lookups
func NewArrayMap ¶
func NewArrayMap[K comparable, V any]() ArrayMap[K, V]
type IndexMap ¶
type IndexMap[K constraints.Integer, V any] struct { // contains filtered or unexported fields }
Acts like a map, but backed by an integer indexed slice instead of a map This is mostly for use cases where you have a small list of increasing numbers that you want to store in an array, but you dont want to worry about ensuring the bounds are always correct Note: If you put a huge key in here, the slice will allocate a ton of space.
func NewIndexMap ¶
func NewIndexMap[K constraints.Integer, V any]() IndexMap[K, V]
type Item ¶
type Item[T any] struct { Priority int // The priority of the item in the queue. Value T // The value of the item; arbitrary. // contains filtered or unexported fields }
An Item is something we manage in a priority queue.
type MiniSlice ¶
type MiniSlice[A ArrayConstraint[T], T comparable] struct { Array A Slice []T // contains filtered or unexported fields }
A mini slice that allocates the first N elements into an array and then heap allocates the remaining into a traditional slice
func (*MiniSlice[A, T]) Clear ¶
func (s *MiniSlice[A, T]) Clear()
Clears the array, so the next append will start at index 0
func (*MiniSlice[A, T]) Delete ¶
Removes the element at the supplied index, swapping the element that was at the last index to the supplied index
type PriorityMap ¶
type PriorityMap[K comparable, T any] struct { // contains filtered or unexported fields }
Note: Higher value is pulled out first
func NewPriorityMap ¶
func NewPriorityMap[K comparable, T any]() *PriorityMap[K, T]
func (*PriorityMap[K, T]) Clear ¶
func (q *PriorityMap[K, T]) Clear()
Removes all items from the queue
func (*PriorityMap[K, T]) Get ¶
func (q *PriorityMap[K, T]) Get(key K) (T, int, bool)
Gets the item, doesnt remove it
func (*PriorityMap[K, T]) Len ¶
func (q *PriorityMap[K, T]) Len() int
func (*PriorityMap[K, T]) Pop ¶
func (q *PriorityMap[K, T]) Pop() (K, T, int, bool)
Pops the highest priority item
func (*PriorityMap[K, T]) Put ¶
func (q *PriorityMap[K, T]) Put(key K, val T, priority int)
Adds the item, overwriting the old one if needed
func (*PriorityMap[K, T]) Remove ¶
func (q *PriorityMap[K, T]) Remove(key K) (T, bool)
Gets the value and removes it from the queue
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
func NewPriorityQueue ¶
func NewPriorityQueue[T any]() *PriorityQueue[T]
Note: Higher value is pulled out first
func (*PriorityQueue[T]) Clear ¶
func (pq *PriorityQueue[T]) Clear()
func (*PriorityQueue[T]) Len ¶
func (pq *PriorityQueue[T]) Len() int
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() *Item[T]
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(item *Item[T])
func (*PriorityQueue[T]) Remove ¶
func (pq *PriorityQueue[T]) Remove(item *Item[T])
func (*PriorityQueue[T]) Update ¶
func (pq *PriorityQueue[T]) Update(item *Item[T])
type Queue ¶
type Queue[T any] struct { Buffer []T ReadIdx int WriteIdx int // contains filtered or unexported fields }
func NewFixedQueue ¶
func (*Queue[T]) GrowDouble ¶
func (q *Queue[T]) GrowDouble()
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
func NewRingBuffer ¶
func NewRingBuffer[T any](length int) *RingBuffer[T]
func (*RingBuffer[T]) Add ¶
func (b *RingBuffer[T]) Add(t T)
func (*RingBuffer[T]) Buffer ¶
func (b *RingBuffer[T]) Buffer() []T
TODO - Maybe convert this to an iterator
func (*RingBuffer[T]) Cap ¶
func (b *RingBuffer[T]) Cap() int
func (*RingBuffer[T]) Len ¶
func (b *RingBuffer[T]) Len() int
func (*RingBuffer[T]) Remove ¶
func (b *RingBuffer[T]) Remove() (T, bool)
Returns the last element and false if the buffer is emptied
type Stack ¶
type Stack[T any] struct { Buffer []T }
func (*Stack[T]) Remove ¶
func (s *Stack[T]) Peek() (T, bool) { if q.ReadIdx == q.WriteIdx { var ret T return ret, false } return q.Buffer[q.ReadIdx], true }
func (s *Stack[T]) PeekLast() (T, bool) { if q.ReadIdx == q.WriteIdx { var ret T return ret, false } idx := (q.WriteIdx + len(q.Buffer) - 1) % len(q.Buffer) return q.Buffer[idx], true }