A silly one.
Regex with range subtraction (all characters '!' to 'z' are accepted, except -/= and \), also checks for length.
So that regex is compiled only once, we construct it lazily.
Then we pick the shorter of the two strings, get all the overlapping windows into it, and colleсt them into a HashSet for uniqueness.
Then we use an Aho-Corasick automaton with all of these substrings to match on them simultaneously in one pass.
However, if you think about it, the same thing can be written without dependencies/nightly features
This trades CPU for memory, for instance:
Rust
Look at it go!
A silly one.
Regex with range subtraction (all characters
'!'
to'z'
are accepted, except-
/
=
and\
), also checks for length.So that regex is compiled only once, we construct it lazily.
Then we pick the shorter of the two strings, get all the overlapping windows into it, and colleсt them into a
HashSet
for uniqueness.Then we use an Aho-Corasick automaton with all of these substrings to match on them simultaneously in one pass.
However, if you think about it, the same thing can be written without dependencies/nightly features
This trades CPU for memory, for instance:
Look at it go!