pubgrub/version_ranges

Version range primitives and operations.

Ranges are represented as sorted, non-overlapping intervals and carry a compare function used for ordering.

Types

A range bound: unbounded, inclusive, or exclusive.

pub type Bound(a) {
  Unbounded
  Included(a)
  Excluded(a)
}

Constructors

  • Unbounded
  • Included(a)
  • Excluded(a)

A comparison function for values of type a.

pub type Compare(a) =
  fn(a, a) -> order.Order

An interval is a pair of start/end bounds.

pub type Interval(a) =
  #(Bound(a), Bound(a))

A set of disjoint, ordered intervals.

pub type Ranges(a) {
  Ranges(
    segments: List(#(Bound(a), Bound(a))),
    compare: fn(a, a) -> order.Order,
  )
}

Constructors

Values

pub fn between(
  compare: fn(a, a) -> order.Order,
  lower: a,
  upper: a,
) -> Ranges(a)

Range bounded by [lower, upper).

pub fn compare(ranges: Ranges(a)) -> fn(a, a) -> order.Order

Extract the compare function carried by a range set.

pub fn complement(ranges: Ranges(a)) -> Ranges(a)

Complement of a range set.

pub fn contains(ranges: Ranges(a), value: a) -> Bool

Check if a value is included in the range set.

pub fn empty(compare: fn(a, a) -> order.Order) -> Ranges(a)

The empty range set.

pub fn equal(left: Ranges(a), right: Ranges(a)) -> Bool

Check whether two range sets have identical intervals.

pub fn from_range_bounds(
  compare: fn(a, a) -> order.Order,
  start: a,
  end: a,
) -> Ranges(a)

Alias for between.

pub fn full(compare: fn(a, a) -> order.Order) -> Ranges(a)

The full range set.

pub fn higher_than(
  compare: fn(a, a) -> order.Order,
  value: a,
) -> Ranges(a)

Values greater than or equal to value.

pub fn intersection(
  left: Ranges(a),
  right: Ranges(a),
) -> Ranges(a)

Intersection of two range sets.

pub fn is_disjoint(left: Ranges(a), right: Ranges(a)) -> Bool

True if two range sets do not overlap.

pub fn is_empty(ranges: Ranges(a)) -> Bool

True if the range set has no intervals.

pub fn is_full(ranges: Ranges(a)) -> Bool

True when the range spans all values.

pub fn lower_than(
  compare: fn(a, a) -> order.Order,
  value: a,
) -> Ranges(a)

Values less than or equal to value.

pub fn singleton(
  compare: fn(a, a) -> order.Order,
  value: a,
) -> Ranges(a)

A single-value range.

pub fn strictly_higher_than(
  compare: fn(a, a) -> order.Order,
  value: a,
) -> Ranges(a)

Values strictly greater than value.

pub fn strictly_lower_than(
  compare: fn(a, a) -> order.Order,
  value: a,
) -> Ranges(a)

Values strictly less than value.

pub fn subset_of(subset: Ranges(a), container: Ranges(a)) -> Bool

True if subset is fully contained in container.

pub fn to_string(
  ranges: Ranges(a),
  value_to_string: fn(a) -> String,
) -> String

Render a range set using a value formatter.

pub fn union(left: Ranges(a), right: Ranges(a)) -> Ranges(a)

Union of two range sets.

Search Document