A module that provides KMP-based search for strings and bytes.
Project description
kmp_util is a Python C extension module that provides efficient substring search functionality using the Knuth-Morris-Pratt (KMP) algorithm. It supports searching for patterns in both byte sequences and Unicode strings.
Features
``find_bytes``: Searches for a byte pattern in a byte sequence.
``find_str``: Searches for a substring in a Unicode string. Fully supports UTF-8 and Unicode characters.
Both functions return the starting index of the first occurrence of the pattern in the text, or -1 if the pattern is not found.
Installation
To install the module, run the following commands:
python setup.py build
python setup.py install
Example Usage
import kmp_util
# Example 1: Using find_bytes to search in a byte sequence
result = kmp_util.find_bytes(b'111', b'2')
print(result) # Output: -1 (pattern not found)
# Example 2: Using find_str to search in a Unicode string
result = kmp_util.find_str('abc中文', '文')
print(result) # Output: 4 (pattern found at index 4)
Functions
find_bytes(text: bytes, pattern: bytes) -> int
Searches for the first occurrence of the byte pattern in the byte sequence.
Parameters:
text (bytes): The byte sequence to search in.
pattern (bytes): The byte pattern to search for.
Returns:
The starting index of the first occurrence of the pattern in the text, or -1 if the pattern is not found.
find_str(text: str, pattern: str) -> int
Searches for the first occurrence of the substring in the Unicode string.
Parameters:
text (str): The Unicode string to search in.
pattern (str): The substring to search for.
Returns:
The starting index of the first occurrence of the pattern in the text, or -1 if the pattern is not found.
Notes
find_bytes operates on raw byte sequences (bytes in Python).
find_str operates on Unicode strings (str in Python) and fully supports UTF-8 encoded characters.
License
This module is open-source and available under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kmp_util-1.0.1.tar.gz.
File metadata
- Download URL: kmp_util-1.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3b05e40b29c362d617a0309a848430bb50d5104e519e88317ff63bdd73addb1
|
|
| MD5 |
7df92f58e610f44a0e51f8459a3d5201
|
|
| BLAKE2b-256 |
53de7f5562a3e9a6099c0e10d224cdd119b799f8815ce9747800cb8926bc3ca1
|
File details
Details for the file kmp_util-1.0.1-pp311-pypy311_pp73-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-pp311-pypy311_pp73-win_amd64.whl
- Upload date:
- Size: 7.7 kB
- Tags: PyPy, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8febaf63ee55688c0abf46b088d32a9b3fa6b780a206749b115819ceb23384eb
|
|
| MD5 |
baf7b693c287d3087614066c1322b67a
|
|
| BLAKE2b-256 |
dd4d8ae6b83528545dfd86583bfcf37a622e60335a533a8a468b5f7d8403e494
|
File details
Details for the file kmp_util-1.0.1-pp310-pypy310_pp73-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-pp310-pypy310_pp73-win_amd64.whl
- Upload date:
- Size: 7.7 kB
- Tags: PyPy, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb4bf68ccf8f947c129403548c595b1c0b9ae8183f125e95b0067078016e615
|
|
| MD5 |
807f51a8c78529a65e6547b8e6584fa1
|
|
| BLAKE2b-256 |
94bd9ef0a2317790fb6d340212ef53ef5dda999174142713670292cfcb346d9a
|
File details
Details for the file kmp_util-1.0.1-pp38-pypy38_pp73-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-pp38-pypy38_pp73-win_amd64.whl
- Upload date:
- Size: 8.1 kB
- Tags: PyPy, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d73cbb245d8cec775a6c498871653aae672f39fb4d6ec8a515dc9fedc1d83e0e
|
|
| MD5 |
d4c6d3d67e391b34a6ffe720902f3c38
|
|
| BLAKE2b-256 |
c0e4791392a91446bfd556e12e3fa14d82d03f7df1081b3d82d027354ca5869c
|
File details
Details for the file kmp_util-1.0.1-graalpy311-graalpy241_311_native-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-graalpy311-graalpy241_311_native-win_amd64.whl
- Upload date:
- Size: 8.1 kB
- Tags: Windows x86-64, graalpy311
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
733a5427065426fe44ee19146192e227c6646227922d8edf2bef20fe4470237a
|
|
| MD5 |
28f334bed10119ff8a468d056c5e4ed6
|
|
| BLAKE2b-256 |
58c3559d19893e610b1a282a2b4fb2a32b78840a822c0945ae1f0f1bf11c788d
|
File details
Details for the file kmp_util-1.0.1-cp314-cp314t-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp314-cp314t-win_amd64.whl
- Upload date:
- Size: 7.7 kB
- Tags: CPython 3.14t, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
033ac05fec2f731c7456f3a4c5725685a7f2f1f581cc41ac5445a792a41524ba
|
|
| MD5 |
0b58deb55cad58ab051a778758890037
|
|
| BLAKE2b-256 |
1c635681964c54b9c2d758b85a358ea32404e66fb481ee71e30566ced9c0ebfd
|
File details
Details for the file kmp_util-1.0.1-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 7.7 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f579957e67482e042be613ecfb3d622b4d2528758c05f1ebd24a09ad3bcbaeb4
|
|
| MD5 |
8ed9caedf6672c6da47413a91c2d9531
|
|
| BLAKE2b-256 |
a221a49ccd1ca295f67206016fc9de0b4ecf5d9e291e72ca768ff044a57f8565
|
File details
Details for the file kmp_util-1.0.1-cp314-cp314-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp314-cp314-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.14, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd0e78a1ceec3cad4c96319a3f1f661a185d76f9882bdc4fa2d7b0dc22a3c301
|
|
| MD5 |
e4e144755cea6ec9a5dcb3d38bcfd984
|
|
| BLAKE2b-256 |
3ab55611f5256a4e8f10b2c19c0e41ddd66d1ceb392635250dee18eedaad5234
|
File details
Details for the file kmp_util-1.0.1-cp313-cp313t-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp313-cp313t-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.13t, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3505cfc99033c9141ccdd9586ea3faf27d64bdaf7f38fa5b31bf43e21f13113
|
|
| MD5 |
af8262d3564512ea5f528956de003e5f
|
|
| BLAKE2b-256 |
d733f45a8e33870dae867cdeba21f92255f921b9e6d8366206a8864bb32a87fc
|
File details
Details for the file kmp_util-1.0.1-cp313-cp313t-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp313-cp313t-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.13t, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
810b31908cd453c8d34420dfebd8a46a71fc2621cbc02ea3862869a1f5f47e07
|
|
| MD5 |
d10a9a3fd01f1299754c78d889a12f2d
|
|
| BLAKE2b-256 |
53b365900a9c5a39a3d25ac19ac759e86f8cd671d92c2d9a9e27f2ab8007492b
|
File details
Details for the file kmp_util-1.0.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7de3ae4ec615e59e6605f347bec59b6454cb8a2ff6bcefd01cc7423fad6a96f
|
|
| MD5 |
1902e5d06134de4f2a3ec9872d60c68c
|
|
| BLAKE2b-256 |
dc2ed0dd6c449312c3afc5d5b0e90ae0e3f9ef8d0c029f243a6edc7ce5afc551
|
File details
Details for the file kmp_util-1.0.1-cp313-cp313-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp313-cp313-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.13, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21d8e43b401493930ded1ff638fbe1a0c1cc633f1a08456e91af95519372f225
|
|
| MD5 |
4a38ade7ec0b397336930b2445b901be
|
|
| BLAKE2b-256 |
7f67cb9ae060cf5f61cf122c89270ae3f8aacb5685c1e459e7de425647fab7af
|
File details
Details for the file kmp_util-1.0.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53707c8eed27ac66dabf804b75fb7c5c07633520993ae75bd48e0e188d2fb43e
|
|
| MD5 |
e649f171cb0fb0bacc3959ad73edc200
|
|
| BLAKE2b-256 |
3bc769fee6e7afb7c78aaaedeaa6fbf5f3ae27f7e42db02ee08d491cde5b7190
|
File details
Details for the file kmp_util-1.0.1-cp312-cp312-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp312-cp312-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.12, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fca545493f3666ef01b361ab6018d0be0c25988e9478ce4179cda945e7cc14d7
|
|
| MD5 |
34c38354ad48ffa01a25f460998e316c
|
|
| BLAKE2b-256 |
7ab6a4d9556cfc9046d2da5a2b7897c1c1fa8c631339d51b9dd6c2b9ad4825c2
|
File details
Details for the file kmp_util-1.0.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b1a55eb23957aa08803cd807c701d908c7c5e49fd6e12a886ec3fdfd8af3210
|
|
| MD5 |
1839390e4c702c18fc48b1d278889a95
|
|
| BLAKE2b-256 |
40ac12a03432c2cec7706ff5e8ec155902a9ecb766b26f2e236ae366e81df557
|
File details
Details for the file kmp_util-1.0.1-cp311-cp311-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp311-cp311-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
800b93d5fec1aac7a1eb2d620d80e899925dd94c990829f131fd52bf1402934d
|
|
| MD5 |
e7420dee2f9369fcdccfae54959ad40e
|
|
| BLAKE2b-256 |
5bd3b335dc6725d893136caa3bee2cb51bcd580bd7c6b657113d023e4015671a
|
File details
Details for the file kmp_util-1.0.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 8.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f96250d630558c028c15fc3fe4db895f99bbbefc0707dd46715711cfd3d443d8
|
|
| MD5 |
a315211ee43d83f8c421c80cf2d1bfb4
|
|
| BLAKE2b-256 |
8e67a40c4bae942db05736cc6ff36d4e2b43470a8c1c7ee0c4720488752f071a
|
File details
Details for the file kmp_util-1.0.1-cp310-cp310-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp310-cp310-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39a14b2749e791755376a7c3036d5c70655089d681f7f51e98a3b57745e48738
|
|
| MD5 |
e80af1d2c44177872766c0499f78060a
|
|
| BLAKE2b-256 |
fd55e712874bb71d441bcde84d1b81c667ae5456620da8a132df726e36eafa37
|
File details
Details for the file kmp_util-1.0.1-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
451df85ef295e1c4348551b04dffb88e3f8f1209986d3b1f5070b18e1300a882
|
|
| MD5 |
0e4cf526fe79d4143abb643337b5427c
|
|
| BLAKE2b-256 |
0656d30558883f393cae7b015e039ecc5e36cd01cbad5e64d1bfaeb7a6041df5
|
File details
Details for the file kmp_util-1.0.1-cp39-cp39-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp39-cp39-win32.whl
- Upload date:
- Size: 7.1 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14053993b1e8ef5dc105e6e7a1cd0964ac1ca8c8ee5318f9bb3b92985aed2aed
|
|
| MD5 |
f66d2b47a01d5cd1bf119e6aea0ac2b5
|
|
| BLAKE2b-256 |
e3fcc4ff0cc9aa7759089a34290cd50628643f9752612f7f8cbbc55f6a0f4c92
|
File details
Details for the file kmp_util-1.0.1-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
516498608784cebbdeb4c61e9281b6a0cfa632fd77b26ae90e5b9427427818b9
|
|
| MD5 |
d0ce5e88ca455903d68c51e08c878072
|
|
| BLAKE2b-256 |
a95b470dc8e4e2697a3e39b1c6e2ffd8784faca6a2e563f68df0362ac3fe978c
|
File details
Details for the file kmp_util-1.0.1-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 7.6 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23e0659e15cfe0d9a99b4eead7c4a87a7337eba16e905afb2d31d405c9df533e
|
|
| MD5 |
24c9d0f2c6016ddb04e3852f802bdbbb
|
|
| BLAKE2b-256 |
32d0ed77eeeed02b2ab17ab5da2b2b82ce957f0e6b73c526d4d79206d1219596
|
File details
Details for the file kmp_util-1.0.1-cp37-cp37m-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp37-cp37m-win32.whl
- Upload date:
- Size: 7.0 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
947ebc48981b90f472876fd2506f0302ad515b990b8971984e1d45dd56da7896
|
|
| MD5 |
08ef2e224f24371e4a6c19c32674bfcd
|
|
| BLAKE2b-256 |
9969ed4c8b0c5de970bf4c27e35237c0e616320db0c1105be572d32b75f54720
|
File details
Details for the file kmp_util-1.0.1-cp36-cp36m-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 8.0 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1a10d6fd6827e49b43a23cb6cd87b2bf20c3ed62e841823df48397653d650eb
|
|
| MD5 |
0384f161ad02b9278ce6d2f7af958266
|
|
| BLAKE2b-256 |
89e8a4f0be6bf53af95dd9f341b53e85a0a517a3bcb1391c494f0bb80122571f
|
File details
Details for the file kmp_util-1.0.1-cp36-cp36m-win32.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 10.8 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62b8bd35422c2d2a201ea443ec11766bc9133442ee7bb60ae39bca9205867349
|
|
| MD5 |
5334184188f22db07acfac4fa4dae781
|
|
| BLAKE2b-256 |
30b2176181cca64ff02129cf133a3d9e294608f7bafc38bcc59167f226f9bf31
|
File details
Details for the file kmp_util-1.0.1-cp35-cp35m-win_amd64.whl.
File metadata
- Download URL: kmp_util-1.0.1-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 8.0 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d4401a7b42622ab003e421c872ae63747d3b02a282fdcd7493f8920b91db21f
|
|
| MD5 |
8e43b971523e580f00a5c461e31b7f01
|
|
| BLAKE2b-256 |
97469971bb8f10d2bc9c1ea2726c57d56682d632bf896d0ab89c704620243ead
|