numrange

package
v1.0.0-alpha.17 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package numrange is the single compiled {label, start, end} model of GROUP_NUMERIC_RANGES and the numeric RangeTables the facade validates at pulse.New time, and the one reading of the grouper's params — shared by the operator factory (internal/processing) and predict (internal/descriptor) so both refuse the same request with the same code and message.

Bounds are HALF-OPEN: a range covers [start, end). It is the only semantics that cannot misplace a float — a value is never "between" two adjacent ranges and never in both — so [0, 91) and [91, 104) are adjacent, not overlapping, and the integer idiom {0, 91}, {91, 104} puts 90 in the first range and 91 in the second. An omitted (or null) bound is open: -inf below, +inf above.

Leaf: stdlib + the public errors / types packages + paramread + daterange (the shared source-ambiguity and table-kind refusals).

Index

Constants

View Source
const DefaultUnmatchedLabel = "unmatched"

DefaultUnmatchedLabel is the bucket label of a row outside every range.

Operator is the type name every refusal names.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Set is the compiled inline range set; nil for a table source until
	// Resolve runs.
	Set *Set
	// Order is the supplied range labels in author order (the emission
	// order); nil for a table source until Resolve runs.
	Order []string
	// Table names a numeric range table, resolved later against the
	// instance's registry; "" for an inline source.
	Table string
	// UnmatchedLabel is the bucket of a row outside every range.
	UnmatchedLabel string
}

Config is a parsed GROUP_NUMERIC_RANGES configuration. Exactly one of an inline source (Set + Order resolved) or Table is set.

func Parse

func Parse(raw json.RawMessage) (Config, error)

Parse validates raw GROUP_NUMERIC_RANGES params: malformed params (PROCESSING_CONFIG), not exactly one of ranges / table (PULSE_RANGE_SOURCE_AMBIGUOUS), and for an inline source every Compile refusal plus an unmatched label colliding with a range label (PROCESSING_CONFIG). A table source is resolved by Resolve.

func (*Config) Resolve

func (c *Config) Resolve(specs []Spec) error

Resolve compiles specs (the inline ranges, or a resolved numeric table's) into c.Set and records the author order, refusing an unmatched label that collides with a range label.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is a validated collection of labeled numeric ranges, stored sorted by lower bound (open-lower first). Validated non-overlapping, so at most one range contains any value.

func Compile

func Compile(specs []Spec) (*Set, error)

Compile validates specs into a Set. Each failure carries its own code:

  • empty spec set → PULSE_RANGE_EMPTY
  • a non-finite bound, or start >= end when both bounds are present → PULSE_RANGE_INVALID
  • two specs sharing a Label → PULSE_RANGE_DUPLICATE_LABEL
  • two half-open ranges that share any value (open ends extend to ±inf) → PULSE_RANGE_OVERLAP

func (*Set) Len

func (s *Set) Len() int

Len reports the number of ranges in the set.

func (*Set) Match

func (s *Set) Match(v float64) (string, bool)

Match returns the label of the range containing v (start <= v < end) and true; "", false when no range contains it or v is NaN.

type Spec

type Spec struct {
	Label string   `json:"label"`
	Start *float64 `json:"start,omitempty"`
	End   *float64 `json:"end,omitempty"`
}

Spec is the wire-level shape of a single labeled numeric range, authored inline on a GROUP_NUMERIC_RANGES grouper or in a numeric range table. Start and End are JSON numbers; nil (omitted or null) is an open bound. The range covers [Start, End).

Jump to

Keyboard shortcuts

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