Documentation
¶
Overview ¶
Package itree provides an interval tree implementation.
Index ¶
- type Comparable
- type Entry
- type ITree
- func (t *ITree[K, V]) Compact(merge func([]V) V) *ITree[K, V]
- func (t *ITree[K, V]) Entries() []Entry[K, V]
- func (t *ITree[K, V]) Insert(interval Interval[K], value V)
- func (t *ITree[K, V]) Query(key K) []V
- func (t *ITree[K, V]) Size() int
- func (t *ITree[K, V]) Traverse(fn func(interval Interval[K], value V))
- type Interval
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparable ¶
Comparable is an interface for types that can be compared.
type Entry ¶ added in v0.5.4
type Entry[K Comparable[K], V any] struct { Interval Interval[K] Value V }
Entry represents an interval and its associated value in the tree.
type ITree ¶
type ITree[K Comparable[K], V any] struct { // contains filtered or unexported fields }
ITree represents an interval tree.
func NewITree ¶
func NewITree[K Comparable[K], V any]() *ITree[K, V]
NewITree creates a new interval tree.
func (*ITree[K, V]) Compact ¶ added in v0.5.4
Compact merges nodes with identical intervals using the provided merge function. Returns a new tree where each unique interval appears exactly once.
func (*ITree[K, V]) Entries ¶ added in v0.5.4
Entries returns all entries in the tree as a slice of Entry structs.
func (*ITree[K, V]) Query ¶
func (t *ITree[K, V]) Query(key K) []V
Query returns the values associated with the intervals that contain the given key.
type Interval ¶
type Interval[V Comparable[V]] struct { Low V High V }
Interval represents the [Low, High] interval (inclusive).
func NewInterval ¶
func NewInterval[V Comparable[V]](low, high V) Interval[V]
NewInterval creates a new interval with the given low and high values.
func (Interval[V]) Compare ¶ added in v0.5.4
Compare returns a negative value if i < other, zero if i == other, and a positive value if i > other. Intervals are ordered by their low value first, then by their high value.
type Node ¶
type Node[K Comparable[K], V any] struct { // contains filtered or unexported fields }
Node represents a node in the interval tree.