interval

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint = constraints.Integer

Endpoint is a type that may be used as an interval endpoint.

type Entry

type Entry[K Endpoint, V any] struct {
	Start, End K // The interval range, inclusive.
	Value      V
}

Entry is an entry in a Intersect. This means that it is the intersection of all intervals which contain a particular point.

func (Entry[K, V]) Contains

func (e Entry[K, V]) Contains(point K) bool

Contains returns whether an entry contains a given point.

type Intersect

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

Intersection is an interval intersection map: a collection of intervals, such that given a point in K, one can query for the intersection of all intervals in the collection which contain it, along with the values associated with each of those intervals.

A zero value is ready to use.

func (*Intersect[K, V]) Contiguous

func (m *Intersect[K, V]) Contiguous(values bool) iter.Seq[Entry[K, []V]]

Ranges returns an iterator over the contiguous ranges in this map.

If values is true, the yielded entries will include all of the values that fall within those contiguous ranges.

func (*Intersect[K, V]) Entries

func (m *Intersect[K, V]) Entries() iter.Seq[Entry[K, []V]]

Entries returns an iterator over the entries in this map.

There exists one entry per maximal subset of the map with non-empty intersection. Entries are yielded in order, and are pairwise disjoint.

func (*Intersect[K, V]) Format

func (m *Intersect[K, V]) Format(s fmt.State, v rune)

Format implements fmt.Formatter.

func (*Intersect[K, V]) Get

func (m *Intersect[K, V]) Get(point K) Entry[K, []V]

Get returns the intersection of all intervals which contain point.

If no such interval exists, the Entry.Values will be nil.

func (*Intersect[K, V]) Insert

func (m *Intersect[K, V]) Insert(start, end K, value V) (disjoint bool)

Insert inserts a new interval into this map, with the given associated value. Both endpoints are inclusive.

Returns true if the interval was disjoint from all others in the set.

type Nesting

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

Nesting is a collection of intervals (and associated values) arranged in such a way that splits the collection into strictly nesting sets: a strictly nesting set of intervals is one such that no intervals in it overlap, except when one set is a strict subset of another.

Inserting n intervals into this set is worst-case O(n^2 log n). Insertion order matters: larger intervals should be inserted first. To prevent nesting, insert *shorter* intervals first, instead.

func (*Nesting[K, V]) Clear

func (n *Nesting[K, V]) Clear()

Clear resets this collection without discarding allocated memory (where possible).

func (*Nesting[K, V]) Insert

func (n *Nesting[K, V]) Insert(start, end K, value V)

Insert adds a new interval to the collection.

func (*Nesting[K, V]) Sets

func (n *Nesting[K, V]) Sets() iter.Seq[iter.Seq[Entry[K, V]]]

Entries returns an iterator over the nesting sets in this collection.

Within each set, the order they are yielded in is unspecified.

Jump to

Keyboard shortcuts

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