Hash trie
Introduction
Hash trie is an enhanced Trie data structure stores keyword indexes for faster keyword lookup. The storage is done in such a way that it does efficient memory usage and faster lookup.
Usage
Importing and instantiating
from pyhtrie.htrie import Trie
trie = Trie()
Indexing
Syntax : trie.index_text(
data,keyword_to_index)
data: Data can be any data to indexkeyword_to_index: Keyword associated with thedataindexed
trie.index_text('car','car')
trie.index_text('cat','cat')
trie.index_text('cast','cast')
trie.index_text('Batman', 'batman')
trie.index_text('Bash', 'bash')
Prefix match
Syntax : trie.prefix_match(
prefix_text_to_search)
The function returns all data matching the prefix text
prefix_text_to_search: Will be the prefix text on which the search will be performed. If there are no nodes matching the route of the prefix text then it will return an empty array
trie.prefix_match('ca')
Pattern match
Syntax : trie.pattern_match(
pattern_text_to_search)
This function returns all data associated with the text pattern. When compared to the prefix_match function, this function need not necessarily require the pattern_text_to_search to match with the prefix of the keyword to be searched for. The pattern_text_to_search can appear anywhere within the keyword
pattern_text_to_search: Is the text pattern to be searched.
trie.pattern_match('at')
Storage details
The keywords to be indexed are stored in a Trie data structure as can be seen in the image below. However for faster indexing of pattern match within keywords, each node in the trie is added to the hash-map with the letter corresponding to the node being the key.
So if you need to search for any words beginning with 'ca', then prefix_match('ca') will return [cat, car, cast] as in a regular trie. However, if you want to search for any words with 'at' in them, you can use the function pattern_match('as') that will return [cat, batman]. The prefix match is done with the help of the hash-map. When a prefix match of 'at' is done, the hash-map is checked for the letter 'a' in 'at'. This returns a list of three a nodes [a,a,a] each pointing to a correspinding 'a' node in the tries as shown in the figure above. Then each of them are traversed to see which of them have the next node as 't' of 'at'. The result will be the 't' of 'cat' and the 't' preceding 'm' in 'batman'. Then the algorithm performs a collection operation from each of these 't's returned to retrieve keywords stored under those t's. The result, as can be inferred from the figure above, will be [cat, batman]
Metadata
Release files for pyhtrie 1.0.0
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 |
|---|---|---|---|---|
| pyhtrie-1.0.0.tar.gz | 2.8 kB | Without provenance | Details for pyhtrie-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyhtrie-1.0.0-py2-none-any.whl | Python 2 | none | any | Details for pyhtrie-1.0.0-py2-none-any.whl |
Total release size: 7.1 kB
Release files / pyhtrie-1.0.0.tar.gz
| Download URL | pyhtrie-1.0.0.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b848df369f3a8be380b478ccd9c535bb22ada67a084ce6b704b3cd45fbc152a9
|
|
BLAKE2b-256 checksum How to use checksums |
05d73343fd865ca866b9fc5195c84bbd92e41070a2af4dad5efea392a091896e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/2.7.15
|
Release files / pyhtrie-1.0.0-py2-none-any.whl
| Download URL | pyhtrie-1.0.0-py2-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
490b0b634d978b408e088db90af23cda8af3af03aae8d84eb4060791f8e4f248
|
|
BLAKE2b-256 checksum How to use checksums |
cfd01b085697e7f5bbc81908b2a9ed6326f06ab5f1c0391f9742dcc0aeba7735
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/2.7.15
|
Security for pyhtrie 1.0.0
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.