Documentation ¶
Overview ¶
Package dstruct contains data stuctures.
Package dstruct implements various Data STRUCTures.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap implemements a heap data structure by wrapping around the standard library's heap.
func HeapFromSlice ¶
func HeapFromSlice[T any](src []T, best utils.Comparator[T]) Heap[T]
HeapFromSlice creates and initializes a heap from a given slice.
func NewHeap ¶
func NewHeap[T any](best utils.Comparator[T]) Heap[T]
NewHeap creates and initializes a heap.
func (Heap[T]) Data ¶
func (h Heap[T]) Data() *[]T
Data returns a pointer to the internal data Run Heap.Fix if you modify it in any way.
func (Heap[T]) Fix ¶
Fix re-establishes the heap ordering after the element at index i has changed its value. Changing the value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling Remove(h, i) followed by a Push of the new value. The complexity is O(log n) where n = h.Len().
func (*Heap[T]) Pop ¶
func (h *Heap[T]) Pop() T
Pop removes and returns the minimum element (according to Less) from the heap. The complexity is O(log n) where n = h.Len(). Pop is equivalent to Remove(h, 0).
func (*Heap[T]) Push ¶
func (h *Heap[T]) Push(t T)
Push pushes the element x onto the heap. The complexity is O(log n) where n = h.Len().
func (Heap[T]) Remove ¶
Remove removes and returns the element at index i from the heap. The complexity is O(log n) where n = h.Len().
func (Heap[T]) Repair ¶
func (h Heap[T]) Repair()
Repair establishes the heap invariants required by the other routines in this package. Repair is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated. The complexity is O(n) where n = h.Len().
type LruCache ¶
type LruCache[K comparable, V any] struct { // contains filtered or unexported fields }
LruCache is a implements a Least Recently Used cache. It acts as a dictionary of keys and values, with a maximum number of entries. When this maximum is surpassed, the least recently used item is dropped.
func NewLRU ¶
func NewLRU[K comparable, V any](cap int) *LruCache[K, V]
NewLRU creates new lru cache with the specified capacity, measured in number of key-value paires stored.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack data structure. Implements a LIFO queue.
func NewStack ¶
NewStack creates a new stack, with optional arguments for initial size (with default initialization) and initial capacity.
func (*Stack[T]) Data ¶
func (s *Stack[T]) Data() []T
Data reveals the internal storage. The storage is arranged from bottom to top of the stack.
func (*Stack[T]) Invert ¶
func (s *Stack[T]) Invert()
Invert reverses the order of the items within the stack.