Documentation
¶
Overview ¶
Library that provides to divide a sequence of something into spans.
Index ¶
- Variables
- func CompareDec[Type cmp.Ordered](first, second Span[Type]) int
- func CompareInc[Type cmp.Ordered](first, second Span[Type]) int
- func Even[Type constraints.Integer](begin, end, quantity Type) iter.Seq2[uint64, Span[Type]]
- func EvenSlices[Type any, TypeQ constraints.Integer](divisible []Type, quantity TypeQ) iter.Seq[[]Type]
- func IsContinuous[Type constraints.Integer](spans []Span[Type]) error
- func IsNonDecreasing[Type cmp.Ordered](spans []Span[Type]) error
- func IsNonIncreasing[Type cmp.Ordered](spans []Span[Type]) error
- func IsNotDiffSequencing[Type cmp.Ordered](spans []Span[Type]) error
- func IsNotIntersect[Type cmp.Ordered](spans []Span[Type]) error
- func SearchDec[Type cmp.Ordered](item, target Span[Type]) int
- func SearchInc[Type cmp.Ordered](item, target Span[Type]) int
- type Span
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrSpansDiffSequencing = errors.New("spans have different types of sequences") ErrSpansDiscontinuous = errors.New("spans is discontinuous") ErrSpanSequenceNotNonDecreasing = errors.New("span sequence is not non-decreasing") ErrSpanSequenceNotNonIncreasing = errors.New("span sequence is not non-increasing") ErrSpansIntersect = errors.New("spans is intersect") ErrSpansQuantityNegative = errors.New("spans quantity is negative") ErrSpansQuantityZero = errors.New("spans quantity is zero") ErrSpanWidthNegative = errors.New("span width is negative") ErrSpanWidthZero = errors.New("span width is zero") )
Functions ¶
func CompareDec ¶ added in v0.4.0
Compare function for sorting of decreasing sequence of spans.
Partially detects spans intersections, but does not guarantee complete verification.
Partially detects the presence of spans that have a different sequence type, but does not guarantee complete verification.
func CompareInc ¶ added in v0.4.0
Compare function for sorting of increasing sequence of spans.
Partially detects spans intersections, but does not guarantee complete verification.
Partially detects the presence of spans that have a different sequence type, but does not guarantee complete verification.
func Even ¶ added in v0.7.0
A range iterator used to iterating over a sequence of spans obtained by dividing a linear sequence of integers evenly from begin to end inclusive into a specified quantity of spans.
If begin is greater than end, the sequence of spans will be decreasing, otherwise - increasing.
Quantity of iterations can be less than the specified quantity of spans, but cannot be greater.
If a zero or negative quantity of spans is specified, the iterator will panic.
Works like Evenly but does not perform memory allocation.
func EvenSlices ¶ added in v0.9.0
func EvenSlices[Type any, TypeQ constraints.Integer](divisible []Type, quantity TypeQ) iter.Seq[[]Type]
A range iterator used to iterating over a subslices obtained by evenly dividing a main slice into a specified quantity of subslices.
Quantity of iterations can be less than the specified quantity of subslices, but cannot be greater.
If a zero or negative quantity of subslices is specified, the iterator will panic.
func IsContinuous ¶ added in v0.4.0
func IsContinuous[Type constraints.Integer](spans []Span[Type]) error
Checks that a sequence of spans is continuous and monotone.
func IsNonDecreasing ¶ added in v0.6.0
Checks that a spans sequence consists of only non-decreasing spans.
func IsNonIncreasing ¶ added in v0.6.0
Checks that a spans sequence consists of only non-increasing spans.
func IsNotDiffSequencing ¶ added in v0.4.0
Checks that a sequence of spans does not contain spans with different sequence types (increasing or decreasing).
func IsNotIntersect ¶ added in v0.4.0
Checks that a sequence of spans does not contain intersect spans.
Types ¶
type Span ¶
Describes span.
func Evenly ¶ added in v0.3.0
func Evenly[Type constraints.Integer](begin, end, quantity Type) ([]Span[Type], error)
Divides a linear sequence of integers evenly from begin to end inclusive into a specified quantity of spans.
If begin is greater than end, the sequence of integers will be considered decreasing, otherwise - increasing.
Length of the returned slice can be less than the specified quantity of spans, but cannot be greater.
If a zero or negative quantity of spans is specified, an error is returned.
Example ¶
package main
import (
"fmt"
"github.com/akramarenkov/span"
)
func main() {
spans, err := span.Evenly(1, 8, 3)
fmt.Println(err)
fmt.Println(spans)
}
Output: <nil> [{1 3} {4 6} {7 8}]
func Linear ¶ added in v0.3.0
func Linear[Type constraints.Integer](begin, end, width Type) ([]Span[Type], error)
Divides a linear sequence of integers from begin to end inclusive into spans of the specified width.
If begin is greater than end, the sequence of integers will be considered decreasing, otherwise - increasing.
If a zero or negative width of span is specified, an error is returned.
Example ¶
package main
import (
"fmt"
"github.com/akramarenkov/span"
)
func main() {
spans, err := span.Linear(1, 7, 2)
fmt.Println(err)
fmt.Println(spans)
}
Output: <nil> [{1 2} {3 4} {5 6} {7 7}]