prefixtree
This package provides PrefixDict, a dictionary like object, and PrefixSet, set like object, that are implemented using using prefix trees, or tries. Using tries provides the following unique features when compared to the builtin dict and set objects.
Keys are returned in sorted order.
Slice operations for getting, setting and deleting values.
Trie based collections are useful when ordered access to key and values is a requirement.
Usage
PrefixDict and PrefixSet behave like the builtin dict and set objects. They are implementations of the MutableMapping and MutableSet abstract base classes. They also support the same constructors as the builtins.
>>> from prefixtree import PrefixDict >>> pd = PrefixDict(a=0, b=1) >>> pd['c'] = 2 >>> 'a' in pd True >>> 'd' in pd False
The only incompatible API difference between prefixtree collections and the builtins is that PrefixDict and PrefixSet only support strings as keys. Unicode strings will be encoded to byte strings before and after use.
Unlike the bultins, it’s possible to use slices when getting, setting and deleting values from prefixtree collecionts.
>>> list(pd['a':'c']) [0, 1, 2] >>> pd[:'b'] = [4, 3] >>> list(pd['a':'c':-1]) [2, 3, 4]
PrefixDict also has additional methods not present on builtin dicts.
commonprefix(key), to find the longest comment prefix with current keys.
startswith(prefix), iterates over current keys with matching prefix.
Refer to the full prefixtree documentation on Read The Docs for details.
Compatability
prefixtree is implemented to be compatible with Python 2.x and Python 3.x. It has been tested against the following Python implementations:
CPython 2.6
CPython 2.7
CPython 3.2
PyPy 1.9.0
Continuous integration testing is provided by Travis CI.
Issues
Source code for prefixtree is hosted on GitHub. Any bug reports or feature requests can be made using GitHub’s issues system.
Further Reading
Full documentation for prefixtree is hosted by Read The Docs.
Metadata
Release files for prefixtree 0.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 |
|---|---|---|---|---|
| prefixtree-0.2.tar.gz | 580.0 kB | Without provenance | Details for prefixtree-0.2.tar.gz |
Release files / prefixtree-0.2.tar.gz
| Download URL | prefixtree-0.2.tar.gz |
|---|---|
| Size | 580.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c012520d21dd39685cc13f11461d42a32b67d18ba80fccaac8252cc2d22e283
|
|
BLAKE2b-256 checksum How to use checksums |
28c090789ffd3fef08972f28ab385ee16a59c30bb08e212bb2c5c16a04d33ff6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for prefixtree 0.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.