de.caff.generics.algorithm

## Class FastSequenceSearch<T>

- java.lang.Object
- - de.caff.generics.algorithm.FastSequenceSearch<T>

- Type Parameters:
    `T` - type of sequence elements, it is required

      public class FastSequenceSearch<T>
      extends java.lang.Object

  Fast search algorithm in sequences of random-accessible values.

  Currently only forward search is implemented, but basically both the search indexable and the searched indexable can be `reversed` before searching.

  Although based on integers this may also be used for searches in byte or character sequences.

  Since:
    July 07, 2020
  Author:
    Rammi

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FastSequenceSearch(java.util.function.BiPredicate<? super T,? super T> equality, T... searchTerm)` Constructor.
    `FastSequenceSearch(Indexable<T> searchTerm, java.util.function.BiPredicate<? super T,? super T> equality)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `IntIndexable` | `findAllMatches(Indexable<T> data, boolean allowOverlaps)` Find all matches.
    `int` | `findFirst(Indexable<T> data)` Find the first appearance of the search term in the given data.
    `int` | `findNext(Indexable<T> data, int pos)` Find the next appearance of the search term after the given position in the given data.
    `int` | `findNext(Indexable<T> data, int pos, int end)` Find the next appearance of the search term after the given start position and before the given end position in the given data.
    `Indexable<T>` | `getSearchTerm()` Get the search term.
    `static <TT> FastSequenceSearch<TT>` | `usingDeepEquals(Indexable<TT> searchTerm)` Create a fast sequence search which uses `Objects.deepEquals()` for equality.
    `static <TT> FastSequenceSearch<TT>` | `usingDeepEquals(TT... searchTerm)` Create a fast sequence search which uses `Objects.deepEquals()` for equality.
    `static <TT> FastSequenceSearch<TT>` | `usingEquals(Indexable<TT> searchTerm)` Create a fast sequence search which uses `Objects.equals()` for equality.
    `static <TT> FastSequenceSearch<TT>` | `usingEquals(TT... searchTerm)` Create a fast sequence search which uses `Objects.equals()` for equality.
    `static <TT> FastSequenceSearch<TT>` | `usingIdentity(Indexable<TT> searchTerm)` Create a fast sequence search which uses identity (i.e.
    `static <TT> FastSequenceSearch<TT>` | `usingSame(TT... searchTerm)` Create a fast sequence search which uses identity (i.e.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FastSequenceSearch

          public FastSequenceSearch(@NotNull
                                    Indexable<T> searchTerm,
                                    @NotNull
                                    java.util.function.BiPredicate<? super T,? super T> equality)

      Constructor.
      Parameters:
        `searchTerm` - term to search for
        `equality` - predicate which defines whether two elements are equal

    - #### FastSequenceSearch

          @SafeVarargs
          public FastSequenceSearch(@NotNull
                                                 java.util.function.BiPredicate<? super T,? super T> equality,
                                                 @NotNull
                                                 T... searchTerm)

      Constructor.
      Parameters:
        `searchTerm` - long int sequence to search for
        `equality` - predicate which defines whether two elements are equal

  - ### Method Detail

    - #### usingEquals

          @NotNull
          public static <TT> FastSequenceSearch<TT> usingEquals(@NotNull
                                                                         Indexable<TT> searchTerm)

      Create a fast sequence search which uses `Objects.equals()` for equality.
      Type Parameters:
        `TT` - sequence element type
      Parameters:
        `searchTerm` - search term
      Returns:
        fast sequential search which uses standard equality

    - #### usingEquals

          @NotNull
           @SafeVarargs
          public static <TT> FastSequenceSearch<TT> usingEquals(@NotNull
                                                                                       TT... searchTerm)

      Create a fast sequence search which uses `Objects.equals()` for equality.
      Type Parameters:
        `TT` - sequence element type
      Parameters:
        `searchTerm` - search term
      Returns:
        fast sequential search which uses standard equality

    - #### usingDeepEquals

          @NotNull
          public static <TT> FastSequenceSearch<TT> usingDeepEquals(@NotNull
                                                                             Indexable<TT> searchTerm)

      Create a fast sequence search which uses `Objects.deepEquals()` for equality.
      Type Parameters:
        `TT` - sequence element type
      Parameters:
        `searchTerm` - search term
      Returns:
        fast sequential search which uses standard equality

    - #### usingDeepEquals

          @NotNull
           @SafeVarargs
          public static <TT> FastSequenceSearch<TT> usingDeepEquals(@NotNull
                                                                                           TT... searchTerm)

      Create a fast sequence search which uses `Objects.deepEquals()` for equality.
      Type Parameters:
        `TT` - sequence element type
      Parameters:
        `searchTerm` - search term
      Returns:
        fast sequential search which uses standard equality

    - #### usingIdentity

          @NotNull
          public static <TT> FastSequenceSearch<TT> usingIdentity(@NotNull
                                                                           Indexable<TT> searchTerm)

      Create a fast sequence search which uses identity (i.e. `o1 == o2`) for equality.
      Type Parameters:
        `TT` - sequence element type
      Parameters:
        `searchTerm` - search term
      Returns:
        fast sequential search which uses standard equality

    - #### usingSame

          @NotNull
           @SafeVarargs
          public static <TT> FastSequenceSearch<TT> usingSame(@NotNull
                                                                                     TT... searchTerm)

      Create a fast sequence search which uses identity (i.e. `o1 == o2`) for equality.
      Type Parameters:
        `TT` - sequence element type
      Parameters:
        `searchTerm` - search term
      Returns:
        fast sequential search which uses standard equality

    - #### getSearchTerm

          @NotNull
          public Indexable<T> getSearchTerm()

      Get the search term.
      Returns:
        search term

    - #### findFirst

          public int findFirst(@NotNull
                               Indexable<T> data)

      Find the first appearance of the search term in the given data.
      Parameters:
        `data` - data to search through
      Returns:
        index of first appearance of the search term in the given data, or `-1` if there was nothing found

    - #### findNext

          public int findNext(@NotNull
                              Indexable<T> data,
                              int pos)

      Find the next appearance of the search term after the given position in the given data.
      Parameters:
        `data` - data to search through
        `pos` - position to start the search
      Returns:
        position of next appearance of the search term in the given data after the given position, or `-1` if there was nothing found between the position and the end of data

    - #### findNext

          public int findNext(@NotNull
                              Indexable<T> data,
                              int pos,
                              int end)

      Find the next appearance of the search term after the given start position and before the given end position in the given data.
      Parameters:
        `data` - data to search through
        `pos` - position to start the search
        `end` - position to end the search, the whole search term has to fit before this position to be found
      Returns:
        position of next appearance of the search term in the given data after the given start position and before the given end position, or `-1` if there was nothing found between the position and the end of data

    - #### findAllMatches

          @NotNull
          public IntIndexable findAllMatches(@NotNull
                                                      Indexable<T> data,
                                                      boolean allowOverlaps)

      Find all matches.
      Parameters:
        `data` - data to search
        `allowOverlaps` - allow overlapping sequences in the matches?
      Returns:
        start position of all matches