de.caff.generics.algorithm

## Class FastCharSequenceSearch

- java.lang.Object
- - de.caff.generics.algorithm.FastCharSequenceSearch

-     public class FastCharSequenceSearch
      extends java.lang.Object

  Fast search algorithm in sequences of random-accessible char 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
    `FastCharSequenceSearch(char... searchTerm)` Convenience constructor.
    `FastCharSequenceSearch(CharIndexable searchTerm)` Constructor.
    `FastCharSequenceSearch(java.lang.String searchTerm)` Convenience constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `IntIndexable` | `findAllMatches(CharIndexable data, boolean allowOverlaps)` Find all matches.
    `int` | `findFirst(CharIndexable data)` Find the first appearance of the search term in the given data.
    `int` | `findNext(CharIndexable data, int pos)` Find the next appearance of the search term after the given position in the given data.
    `int` | `findNext(CharIndexable 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.
    `CharIndexable` | `getSearchTerm()` Get the search term.

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

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

- - ### Constructor Detail

    - #### FastCharSequenceSearch

          public FastCharSequenceSearch(@NotNull
                                        CharIndexable searchTerm)

      Constructor.
      Parameters:
        `searchTerm` - term to search for

    - #### FastCharSequenceSearch

          public FastCharSequenceSearch(@NotNull
                                        java.lang.String searchTerm)

      Convenience constructor.
      Parameters:
        `searchTerm` - search term

    - #### FastCharSequenceSearch

          public FastCharSequenceSearch(@NotNull
                                        char... searchTerm)

      Convenience constructor.
      Parameters:
        `searchTerm` - search term

  - ### Method Detail

    - #### getSearchTerm

          @NotNull
          public CharIndexable getSearchTerm()

      Get the search term.
      Returns:
        search term

    - #### findFirst

          public int findFirst(@NotNull
                               CharIndexable 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
                              CharIndexable 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
                              CharIndexable 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
                                                      CharIndexable data,
                                                      boolean allowOverlaps)

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