A C implemented Suffix Tree package
Project description
Introduction
This is a Suffix Tree data structure lib implemented in C++, wrapped with python.
Expect for contructing the tree, this lib also provides to construct the query tree for speeding up querying strings.
Install and Build
Install from Pypi
run pip install csuffixtree
Build
You can build this either on linux or windows.
Install Python Package
- Build SuffixTreePyBinding solution in Windows
- On linux you should go to
linux
directory, and runmake python
- under SuffixTreePy directory. run
python setup.py install
How to use
You can construct a suffix tree in the following way.
from suffixtree import *
tree = SuffixTree(True,["abc","123","321"])
tree.addStrings(["xyz","abcd"])
print(tree.findString("1"))
print(tree.findString("a"))
If you finished inserting strings to a suffix tree, and you want the querying be very fast you can do:
# convert tree to query tree, this release a part of memory
qtree = tree.createQueryTree()
qtree.cacheNodes() # take some time to cache intermediate nodes
qtree.findString("a")
For simplicity you can also write
# do not preserve string
qtree = SuffixQueryTree(False,["abc","abcd","123","321"])
idx = qtree.findStringIdx("abc") # you cannot use findString now
print(idx)
Serialization
SuffixQueryTree can be serialized and deserialized to/from a file a bytes object. For example:
# do not preserve string
qtree = SuffixQueryTree(False,["abc","abcd","123","321"])
idx = qtree.findStringIdx("abc") # you cannot use findString now
print(idx)
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
csuffixtree-0.3.0.tar.gz
(7.1 kB
view hashes)
Built Distribution
csuffixtree-0.3.0-py3-none-any.whl
(121.6 kB
view hashes)
Close
Hashes for csuffixtree-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ada49ddbae2d6cfc89c812b7baa46480bb1b37c80e4772bc6edb22b9056bc10 |
|
MD5 | cce86112820bbab99f0222a9b6932420 |
|
BLAKE2b-256 | 6c8ff6f6eeb87bb37cc6827b46d78782f0b67acc831b8a0355954d53eb0a85d8 |