interval

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package interval provides an augmented interval tree for efficient range-overlap queries. It supports Insert, Delete, QueryOverlap, and QueryPoint operations with O(log N) insert/delete and O(log N + k) query time, where k is the number of overlapping intervals.

The tree is backed by a red-black tree where each node stores the maximum right endpoint (maxHigh) in its subtree, enabling subtree pruning during overlap queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Integer constrains interval endpoints to integer types.

type Interval

type Interval[K Integer, V comparable] struct {
	Low   K
	High  K
	Value V
}

Interval represents a closed range [Low, High] with an associated Value.

type Tree

type Tree[K Integer, V comparable] struct {
	// contains filtered or unexported fields
}

Tree is an augmented interval tree supporting overlap queries.

func New

func New[K Integer, V comparable]() *Tree[K, V]

New creates an empty interval tree.

func (*Tree[K, V]) Clear

func (t *Tree[K, V]) Clear()

Clear removes all intervals from the tree.

func (*Tree[K, V]) Delete

func (t *Tree[K, V]) Delete(low, high K, value V) bool

Delete removes one interval matching [low, high, value] from the tree. Returns true if the interval was found and removed, false otherwise.

func (*Tree[K, V]) Insert

func (t *Tree[K, V]) Insert(low, high K, value V)

Insert adds an interval [low, high] with the given value to the tree.

func (*Tree[K, V]) Len

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

Len returns the number of intervals in the tree.

func (*Tree[K, V]) QueryOverlap

func (t *Tree[K, V]) QueryOverlap(low, high K) []Interval[K, V]

QueryOverlap returns all intervals that overlap with the query range [low, high]. An interval [a, b] overlaps [low, high] when a <= high AND b >= low.

func (*Tree[K, V]) QueryPoint

func (t *Tree[K, V]) QueryPoint(point K) []Interval[K, V]

QueryPoint returns all intervals containing the given point. Equivalent to QueryOverlap(point, point).

Jump to

Keyboard shortcuts

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