itree

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package itree provides an interval tree implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparable

type Comparable[V any] interface {
	Compare(other V) int
}

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

func (i Interval[V]) Compare(other Interval[V]) int

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.

func (Interval[V]) Contains

func (i Interval[V]) Contains(value V) bool

Contains returns whether the interval contains the given value.

func (Interval[V]) Equal added in v0.5.4

func (i Interval[V]) Equal(other Interval[V]) bool

Equal returns whether the interval is equal to another interval.

type Node

type Node[K Comparable[K], V any] struct {
	// contains filtered or unexported fields
}

Node represents a node in the interval tree.

func NewNode

func NewNode[K Comparable[K], V any](interval Interval[K], value V) *Node[K, V]

NewNode creates a new node with the given interval.

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

func (t *Tree[K, V]) Compacted(merge func([]V) V) *Tree[K, V]

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

func (t *Tree[K, V]) Entries() []Entry[K, V]

Entries returns all entries in the tree as a slice of Entry structs.

func (*Tree[K, V]) Insert added in v0.5.7

func (t *Tree[K, V]) Insert(interval Interval[K], value V)

Insert adds an interval to the interval tree.

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.

func (*Tree[K, V]) Size added in v0.5.7

func (t *Tree[K, V]) Size() int

Size returns the number of nodes in the tree.

func (*Tree[K, V]) Traverse added in v0.5.7

func (t *Tree[K, V]) Traverse(fn func(interval Interval[K], value V))

Traverse walks the tree in pre-order (root, left, right) and calls the provided function for each node with its interval and value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL