Class NumberSet

A set of numbers represented by the union of disjoint intervals

Remarks

Hierarchy

  • NumberSet

Properties

intervals: readonly Interval[]

Methods

  • Convenience generator to iterate over the internal intervals

    Example

    const set = new NumberSet([Interval.Open(-1, 0), Interval.Open(0, 1)]);
    for (const interval of set) {
    console.log(interval.toString());
    }
    // "(-1,0)"
    // "(0,1)"

    Returns Generator<Interval, void, undefined>

  • Returns

    True if x is included in this set

    Parameters

    • x: number

      Number to search for

    Returns boolean

  • Returns

    The NumberSet's diameter (supremum of distances between two points in the set, e.g. largest upper bound minus the smallest lower bound in our case)

    Returns number

  • Transforms the set to its string representation by joining the intervals' string representation with ", " and surrounding the result with braces

    Example

    console.log(
    new NumberSet([Interval.Open(-1, 0), Interval.Open(0, 1)]).toString()
    );
    // "{(-1,0), (0,1)}"

    Returns

    This set's string representation

    Returns string

  • Constructs a new NumberSet from the given intervals.

    Remarks

    Note that the intervals are stored internally in a "normalized" manner meaning

    • touching intervals are merged
    • empty intervals are omitted
    • the intervals are sorted by their lower bound in ascending order (included bounds have precedence)

    Parameters

    • intervals: readonly Interval[]

      Intervals representing this set

    Returns NumberSet

  • Alpha

    Constructs a NumberSet from a string representation

    Remarks

    Expects a list of Interval string representations separated by ", " surrounded by curly braces. See fromString for more information on formatting intervals.

    Prefer constructing directly from Intervals instead of strings if possible

    Example

    NumberSet.fromString("{(-1,0), (0,1)}").equals(new NumberSet([
    Interval.Open(-1,0), Interval.Open(0,1)
    ])); // true

    Returns

    NumberSet corresponding to the string representation

    Throws

    ParseError if s is malformed

    Parameters

    • s: string

      String representation of the NumberSet

    Returns NumberSet

Generated using TypeDoc