Closed thomasa299792 closed 3 years ago
StringSearchAlgorithms is about efficient matching of strings. Especially it can find strings in InputStreams
or Readers
. And InputStreams/Readers
can only be traversed in one direction (forwards) efficiently.
Adding a feature Backwards Search would be technically limited to the search in strings - so we could not provide this feature in the already existing StringFinder
class.
Besides I am quite sceptical about the benefit of allwoing findNext()
and findPrevious()
simultaneously: If applied on a forward search calling findPrevious
means that I search an already found match. Just storing the matches in a list and return the last stored stringmatch would be far more efficient than searching backwards.
If you just want to search backwards through a string efficiently:
Search using a new ReverseCharProvider(new StringCharProvider("hay needle hay", 14))
with the reverted search word (´"eldeen" instead of needle
).
Consider supporting the very common need of searching backwards in a string.
For example, consider adding a method
findPrevious()
as a sibling to StringFinder.findNext().