Interface SuffixArray.Range

All Superinterfaces:
Iterable<Integer>
Enclosing class:
SuffixArray

public static interface SuffixArray.Range extends Iterable<Integer>
Interface representing a range in a suffix array resulting from a search for all instances of a subsequence.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    end()
    Get the ending index into the corresponding suffix array (exclusive).
    Get an iterator that will return a sequence of indices into a sequence.
    int[]
    Create a sorted array containing the subsequence indices for this range.
    int
    Get the number of sequences in this range.
    int
    Get the starting index into the corresponding suffix array (inclusive).
     
    int
    Get an index into a sequence for a subsequence.
    int
    Get the length of the subsequence.
    int[]
    Get an array of subsequence indices.
    int[]
    toArray(int[] a)
    Get an array of subsequence indices using an existing array.
    void
    toArray(int[] a, int offset)
    Get an array of subsequence indices using an existing array and an offset into that array.

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • size

      int size()
      Get the number of sequences in this range.
      Returns:
      the number of sequences
    • start

      int start()
      Get the starting index into the corresponding suffix array (inclusive).
      Returns:
      the starting index
    • end

      int end()
      Get the ending index into the corresponding suffix array (exclusive).
      Returns:
      the ending index
    • subsequenceIndex

      int subsequenceIndex(int ind)
      Get an index into a sequence for a subsequence. The subsequences associated with a range are indexed starting at 0. Each has a corresponding index into the full sequence.
      Parameters:
      ind - the subsequence index (non-negative and less then the size of this range)
      Returns:
      the corresponding index into the sequence
      See Also:
    • subsequenceLength

      int subsequenceLength()
      Get the length of the subsequence.
      Returns:
      the subsequence length
    • iterator

      Get an iterator that will return a sequence of indices into a sequence.

      Note: the iterator is an instance of SuffixArray.Iterator and the subsequences are in lexical order of the corresponding suffixes. This will in general not be the order in which the subsequences appear in the sequence itself. To put the subsequences in their order or appearance, use toArray() and sort the array that is returned.

      Specified by:
      iterator in interface Iterable<Integer>
      Returns:
      the iterator.
    • sequenceOrder

      int[] sequenceOrder()
      Create a sorted array containing the subsequence indices for this range.

      This method is provided for convenience: the simplest implementation just calls toArray() to obtain an array and passes that array to Arrays.sort(int[]) before returning the array. For very long sequences where a subsequence occurs a large number of times, this method will allocate a significant amount of memory.

      If the order of the sequence indices do not matter, or if they will be sorted later (e.g., when indices are obtained using two separate ranges), one should not use this method.

      Returns:
      the subsequence indices sorted in numerical order (lowest first)
    • toArray

      int[] toArray()
      Get an array of subsequence indices. Each element of the array will be an index into the sequence corresponding to this object's suffix array.
      Returns:
      the array of indices into a sequence
    • toArray

      int[] toArray(int[] a)
      Get an array of subsequence indices using an existing array. Each element of the array will be an index into the sequence corresponding to this object's suffix array.

      The argument array will be ignored if it is too short and a new array will be allocated.

      Parameters:
      a - an array into which the values should be stored
      Returns:
      the array of indices into a sequence
    • toArray

      void toArray(int[] a, int offset) throws IllegalArgumentException
      Get an array of subsequence indices using an existing array and an offset into that array. Each element of the array will be an index into the sequence corresponding to this object's suffix array. An exception will be thrown if the array passed as the first argument is too short.

      One use case occurs when searching for multiple substrings. This method can be used to put all of the substring indices into the same array, which can then be sorted so that the substrings referenced by the subsequence indices appear in the same order as in the sequence.

      Parameters:
      a - an array into which the values should be stored
      offset - the starting index into the array
      Throws:
      IllegalArgumentException - the array is too short
    • stream

      IntStream stream()