Documentation ¶
Overview ¶
Package interval implements intervals of integers.
Interval types are named by whether or not either of their ends is open/closed. For example, the type CO is closed on the left and open on the right, so it describes the interval type [a,b).
Only signed integers are supported, to make arithmetic simpler. In general, the package will note behave well in the presence of overflows.
The package also includes a Set type, which can efficiently store sparse integer intervals. It is parameterized, so can be used with any of the interval types in this package.
The easiest way to use it is to define a local alias for the interval kind appropriate for the problem, e.g.
type Interval = interval.CO[int]
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
func Convert[J, I Interval[T], T constraints.Signed](i I) J
Convert between interval kinds.
Types ¶
type CC ¶
type CC[T constraints.Signed] struct { Min T Max T }
CC is a closed interval of T, that is [Min, Max]. Well-formed intervals have Min≤Max+1, the empty interval is {0,-1}.
func MakeCC ¶
func MakeCC[T constraints.Signed](a, b T) CC[T]
func (CC[T]) Intersects ¶
Intersects returns whether i and j intersect.
type CO ¶
type CO[T constraints.Signed] struct { Min T Max T }
CO is a right half-open interval of T, that is [Min, Max). Well-formed intervals have Min≤Max, the empty interval is {0,0}.
func MakeCO ¶
func MakeCO[T constraints.Signed](a, b T) CO[T]
func (CO[T]) Intersects ¶
Intersects returns whether i and j intersect.
type Interval ¶
type Interval[T constraints.Signed] interface { CO[T] | OC[T] | OO[T] | CC[T] // contains filtered or unexported methods }
Interval is a constraint for any of the interval types in this package
type OC ¶
type OC[T constraints.Signed] struct { Min T Max T }
OC is a left half-open interval of T, that is (Min, Max]. Well-formed intervals have Min≤Max, the empty interval is {0,0}.
func MakeOC ¶
func MakeOC[T constraints.Signed](a, b T) OC[T]
func (OC[T]) Intersects ¶
Intersects returns whether i and j intersect.
type OO ¶
type OO[T constraints.Signed] struct { Min T Max T }
OO is an open interval of T, that is (Min, Max). Well-formed intervals have Min≤Max+1, the empty interval is {0,1}.
func MakeOO ¶
func MakeOO[T constraints.Signed](a, b T) OO[T]
func (OO[T]) Intersects ¶
Intersects returns whether i and j intersect.
type Set ¶
type Set[I Interval[T], T constraints.Signed] struct { // contains filtered or unexported fields }
Set is a set of T, built out of intervals. The zero value is an empty set.
func (*Set[I, T]) Continuous ¶
Continuous returns whether s is representable by a single interval. The empty set is considered continuous.