kmp.cpp 487 B

123456789101112131415161718192021
  1. #include "kmp.h"
  2. #include <util/generic/yexception.h>
  3. TKMPMatcher::TKMPMatcher(const char* patternBegin, const char* patternEnd)
  4. : Pattern(patternBegin, patternEnd)
  5. {
  6. ComputePrefixFunction();
  7. }
  8. TKMPMatcher::TKMPMatcher(const TString& pattern)
  9. : Pattern(pattern)
  10. {
  11. ComputePrefixFunction();
  12. }
  13. void TKMPMatcher::ComputePrefixFunction() {
  14. ssize_t* pf;
  15. ::ComputePrefixFunction(Pattern.data(), Pattern.data() + Pattern.size(), &pf);
  16. PrefixFunction.Reset(pf);
  17. }