Documentation ¶
Overview ¶
Package intervals provides a fast insertion-sort based solution to the merge overlapping intervals problem.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interval ¶
type Interval[T constraints.Ordered] struct { Start T End T }
Interval represents a range of the form `[Start, End)`, which contains all x in Start <= x < End. x can be any type that is ordered, including the various sizes of int, uint, float types, uintptr and string.
If T is a float, neither Start nor End can be NaN, since NaN is not ordered.
type Intervals ¶
type Intervals[T constraints.Ordered] []Interval[T]
Intervals is an ascending ordered representation of a slice of non-overlapping Interval.
func (Intervals[T]) Insert ¶
Insert adds a given Interval to Intervals, possibly inserting in the correct order between two intervals, extending an existing interval, or compacting existing intervals as necessary. ivs must be correctly ordered. An empty v will result in a noop, and an invalid v may panic.
Insert is not safe for concurrent access; add a lock if necessary.
func (Intervals[T]) Search ¶
Search will return the Interval in the given Intervals containing the value of off and true if found. Otherwise, it will return an empty Interval and false. ivs must be correctly ordered.
Search is not safe for concurrent access with Interval; add a read lock if necessary.