/KMP_Tool

A string matching tool based on KMP algorithm (Knuth-Morris-Pratt Algorithm)

Primary LanguageC++GNU General Public License v2.0GPL-2.0

KMPTool

A string matching tool based on KMP algorithm (Knuth-Morris-Pratt Algorithm). I wrote it in a pure C style, it is both okay for GCC and G++.

Code Example

Alt text

You should declare a KMPRes first, then call malKMPRes(KMPRes * res) to initialize it since it need so memory from heap. You can get the matched position in KMPRes.matchPos and the length of KMPRes.matchPos in KMPRes.matchCount. Don't forget to call delKMPRes(KMPRes * res) to recycle the heap memory.

Alt text

The output of the code example.

Motivation

Sometimes, I need the functionarity above but there is not such function in standard library, so I wrote it and review KMP by the way.

API Reference

Alt text

The function declared in kmptool.h