Documentation
¶
Index ¶
- func RegisterStdPreload(v *vm.VM)
- type BTree
- type BTreeNode
- func (node *BTreeNode[T]) Append(key T, child *BTreeNode[T])
- func (node *BTreeNode[T]) Concat(other *BTreeNode[T], idx int)
- func (node *BTreeNode[T]) Delete(tree *BTree[T], key T)
- func (node *BTreeNode[T]) DeleteIthKey(i int)
- func (node *BTreeNode[T]) InsertKeyChild(key T, child *BTreeNode[T])
- func (node *BTreeNode[T]) InsertNonFull(tree *BTree[T], key T)
- func (node *BTreeNode[T]) IsFull(maxKeys int) bool
- func (node *BTreeNode[T]) Max() T
- func (node *BTreeNode[T]) Merge(idx int)
- func (node *BTreeNode[T]) Min() T
- func (node *BTreeNode[T]) Search(key T) bool
- func (parent *BTreeNode[T]) Split(idx int, maxKeys int)
- func (node *BTreeNode[T]) Verify(tree *BTree[T])
- type Deque
- type HashMap
- type Heap
- type LinkedList
- func (l *LinkedList) Back() (any, bool)
- func (l *LinkedList) Clear()
- func (l *LinkedList) Empty() bool
- func (l *LinkedList) Front() (any, bool)
- func (l *LinkedList) PopBack() (any, bool)
- func (l *LinkedList) PopFront() (any, bool)
- func (l *LinkedList) PushBack(v any)
- func (l *LinkedList) PushFront(v any)
- func (l *LinkedList) Size() int
- func (l *LinkedList) ToArray() []any
- type Node
- type Queue
- type Set
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterStdPreload ¶
RegisterStdPreload installs the `std` module under package.preload. `require("std")` returns a table of constructors for the data structures defined in this package — stack, queue, deque, set, linked list, heap, hashmap, trie, btree. Each constructor returns a fresh object whose methods are bound to a private Go instance via colon-call.
Types ¶
type BTree ¶
type BTree[T constraints.Ordered] struct { // contains filtered or unexported fields }
type BTreeNode ¶
type BTreeNode[T constraints.Ordered] struct { // contains filtered or unexported fields }
func NewBTreeNode ¶
func NewBTreeNode[T constraints.Ordered](maxKeys int, isLeaf bool) *BTreeNode[T]
func (*BTreeNode[T]) Concat ¶
Add all of other's keys starting from idx and children starting from idx + 1
func (*BTreeNode[T]) DeleteIthKey ¶
func (*BTreeNode[T]) InsertKeyChild ¶
func (*BTreeNode[T]) InsertNonFull ¶
type Deque ¶
type Deque struct {
// contains filtered or unexported fields
}
Deque is a double-ended queue over arbitrary Lua values. Backed by a ring buffer so PushFront/PushBack/PopFront/PopBack are all O(1) amortized. The buffer doubles when full and is never shrunk — real-world deques rarely benefit from shrinkage and the bookkeeping makes the iteration paths uglier.
type HashMap ¶
type HashMap struct {
// contains filtered or unexported fields
}
func DefaultHashMap ¶
func DefaultHashMap() *HashMap
func NewHashMap ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
func New ¶
func New[T constraints.Ordered]() *Heap[T]
func NewAny ¶
NewAny gives a new heap object. element can be anything, but must provide less function.
func (*Heap[T]) Pop ¶
func (h *Heap[T]) Pop()
Pop removes the minimum element (according to Less) from the heap. The complexity is O(log n) where n = h.Len().
type LinkedList ¶
type LinkedList struct {
// contains filtered or unexported fields
}
LinkedList is a doubly-linked list of Lua values. All end-operations are O(1); ToArray is O(n). For random-access use a Deque or a plain Lua table — this type exists for cases where you actually want stable interior references / iteration.
func (*LinkedList) Back ¶
func (l *LinkedList) Back() (any, bool)
Back returns the tail element without removing it.
func (*LinkedList) Empty ¶
func (l *LinkedList) Empty() bool
Empty reports whether the list has no elements.
func (*LinkedList) Front ¶
func (l *LinkedList) Front() (any, bool)
Front returns the head element without removing it.
func (*LinkedList) PopBack ¶
func (l *LinkedList) PopBack() (any, bool)
PopBack removes and returns the tail element.
func (*LinkedList) PopFront ¶
func (l *LinkedList) PopFront() (any, bool)
PopFront removes and returns the head element.
func (*LinkedList) PushFront ¶
func (l *LinkedList) PushFront(v any)
PushFront prepends v to the head.
func (*LinkedList) ToArray ¶
func (l *LinkedList) ToArray() []any
ToArray walks the list head→tail and returns a snapshot slice.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents each node in Trie.
func (*Node) Compact ¶
Compact will remove unecessay nodes, reducing the capacity, returning true if node n itself should be removed.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is a FIFO collection over arbitrary Lua values. Backed by a slice with a head index — Push is amortized O(1) and Pop is O(1). When the head wanders past half the underlying buffer the tail half is shifted down so we don't leak unbounded capacity.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is an unordered collection of unique Lua values. Membership uses Go's native map, which means key equality follows Go's rules: strings, ints, floats, bools and nil all interoperate naturally, and reference values (tables, closures) compare by identity. Sets do NOT honour Lua's float-vs-int equality (1 == 1.0 in Lua but distinct in a Go map) — callers should pre-normalise if they care.
func (*Set) Add ¶
Add inserts v. Returns true if v was newly added, false if already present — handy for "if added then ..." flows.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a LIFO collection over arbitrary Lua values. Backed by a plain slice — Push/Pop/Peek are amortized O(1).
func (*Stack) Clear ¶
func (s *Stack) Clear()
Clear drops every element. Capacity is preserved so subsequent pushes don't immediately re-allocate.