I want to count the number of longest matched substring in a sequence. For example, typedef String<char> TSequence; typedef StringSet<TSequence> TStringSet TSequence haystack = "foo vino tinto bar"; StringSet<TSequence> needles; appendValue(needles, "vino"); appendValue(needles, "vino tinto"); Finder<TSequence> finder(haystack); Pattern<TStringSet, AhoCorasick> pattern(needles); unsigned occurrences = 0; while (find(finder, pattern)) occurrences ++; In this case, occurrences is 2, since "vino" and "vino tinto" both match the haystack. But I only want to count the occurrences of the longest matches - "vino tinto". I cannot remove the needle "vino" since I also want to match the haystack "foo vino bar".