Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RangeSet<T>

A set of non-intersecting ranges.

This class provides operators for combining, subtracting, and querying sets of ranges of an arbitrary type T. It automatically merges adjacent/intersecting ranges after each operation, guaranteeing the smallest possible number of subranges for every set of underlying ranges it represents.

This class is mutable for performance reasons.

This implementation is backed by a tree implementation conforming to RangeSetTree. The default implementation is bintrees' [[BintreeRBRangeSetTree]].

Type parameters

  • T

    The type of the ranges this set is expected to hold.

Hierarchy

  • RangeSet

Index

Accessors

isEmpty

  • get isEmpty(): boolean

subranges

  • get subranges(): Range<T>[]
  • Returns the array of the underlying ranges of this set.

    The resulting ranges are guaranteed not to intersect with each other, nor to be adjacent to any of them.

    Returns Range<T>[]

Methods

add

  • Add another range set to this set, merging intersecting/adjacent ranges.

    This operation modifies this, but keeps other untouched.

    Parameters

    • other: RangeSet<T>

      The other range set to add values from. It is possible to add a range set built with a different underlying tree implementation.

    Returns RangeSet<T>

  • Add a range to this set, merging intersecting/adjacent ranges.

    This operation modifies this.

    Parameters

    • other: Range<T>

      The range to add values from.

    Returns RangeSet<T>

clear

containing

  • containing(value: T): Range<T>
  • Finds a range containing the provided value.

    "Infinity" values cannot be contained, and therefore always return undefined.

    Parameters

    • value: T

      The value to check the containment of.

    Returns Range<T>

    The range that Range.contains value if found, or undefined otherwise.

contains

  • contains(value: T): boolean
  • contains(range: Range<T>): boolean
  • Checks whether any of the ranges within this set contains value.

    "Infinity" values cannot be contained, and therefore always return false.

    Parameters

    • value: T

      The value to check the containment of.

    Returns boolean

  • Checks whether any of the ranges within this set contains range.

    See Range.contains for details of how this check is performed.

    An empty range is always contained in any set. An empty set contains no ranges but an empty range.

    A range with an infinite bound contains other ranges with the same infinite bound, even though infinity itself cannot be contained.

    Parameters

    Returns boolean

enclosing

  • Finds a range enclosing the provided range.

    Enclosing means containing all the elements of range within the resulting range.

    Note: an empty range is not enclosed by any other range.

    Parameters

    • range: Range<T>

      The value to be enclosed by the return.

    Returns Range<T>

    The range that Range.contains range if found, except an empty range, or undefined otherwise.

subtract

  • Subtract every range from the provided range set from this set.

    This operation modifies this, but keeps other untouched.

    This operation relies on Range.union.

    Parameters

    • other: RangeSet<T>

      The other range set containing the ranges to subtract. It is possible to subtract a range set built with a different underlying tree implementation.

    Returns RangeSet<T>

  • Subtract other from this set.

    This operation modifies this.

    This operation relies on Range.subtract.

    Parameters

    • other: Range<T>

      The range to subtract.

    Returns RangeSet<T>

Static numeric

Static of

Generated using TypeDoc