axisds

package module
v0.0.0-...-1be4865 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

axisds: Axis (1D) data structures

Build Status Go Report Card GoDoc

This project contains data structures for entities ordered across a single dimension, which can conceptually be embedded into the real number axis.

  • regiontree: A data structure that partitions a one-dimensional space into contiguous regions, each associated with a property.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustParseInterval

func MustParseInterval[B Boundary](p Parser[B], input string) (start, end B)

MustParseInterval parses a string into an interval; panics on errors.

func MustParseIntervalPrefix

func MustParseIntervalPrefix[B Boundary](
	p Parser[B], input string,
) (start, end B, remaining string)

MustParseIntervalPrefix parses a string into an interval and an optional remainder string, 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

type BoundaryFormatter[B Boundary] func(b B) string

BoundaryFormatter is used to print boundaries.

func MakeBoundaryFormatter

func MakeBoundaryFormatter[B Boundary]() BoundaryFormatter[B]

MakeBoundaryFormatter creates a BoundaryFormatter[B] that uses fmt.Sprint().

type CompareFn

type CompareFn[B Boundary] func(x, y B) int

CompareFn is a function that compares two boundaries and returns -1, 0, or +1.

func EndpointCompareFn

func EndpointCompareFn[B Boundary](bCmp CompareFn[B]) CompareFn[Endpoint[B]]

EndpointCompareFn returns a CompareFn for Endpoint[B].

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

type IntervalFormatter[B Boundary] func(i Interval[B]) string

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

func MakeBasicParser[B Boundary]() Parser[B]

MakeBasicParser creates a Parser[B] that uses Sscanf with `%v` for the boundaries.

func MakeEndpointParser

func MakeEndpointParser[B Boundary](p Parser[B]) Parser[Endpoint[B]]

MakeEndpointParser creates a Parser[Endpoint[B]].

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL