Interface SortedListOfRanges

All Superinterfaces:
CharacterSet
All Known Subinterfaces:
ImmutableSortedListOfRanges, RangesBuffer
All Known Implementing Classes:
CaseFoldData.CaseFoldEquivalenceTable, CaseFoldData.CaseFoldTable, CodePointSet, ImmutableSortedListOfIntRanges, IntRangesBuffer

public interface SortedListOfRanges extends CharacterSet
A storage-agnostic implementation of a sorted list of disjoint integer ranges with inclusive lower and upper bounds. Holds the invariant rangesAreSortedNonAdjacentAndDisjoint().
  • Method Details

    • getLo

      int getLo(int i)
      Returns the inclusive lower bound of the range stored at index i.
    • getHi

      int getHi(int i)
      Returns the inclusive upper bound of the range stored at index i.
    • size

      int size()
      Returns the number of disjoint ranges contained in this list.
    • appendRangesTo

      void appendRangesTo(RangesBuffer buffer, int startIndex, int endIndex)
      Append all ranges from startIndex (inclusive) to endIndex (exclusive) to the given buffer. The caller is responsible for not violating the target buffer's sortedness; This effectively means that the range at startIndex must be rightOf the buffer's last range.
    • isEmpty

      default boolean isEmpty()
    • isSingle

      default boolean isSingle(int i)
      Returns true if the range at index i consists of a single value, i.e. getLo(i) == getHi(i).
    • size

      default int size(int i)
      Returns the number of values contained in the range at index i.
    • sizeOfInverse

      default int sizeOfInverse(Encodings.Encoding encoding)
      Returns the number of disjoint ranges contained in the inverse (as defined by ImmutableSortedListOfRanges.createInverse(Encoding)) of this list.
    • getMin

      default int getMin()
      Returns the smallest value contained in this set. Must not be called on empty sets.
    • getMax

      default int getMax()
      Returns the largest value contained in this set. Must not be called on empty sets.
    • inverseGetMin

      default int inverseGetMin(Encodings.Encoding encoding)
      Returns the smallest value contained in the inverse of this set. Must not be called on empty or full sets.
    • inverseGetMax

      default int inverseGetMax(Encodings.Encoding encoding)
      Returns the largest value contained in the inverse of this set. Must not be called on empty or full sets.
    • contains

      static boolean contains(int aLo, int aHi, int bLo, int bHi)
      Returns true if the range [aLo, aHi] contains the range [bLo, bHi].
    • contains

      default boolean contains(int ia, SortedListOfRanges o, int ib)
      Returns true if the range at index ia contains the range in list o at index ib.
    • contains

      default boolean contains(int ia, int bLo, int bHi)
      Returns true if the range at index ia contains the range [bLo, bHi].
    • containedBy

      default boolean containedBy(int ia, int bLo, int bHi)
      Returns true if the range [bLo, bHi] contains the range at index ia.
    • intersects

      static boolean intersects(int aLo, int aHi, int bLo, int bHi)
      Returns true if the range [aLo, aHi] intersects with the range [bLo, bHi].
    • intersects

      default boolean intersects(int ia, SortedListOfRanges o, int ib)
      Returns true if the range at index ia intersects with the range in list o at index ib.
    • intersects

      default boolean intersects(int ia, int bLo, int bHi)
      Returns true if the range at index ia intersects with the range [bLo, bHi].
    • leftOf

      static boolean leftOf(int aLo, int aHi, int bLo, int bHi)
      Returns true if the range [aLo, aHi] is "left of" the range [bLo, bHi], where "left of" means "all values of range a are less than all values of range b" - i.e. {code aHi < bLo}.
    • leftOf

      static boolean leftOf(int aHi, int bLo)
      Variant of leftOf(int, int, int, int) without the unnecessary parameters.
    • leftOf

      default boolean leftOf(int ia, SortedListOfRanges o, int ib)
      Returns true if the range at index ia is "left of" the range in list o at index ib.
      See Also:
    • leftOf

      default boolean leftOf(int ia, int bLo, int bHi)
      Returns true if the range at index ia is "left of" the range [bLo, bHi].
      See Also:
    • rightOf

      static boolean rightOf(int aLo, int aHi, int bLo, int bHi)
      Returns true if the range [aLo, aHi] is "right of" the range [bLo, bHi], where "right of" means "all values of range a are greater than all values of range b" - i.e. {code aLo > bHi}.
    • rightOf

      static boolean rightOf(int aLo, int bHi)
      Variant of rightOf(int, int, int, int) without the unnecessary parameters.
    • rightOf

      default boolean rightOf(int ia, SortedListOfRanges o, int ib)
      Returns true if the range at index ia is "right of" the range in list o at index ib.
      See Also:
    • rightOf

      default boolean rightOf(int ia, int bLo, int bHi)
      Returns true if the range at index ia is "right of" the range [bLo, bHi].
      See Also:
    • adjacent

      static boolean adjacent(int aLo, int aHi, int bLo, int bHi)
      Returns true if the ranges [aLo, aHi] and [bLo, bHi] are adjacent to each other, meaning that the lower bound of one range immediately follows the upper bound of the other.
    • adjacent

      default boolean adjacent(int ia, SortedListOfRanges o, int ib)
      Returns true if the range at index ia is adjacent to the range in list o at index ib.
      See Also:
    • adjacent

      default boolean adjacent(int ia, int bLo, int bHi)
      Returns true if the range at index ia is adjacent to the range [bLo, bHi].
      See Also:
    • equal

      default boolean equal(int ia, SortedListOfRanges o, int ib)
      Returns true if the range at index ia is equal to the range in list o at index ib.
    • equal

      default boolean equal(int ia, int bLo, int bHi)
      Returns true if the range at index ia is equal to the range [bLo, bHi].
    • binarySearch

      default int binarySearch(int keyLo)
      Performs a binary search for a range with the given lower bound (keyLo), in the same way as Arrays.binarySearch(int[], int) would behave on an array containing only the lower bounds of all ranges in this list.
    • binarySearchExactMatch

      default boolean binarySearchExactMatch(int searchResult, SortedListOfRanges o, int ib)
      Returns true if a given binary search result is equal to the range in list o at index ib.
      Parameters:
      searchResult - the result of a call to binarySearch(int) with o.getLo(ib) as the parameter.
    • binarySearchExactMatch

      default boolean binarySearchExactMatch(int searchResult, int bLo, int bHi)
      Returns true if a given binary search result is equals to the range [bLo, bHi].
      Parameters:
      searchResult - the result of a call to binarySearch(int) with bLo as the parameter.
    • binarySearchGetFirstIntersecting

      default int binarySearchGetFirstIntersecting(int searchResult, SortedListOfRanges o, int ib)
      If there was no exact match in a binary search, this method will return the index of the first range that intersects with the range in o at index ib, or size().
      Parameters:
      searchResult - the result of a call to binarySearch(int) with o.getLo(ib) as the parameter.
    • binarySearchGetFirstIntersecting

      default int binarySearchGetFirstIntersecting(int searchResult, int bLo, int bHi)
      If there was no exact match in a binary search, this method will return the index of the first range that intersects with the range [bLo, bHi], or size().
      Parameters:
      searchResult - the result of a call to binarySearch(int) with bLo as the parameter.
    • binarySearchGetFirstIntersectingOrAdjacent

      default int binarySearchGetFirstIntersectingOrAdjacent(int searchResult, int bLo, int bHi)
      If there was no exact match in a binary search, this method will return the index of the first range that intersects with or is adjacent to the range [bLo, bHi], or size() .
      Parameters:
      searchResult - the result of a call to binarySearch(int) with bLo as the parameter.
    • binarySearchGetFirstIntersectingOrAdjacent

      default int binarySearchGetFirstIntersectingOrAdjacent(int searchResult, int oLo, int oHi, boolean includeAdjacent)
    • binarySearchNoIntersectingFound

      default boolean binarySearchNoIntersectingFound(int firstIntersecting)
      Returns true if no intersecting range was found by a call to binarySearchGetFirstIntersecting(int, int, int) or one if its variants.
      Parameters:
      firstIntersecting - the result of a call to binarySearchGetFirstIntersecting(int, int, int) or one if its variants.
    • addRangeTo

      default void addRangeTo(RangesBuffer buffer, int i)
      Appends the range at index i to the given buffer.
    • rangesAreSortedNonAdjacentAndDisjoint

      default boolean rangesAreSortedNonAdjacentAndDisjoint()
      Returns true if this list is sorted and all of its ranges are disjoint and non-adjacent. This property must hold at all times.
    • rangesAreSortedAndDisjoint

      default boolean rangesAreSortedAndDisjoint()
      Returns true if this list is sorted and all of its ranges are disjoint. This property must hold at all times.
    • contains

      default boolean contains(int codePoint)
      Returns true if this list contains the given codePoint.
      Specified by:
      contains in interface CharacterSet
    • contains

      default boolean contains(SortedListOfRanges o)
      Returns true if this list contains all values of o.
    • intersects

      default boolean intersects(SortedListOfRanges o)
      Returns true if this list intersects with o.
    • union

      static void union(SortedListOfRanges a, SortedListOfRanges b, RangesBuffer target)
      Converts target to the union of a and b.
    • intersect

      static void intersect(SortedListOfRanges a, SortedListOfRanges b, RangesBuffer target)
      Converts target to the intersection of a and b.
    • invert

      static void invert(SortedListOfRanges a, Encodings.Encoding encoding, RangesBuffer target)
    • matchesNothing

      default boolean matchesNothing()
      Returns true if this list is empty.
    • matchesSomething

      default boolean matchesSomething()
      Returns true if this list is non-empty.
    • matchesSingleChar

      default boolean matchesSingleChar()
      Returns true if this list contains just one single value.
    • matchesSingleAscii

      default boolean matchesSingleAscii()
      Returns true if this list contains just one single value which is less than 128.
    • matchesMinAndMax

      default boolean matchesMinAndMax(Encodings.Encoding encoding)
    • matches2CharsWith1BitDifference

      default boolean matches2CharsWith1BitDifference()
      Returns true iff this code point set contains exactly two characters whose binary representation differs in one bit only.
    • valueCount

      default int valueCount()
      Returns the total number of values contained in this list.
    • valueCountEquals

      default boolean valueCountEquals(int cmp)
      Returns true iff the total number of values contained in this list is equal to cmp.
    • valueCountMax

      default boolean valueCountMax(int cmp)
      Returns true iff the total number of values contained in this list is less or equal to cmp.
    • inverseValueCount

      default int inverseValueCount(Encodings.Encoding encoding)
      Returns the total number of values (from Encodings.Encoding.getMinValue() to Encodings.Encoding.getMaxValue()) not contained in this list.
    • matchesEverything

      default boolean matchesEverything(Encodings.Encoding encoding)
      Returns true if this list is equal to [Encodings.Encoding.getMinValue() Encodings.Encoding.getMaxValue() ].
    • equalsListOfRanges

      default boolean equalsListOfRanges(SortedListOfRanges o)
    • defaultToString

      default String defaultToString()
    • rangesToString

      default String rangesToString()
    • inverseRangesToString

      default String inverseRangesToString(Encodings.Encoding encoding)