Documentation
¶
Index ¶
- func Contains[S ~[]T, T constraints.Ordered](s S, e T) bool
- func Enumerate[S ~[]T, T any](s S, f func(l, h T))
- func Hull[S ~[]T, T constraints.Ordered](s S) S
- func InsertInterval[S ~[]T, T constraints.Ordered](s *S, l, h T)
- func Write[S ~[]T, T any](w io.Writer, s S)
- type AsciiSet
- type RuneSet
- func (s RuneSet) AsciiSplit() (AsciiSet, RuneSet)
- func (s RuneSet) CountElements() int
- func (s RuneSet) EnumerateRanges(f func(rmin, rmax rune))
- func (s RuneSet) Hull() RuneSet
- func (s *RuneSet) Insert(r rune)
- func (s *RuneSet) InsertRange(rmin, rmax rune)
- func (s RuneSet) Inverted() RuneSet
- func (s RuneSet) String() string
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[S ~[]T, T constraints.Ordered](s S, e T) bool
Contains returns true if element e passes containment test within the interval set s.
func Enumerate ¶
func Enumerate[S ~[]T, T any](s S, f func(l, h T))
Enumerate is a generic functional enumerator for a set. The callback is called with half-open boundaries for each interval within the set. If s has an odd number of elements, meaning the the last element is an open-ended interval, the callback is called with l = h.
func Hull ¶ added in v0.3.0
func Hull[S ~[]T, T constraints.Ordered](s S) S
Hull returns a set that contains at most one interval that covers all intervals in s.
func InsertInterval ¶
func InsertInterval[S ~[]T, T constraints.Ordered](s *S, l, h T)
InsertInterval merges an interval into s.
- if l < h, a bounded interval [l,h) is merged in
- if l >= h, a half-open interval [l,... is merged instead
Types ¶
type AsciiSet ¶
AsciiSet is a containment set for 7-bit ASCII characters [\x00..\x7f].
func MergeAsciiSets ¶
MergeRuneSets combines multiple containment sets into one.
func (AsciiSet) CountElements ¶ added in v0.3.0
CountElements returns the number of ASCII codeunits effectively contained in s.
func (AsciiSet) EnumerateRanges ¶
EnumerateRanges is a functional enumerator for all the continuous inclusive [cmin,cmax] ranges contained within the set.
func (*AsciiSet) InsertRange ¶
InsertRange inserts an inclusive [cmin,cmax] range of ascii characters into the set. Notice, that the inserted ranges are fully inclusive on both ends, unlike intervals which are always half open.
type RuneSet ¶
RuneSet is a containment set for unicode codepoints [U+00..U+10FFFF].
func MergeRuneSets ¶
MergeRuneSets combines multiple containment sets into one.
func (RuneSet) AsciiSplit ¶
AsciiSplit splits r into ascii and non-ascii matchers.
func (RuneSet) CountElements ¶ added in v0.3.0
CountElements returns the number of unicode codepoints effectively contained in s.
func (RuneSet) EnumerateRanges ¶
EnumerateRanges is a functional enumerator for all the continuous inclusive [rmin,rmax] ranges contained within the set.
func (*RuneSet) InsertRange ¶
InsertRange inserts an inclusive [rmin,rmax] range of unicode codepoints into the set. Notice, that the inserted ranges are fully inclusive on both ends, unlike intervals which are always half open.
type Set ¶
type Set[T constraints.Ordered] []T
Set is a compacted and flattened representation of a set of arithmetic intervals.
All elements in the set are sorted and no duplicates are allowed. Each interval in the set is formed by pairing adjacent even/odd elements. Values with even indices are considered as inclusive lower boundaries, values with odd indices are considered as exclusive upper boundaries. If the total number of elements is odd, then the last element is treaded as open-ended interval:
elements: A B C D E F G meaning: [ ) [ ) [ ) [