A Generalized Suffix Tree for any Python sequence, with Lowest Common Ancestor retrieval.
pip install suffix-tree
>>> from suffix_tree import Tree
>>> tree = Tree({"A": "xabxac"})
>>> tree.find("abx")
True
>>> tree.find("abc")
False
This suffix tree:
works with any Python sequence, not just strings, if the items are hashable,
is a generalized suffix tree for sets of sequences,
is implemented in pure Python,
builds the tree in time proportional to the length of the input,
does constant-time Lowest Common Ancestor retrieval.
Being implemented in Python this tree is not very fast nor memory efficient. The building of the tree takes time proportional to the length of the string of symbols. The query time is proportional to the length of the query string.
To get the best performance turn the python optimizer on: python -O.
Documentation: https://cceh.github.io/suffix-tree/
PyPi: https://pypi.org/project/suffix-tree/
Usage examples:
>>> from suffix_tree import Tree
>>> tree = Tree()
>>> tree.add(1, "xabxac")
>>> tree.add(2, "awyawxawxz")
>>> tree.find("abx")
True
>>> tree.find("awx")
True
>>> tree.find("abc")
False
>>> tree = Tree({"A": "xabxac", "B": "awyawxawxz"})
>>> tree.find_id("A", "abx")
True
>>> tree.find_id("B", "abx")
False
>>> tree.find_id("B", "awx")
True
>>> tree = Tree(
... {
... "A": "sandollar",
... "B": "sandlot",
... "C": "handler",
... "D": "grand",
... "E": "pantry",
... }
... )
>>> for k, length, path in tree.common_substrings():
... print(k, length, path)
...
2 4 s a n d
3 3 a n d
4 3 a n d
5 2 a n
>>> tree = Tree({"A": "xabxac", "B": "awyawxawxz"})
>>> for C, path in sorted(tree.maximal_repeats()):
... print(C, path)
...
1 a w
1 a w x
2 a
2 x
2 x a
Metadata
Release files for suffix-tree 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| suffix_tree-0.1.2.tar.gz | 686.0 kB | Without provenance | Details for suffix_tree-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| suffix_tree-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for suffix_tree-0.1.2-py3-none-any.whl |
Total release size: 718.6 kB
Release files / suffix_tree-0.1.2.tar.gz
| Download URL | suffix_tree-0.1.2.tar.gz |
|---|---|
| Size | 686.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5a927d205956c0161ed4fc90959e55326f67bccea1291fa476b408f347d92ef
|
|
BLAKE2b-256 checksum How to use checksums |
32eb932d92d37e56629d1a9fb5126cd07d3bdc5166a6ea654fb06d4e83961c93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / suffix_tree-0.1.2-py3-none-any.whl
| Download URL | suffix_tree-0.1.2-py3-none-any.whl |
|---|---|
| Size | 32.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7f01f9bf16f88eed830d6be97b3448648c48ea763cf0092a1f29dccd2b13862
|
|
BLAKE2b-256 checksum How to use checksums |
a6b08f6adff523678f5cf23da20f6b3a00727c97287dca39746f2ffdb4ef1b06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for suffix-tree 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.