intrange

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package intrange implements the OpenJD base specification's <IntRangeExpr> grammar (2023-09 Template Schemas, section 3.4.1.1.1): the succinct "1,3,7-10:2" form used for frame ranges.

It is a leaf shared by two callers that DISAGREE about what to accept, which is why Parse is spec-faithful and ParseWithPolicy exists:

  • internal/openjd/expr (the EXPR extension) needs the spec's behavior, and uses Parse.
  • internal/openjd (task-parameter expansion) is stricter than the spec in two ways that predate this package: it rejects a range whose start exceeds its end (the spec makes "1 - -1" the single value [1]) and it rejects a negative step (the spec's set formula defines one). It also orders values first-seen rather than increasing, which it does in its own expansion code rather than here.

Those divergences are deliberate to preserve, NOT bugs to fix in passing: changing them changes which job templates are accepted and the order in which tasks are generated. They are recorded in the sub-project B2 design document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Policy

type Policy struct {
	// PositiveStepOnly rejects a zero or negative step.
	PositiveStepOnly bool
	// AscendingOnly rejects an element whose start exceeds its end.
	AscendingOnly bool
}

Policy narrows what ParseWithPolicy accepts below what the specification permits. The zero Policy accepts everything the specification does.

type Range

type Range struct {
	Start int
	End   int
	Step  int
}

Range is one element of a range expression: a stepped sequence of integers anchored at Start. Step is non-zero and may be negative.

func Parse

func Parse(s string) ([]Range, error)

Parse reads a range expression into its elements, accepting everything the specification permits. It does not expand them; a caller decides its own ordering, de-duplication and size bound.

func ParseWithPolicy

func ParseWithPolicy(s string, p Policy) ([]Range, error)

ParseWithPolicy is Parse, restricted by p.

func (Range) Count

func (r Range) Count() int

Count returns how many integers the range yields, computed arithmetically without allocating — the allocation-free equivalent of len(r.Iterate()), with one exception at the top of the scale: a count that SATURATES (below) is one Iterate declines to materialize at all, so it answers nil rather than that many values.

The specification's set is {x} union {x+mn : m in Z+, x+mn <= y if n > 0, x+mn >= y if n < 0}, so the start is ALWAYS a member and the count is never zero. If the span, or the arithmetic needed to turn it into a count, would overflow, Count saturates to math.MaxInt, which exceeds any caller's bound.

func (Range) Iterate

func (r Range) Iterate() []int

Iterate yields every integer in the range, in the order the step defines.

A range whose Range.Count SATURATES to math.MaxInt cannot be materialized on any machine, so Iterate returns nil for it rather than trying: the loops below would otherwise append until the process ran out of memory. Both callers in this repository bound Count() themselves before ever calling this (internal/openjd's sumRangeCounts and internal/openjd/expr's rangeInts), so the early-out is unreachable through them — it exists so that a caller which FORGETS that bound gets an empty result instead of an out-of-memory kill, which is the only outcome the previous code could offer. It is a backstop, not a substitute for the bound: a range of, say, ten billion values does not saturate and is returned in full, one int per value.

func (Range) String

func (r Range) String() string

String renders the range in the grammar's own notation, for test names and diagnostics.

Jump to

Keyboard shortcuts

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