Documentation
¶
Overview ¶
Package itree provides an interval tree implementation.
Index ¶
- type Comparable
- type Entry
- type Interval
- type Node
- type Tree
- func (t *Tree[K, V]) Compacted(merge func([]V) V) *Tree[K, V]
- func (t *Tree[K, V]) Entries() []Entry[K, V]
- func (t *Tree[K, V]) Insert(interval Interval[K], value V)
- func (t *Tree[K, V]) Query(key K) []V
- func (t *Tree[K, V]) Size() int
- func (t *Tree[K, V]) Traverse(fn func(interval Interval[K], value V))
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 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.
type Tree ¶ added in v0.5.7
type Tree[K Comparable[K], V any] struct { // contains filtered or unexported fields }
Tree represents an interval tree.
func NewTree ¶ added in v0.5.8
func NewTree[K Comparable[K], V any]() *Tree[K, V]
NewTree creates a new interval tree.
func (*Tree[K, V]) Compacted ¶ added in v0.5.7
Compacted merges nodes with identical intervals using the provided merge function. Returns a new tree where each unique interval appears exactly once.
func (*Tree[K, V]) Entries ¶ added in v0.5.7
Entries returns all entries in the tree as a slice of Entry structs.
func (*Tree[K, V]) Query ¶ added in v0.5.7
func (t *Tree[K, V]) Query(key K) []V
Query returns the values associated with the intervals that contain the given key.