Documentation
¶
Index ¶
- func MustParseInterval[B Boundary](p Parser[B], input string) (start, end B)
- func MustParseIntervalPrefix[B Boundary](p Parser[B], input string) (start, end B, remaining string)
- type Boundary
- type BoundaryFormatter
- type CompareFn
- type Endpoint
- func MakeEndEndpoint[B Boundary](endBoundary B, endTyp InclusiveOrExclusive) Endpoint[B]
- func MakeEndpoints[B Boundary](startBoundary B, startTyp InclusiveOrExclusive, endBoundary B, ...) (start, end Endpoint[B])
- func MakeStartEndpoint[B Boundary](startBoundary B, startTyp InclusiveOrExclusive) Endpoint[B]
- type InclusiveOrExclusive
- type Interval
- type IntervalFormatter
- type Parser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustParseInterval ¶
MustParseInterval parses a string into an interval; panics on errors.
Types ¶
type Boundary ¶
type Boundary any
Boundary is the most basic unit used by this library. It represents a boundary on a 1D axis.
The data structures in this package operate on half-open intervals like [startBoundary, endBoundary).
Endpoint is a Boundary wrapper that creates more fine-grained intervals, allowing arbitrary types of intervals (in terms of inclusive vs exclusive endpoints).
NOTE: it's equivalent to think of Boundaries as being infinitesimal and not corresponding to any valid value. In this case, there is no concept of inclusive or exclusive intervals. Endpoint can represent infinitesimal boundaries that are immediately before or after a value, allowing arbitrary types of intervals (with respect to valid values).
type BoundaryFormatter ¶
BoundaryFormatter is used to print boundaries.
func MakeBoundaryFormatter ¶
func MakeBoundaryFormatter[B Boundary]() BoundaryFormatter[B]
MakeBoundaryFormatter creates a BoundaryFormatter[B] that uses fmt.Sprint().
type Endpoint ¶
type Endpoint[B Boundary] struct { B B // If PlusEpsilon is true, the boundary is considered to be infinitesimally // after B. When used as an interval ending point, it corresponds to an // inclusive end bound. When used as an interval starting point, it // corresponds to an exclusive start bound. PlusEpsilon bool }
Endpoint is a Boundary that extends a simpler boundary type to allow representing intervals with inclusive or exclusive end points.
func MakeEndEndpoint ¶
func MakeEndEndpoint[B Boundary](endBoundary B, endTyp InclusiveOrExclusive) Endpoint[B]
func MakeEndpoints ¶
func MakeEndpoints[B Boundary]( startBoundary B, startTyp InclusiveOrExclusive, endBoundary B, endTyp InclusiveOrExclusive, ) (start, end Endpoint[B])
func MakeStartEndpoint ¶
func MakeStartEndpoint[B Boundary](startBoundary B, startTyp InclusiveOrExclusive) Endpoint[B]
type InclusiveOrExclusive ¶
type InclusiveOrExclusive int8
InclusiveOrExclusive is used to specify the type of interval endpoint.
const Exclusive InclusiveOrExclusive = 2
const Inclusive InclusiveOrExclusive = 1
func InclusiveIf ¶
func InclusiveIf(inclusive bool) InclusiveOrExclusive
InclusiveIf returns Inclusive if the argument is true and Exclusive otherwise.
type Interval ¶
type Interval[B Boundary] struct { Start, End B }
Interval represents the half-open interval [Start, End). See Boundary and Endpoint for more details.
type IntervalFormatter ¶
IntervalFormatter is used to print intervals.
func MakeEndpointIntervalFormatter ¶
func MakeEndpointIntervalFormatter[B Boundary]( bFmt BoundaryFormatter[B], ) IntervalFormatter[Endpoint[B]]
MakeEndpointIntervalFormatter creates an IntervalFormatter[Endpoint[B]] which uses the given formatter for B.
func MakeIntervalFormatter ¶
func MakeIntervalFormatter[B Boundary](bFmt BoundaryFormatter[B]) IntervalFormatter[B]
MakeIntervalFormatter creates an IntervalFormatter[B] which uses the given formatter for B.
type Parser ¶
type Parser[B Boundary] interface { // ParseBoundary is used to parse a "bare" boundary. Used for Endpoint[B]. ParseBoundary(str string) (b B, err error) // ParseInterval parses an interval of the form `boundary1, boundary2` // from the input and returns any remaining fields in the string. ParseInterval(input string) (start, end B, remaining string, err error) }
Parser is an interface for parsing intervals.
func MakeBasicParser ¶
MakeBasicParser creates a Parser[B] that uses Sscanf with `%v` for the boundaries.