Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interval ¶
type Interval[T any] struct { // contains filtered or unexported fields }
Interval represents two values, the lesser and the greater. Both must be of the same type.
func NewInterval ¶
func NewInterval[T constraints.Ordered](x, y T) Interval[T]
NewInterval returns an Interval that uses the natural ordering of T for comparison.
func NewIntervalFunc ¶ added in v0.3.0
NewIntervalFunc returns an Interval out of x and y so that the Interval can be sorted on construction by the given comparison function.
The comparison function should return values as follows:
cmp(t1, t2) < 0 if t1 < t2 cmp(t1, t2) > 0 if t1 > t2 cmp(t1, t2) == 0 if t1 == t2
For example, to compare time.Time instances,
NewIntervalFunc(t1, t2, func(t1, t2 time.Time) int { return int(t1.Sub(t2)) })
func (Interval[T]) Greater ¶
func (i Interval[T]) Greater() T
Greater returns the greater value from an Interval.
func (Interval[T]) IsEmpty ¶
IsEmpty returns true if the given Interval is empty, false otherwise. An Interval is empty if its lesser equals its greater.
func (Interval[T]) IsNonEmpty ¶
IsNonEmpty returns true if the given Interval is non-empty, false otherwise. An Interval is non-empty if its lesser is not equal to its greater.
type Relation ¶
type Relation int
Relation represents how two Intervals relate to each other.
const ( RelationUnknown Relation = iota /* Interval x is before Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationBefore /* Interval x meets Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationMeets /* Interval x overlaps Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationOverlaps /* Interval x is finished by Interval y. +-----+ | x | +-----+ +---+ | y | +---+ */ RelationFinishedBy /* Interval x contains Interval y. +-------+ | x | +-------+ +---+ | y | +---+ */ RelationContains /* Interval x starts Interval y. +---+ | x | +---+ +-----+ | y | +-----+ */ RelationStarts /* Interval x is equal to Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationEqual /* Interval x is started by Interval y. +-----+ | x | +-----+ +---+ | y | +---+ */ RelationStartedBy /* Interval x is during Interval y. +---+ | x | +---+ +-------+ | y | +-------+ */ RelationDuring /* Interval x finishes Interval y. +---+ | x | +---+ +-----+ | y | +-----+ */ RelationFinishes /* Interval x is overlapped by Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationOverlappedBy /* Interval x is met by Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationMetBy /* Interval x is after Interval y. +---+ | x | +---+ +---+ | y | +---+ */ RelationAfter )