Documentation ¶
Overview ¶
Package intervals is a library for manipulating sets of intervals.
Index ¶
- type Elem
- type Enum
- type Interval
- type Set
- func Add[E Elem[E]](x Set[E], s ...Interval[E]) Set[E]
- func Collect[E Elem[E]](s ...Interval[E]) Set[E]
- func CollectInto[E Elem[E]](x Set[E], s ...Interval[E]) Set[E]
- func Delete[E Elem[E]](x Set[E], s ...Interval[E]) Set[E]
- func Difference[E Elem[E]](z, x, y Set[E]) Set[E]
- func Intersection[E Elem[E]](z, x, y Set[E]) Set[E]
- func Reduce[E Elem[E]](op func(z, x, y Set[E]) Set[E], sets ...Set[E]) Set[E]
- func SymmetricDifference[E Elem[E]](z, x, y Set[E]) Set[E]
- func Union[E Elem[E]](z, x, y Set[E]) Set[E]
- func (x Set[E]) Contains(r Interval[E]) bool
- func (x Set[E]) ContainsUnit(v E) bool
- func (x Set[E]) Difference(y Set[E]) Set[E]
- func (x Set[E]) Equal(y Set[E]) bool
- func (x Set[E]) Extent() Interval[E]
- func (x Set[E]) Intersection(y Set[E]) Set[E]
- func (x Set[E]) IsSubsetOf(y Set[E]) bool
- func (x Set[E]) Overlaps(y Set[E]) bool
- func (x Set[E]) SymmetricDifference(y Set[E]) Set[E]
- func (x Set[E]) Union(y Set[E]) Set[E]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Enum ¶ added in v0.2.0
An Enum is a computably enumerable Elem. There exists a computable enumeration that lists elements, in a valid Interval of Enum, in an increasing ordering determined by the Compare method.
type Interval ¶
type Interval[E Elem[E]] struct { Low E // inclusive High E // exclusive }
An Interval is a half-open continuous range of elements.
func Range ¶ added in v0.2.0
Range returns an Interval of range [lo, hi). If lo.Compare(hi) >= 0, Range returns an invalid Interval. Note that calling Set method on an invalid Interval panics.
func Unit ¶ added in v0.4.0
Unit returns an Interval that only contains a single element v. If there is no element next to v, Unit returns an invalid Interval. Note that calling Set method on an invalid Interval panics.
type Set ¶
A Set is a slice of separate intervals sorted in ascending order. The zero value for a Set, i.e. a nil Set, is an empty set.
Since Intervals are half-open, the maximum value of E cannot be added into a Set.
func Collect ¶ added in v0.2.0
Collect returns the set of elements that are in any of s.
Collect performs better if s are sorted in ascending order by the Low field.
func CollectInto ¶ added in v0.3.0
CollectInto returns the set of elements that are in any of s, overwriting x. x and s can be the same slice. x must not be used after.
CollectInto performs better if s are sorted in ascending order by the Low field.
func Delete ¶ added in v0.3.0
Delete removes zero or more Intervals from x, returning the modified Set.
func Difference ¶ added in v0.2.0
Difference returns the set of elements that are in x, but not in y, overwriting z. z must not be x or y and z must not be used after.
func Intersection ¶
Intersection returns the set of elements that are in both x and y, overwriting z. z must not be x or y and z must not be used after.
func Reduce ¶ added in v0.3.0
Reduce applies set operation op over sets, returning the end result. op can be any of Difference, Intersection, SymmetricDifference and Union.
func SymmetricDifference ¶
SymmetricDifference returns the set of elements that are in one of x and y, but not in both, overwriting z. z must not be x or y and z must not be used after.
func Union ¶
Union returns the set of elements that are in either x, or y, or both, overwriting z. z must not be x or y and z must not be used after.
func (Set[E]) Contains ¶
Contains reports whether x contains every element in range [r.Low, r.High).
func (Set[E]) ContainsUnit ¶ added in v0.4.0
ContainsUnit reports whether x contains a single element v. Faster than x.Contains(Unit(v)).
func (Set[E]) Difference ¶
Difference returns the set of elements that are in x, but not in y.
func (Set[E]) Extent ¶
Extent returns the smallest Interval that contains every element in x.
If x is empty, Extent returns the zero value.
func (Set[E]) Intersection ¶
Intersection returns the set of elements that are in both x and y.
func (Set[E]) IsSubsetOf ¶
IsSubsetOf reports whether elements in x are all in y.
func (Set[E]) SymmetricDifference ¶
SymmetricDifference returns the set of elements that are in one of x and y, but not in both.