Documentation
¶
Index ¶
- type Node
- func (t *Node[T]) Index() int
- func (t *Node[T]) JumpLeft(n int) *Node[T]
- func (t *Node[T]) JumpRight(n int) *Node[T]
- func (t *Node[T]) Leftmost() *Node[T]
- func (t *Node[T]) Next() *Node[T]
- func (t *Node[T]) Prev() *Node[T]
- func (t *Node[T]) Rightmost() *Node[T]
- func (t *Node[T]) Valid() bool
- func (t *Node[T]) Value() (result T)
- type Treap
- func Merge[T any](left *Treap[T], right *Treap[T]) *Treap[T]
- func NewAutoOrderTreap[T cmp.Ordered](values ...T) *Treap[T]
- func NewAutoOrderTreapWithRand[T cmp.Ordered](randFn func() int, values ...T) *Treap[T]
- func NewTreap[T any](lessFn func(a T, b T) bool, values ...T) *Treap[T]
- func NewTreapWithRand[T any](lessFn func(a T, b T) bool, randFn func() int, values ...T) *Treap[T]
- func (t *Treap[T]) At(index int) *Node[T]
- func (t *Treap[T]) Clear()
- func (t *Treap[T]) Count(value T) int
- func (t *Treap[T]) CountRange(startValue T, inclusiveStart bool, endValue T, inclusiveEnd bool) int
- func (t *Treap[T]) Cut(n int) (left *Treap[T], right *Treap[T])
- func (t *Treap[T]) Elements() iter.Seq[*Node[T]]
- func (t *Treap[T]) ElementsBackwards() iter.Seq[*Node[T]]
- func (t *Treap[T]) Empty() bool
- func (t *Treap[T]) EraseAll(value T) (erasedCount int)
- func (t *Treap[T]) EraseAt(index int, count int) (erasedCount int)
- func (t *Treap[T]) EraseLeftmost(value T, n int) (erasedCount int)
- func (t *Treap[T]) EraseRange(startValue T, inclusiveStart bool, endValue T, inclusiveEnd bool) (erasedCount int)
- func (t *Treap[T]) EraseRightmost(value T, n int) (erasedCount int)
- func (t *Treap[T]) FindLowerBound(value T) (node *Node[T], index int)
- func (t *Treap[T]) FindUpperBound(value T) (node *Node[T], index int)
- func (t *Treap[T]) InsertLeft(value T) (index int)
- func (t *Treap[T]) InsertRight(value T) (index int)
- func (t *Treap[T]) Leftmost() *Node[T]
- func (t *Treap[T]) PopLeftmost() (value T, ok bool)
- func (t *Treap[T]) PopRightmost() (value T, ok bool)
- func (t *Treap[T]) Rightmost() *Node[T]
- func (t *Treap[T]) Root() *Node[T]
- func (t *Treap[T]) Size() int
- func (t *Treap[T]) SplitAfter(value T) (left *Treap[T], right *Treap[T])
- func (t *Treap[T]) SplitBefore(value T) (left *Treap[T], right *Treap[T])
- func (t *Treap[T]) Values() iter.Seq[T]
- func (t *Treap[T]) ValuesBackwards() iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node[T any] struct { // contains filtered or unexported fields }
func (*Node[T]) Index ¶
Index computes the zero-based position of t within an in-order traversal. Returns -1 if t is nil.
func (*Node[T]) JumpLeft ¶
JumpLeft will return element that is n positions to the left, or -n positions to the right if n is negative. If there's no such element, nil will be returned.
func (*Node[T]) JumpRight ¶
JumpRight will return element that is n positions to the right, or -n positions to the left n is negative. If there's no such element, nil will be returned.
type Treap ¶
type Treap[T any] struct { // contains filtered or unexported fields }
func Merge ¶
Merge joins two treaps that share the same ordering function. The treaps must use equivalent lessFn comparators, otherwise the resulting treap will have undefined behavior. Both treaps are consumed.
func NewAutoOrderTreap ¶
NewAutoOrderTreap builds an ordered treap using the natural ordering for type T.
func NewAutoOrderTreapWithRand ¶
NewAutoOrderTreapWithRand builds an ordered treap using the natural ordering for type T and a custom random function.
func NewTreap ¶
NewTreap constructs a treap using lessFn for ordering and optionally inserts values.
func NewTreapWithRand ¶
NewTreapWithRand constructs a treap using lessFn for ordering, randFn for tree balancing, and optionally inserts values.
func (*Treap[T]) At ¶
At returns the node located at the provided index or nil if it is out of range.
func (*Treap[T]) CountRange ¶
CountRange returns how many values fall between startValue and endValue. Each bound contributes to the count only when its inclusive flag is true, so exclusive flags treat that bound as open. Panics if endValue < startValue, or if startValue == endValue with non-inclusive bounds.
func (*Treap[T]) Cut ¶
Cut splits the treap into the first n elements and the remainder. If n is negative, cuts from the end (e.g., Cut(-2) returns all but the last 2 elements as left). If the computed position is negative, everything goes to right.
func (*Treap[T]) ElementsBackwards ¶
Iterate over treap elements in reverse order (rightmost to leftmost)
func (*Treap[T]) EraseAll ¶
EraseAll removes every occurrence of value and reports how many were deleted.
func (*Treap[T]) EraseAt ¶
EraseAt removes up to count elements starting at index and returns how many were erased. Supports negative indexing where -1 refers to the last element. Panics if count is negative.
func (*Treap[T]) EraseLeftmost ¶
EraseLeftmost removes up to n matching values starting from the leftmost occurrence.
func (*Treap[T]) EraseRange ¶
func (t *Treap[T]) EraseRange(startValue T, inclusiveStart bool, endValue T, inclusiveEnd bool) (erasedCount int)
EraseRange removes values between startValue and endValue. Each bound is removed only when its corresponding inclusive flag is true, and the method reports how many values were erased. Panics if endValue < startValue, or if startValue == endValue with non-inclusive bounds.
func (*Treap[T]) EraseRightmost ¶
EraseRightmost removes up to n matching values starting from the rightmost occurrence.
func (*Treap[T]) FindLowerBound ¶
FindLowerBound returns the first node not less than value along with its index.
func (*Treap[T]) FindUpperBound ¶
FindUpperBound returns the last node not greater than value along with its index.
func (*Treap[T]) InsertLeft ¶
InsertLeft inserts value before any equal elements and returns its index.
func (*Treap[T]) InsertRight ¶
InsertRight inserts value after any equal elements and returns its index.
func (*Treap[T]) PopLeftmost ¶
PopLeftmost removes and returns the minimum value, reporting success.
func (*Treap[T]) PopRightmost ¶
PopRightmost removes and returns the maximum value, reporting success.
func (*Treap[T]) Root ¶
Root returns the internal root node of the treap. Returns nil if the tree is empty. Note: The root node is arbitrary - prefer At(0) for first element, Leftmost() for minimum, or Rightmost() for maximum.
func (*Treap[T]) SplitAfter ¶
SplitAfter splits the treap after the last value less than or equal to value.
func (*Treap[T]) SplitBefore ¶
SplitBefore splits the treap at the first value not less than value.
func (*Treap[T]) ValuesBackwards ¶
Iterate over treap values in reverse order (rightmost to leftmost)