https://github.com/dobatymo/hat-trie-python
Python wrapper for https://github.com/Tessil/hat-trie
https://github.com/dobatymo/hat-trie-python
data-structures hat-trie python
Last synced: 7 months ago
JSON representation
Python wrapper for https://github.com/Tessil/hat-trie
- Host: GitHub
- URL: https://github.com/dobatymo/hat-trie-python
- Owner: Dobatymo
- License: mit
- Created: 2018-07-31T02:24:13.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-06T08:46:07.000Z (almost 4 years ago)
- Last Synced: 2025-02-26T00:21:43.718Z (8 months ago)
- Topics: data-structures, hat-trie, python
- Language: Cython
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hat-trie-python
Python wrapper for https://github.com/Tessil/hat-trie (MIT License)
It's still incomplete, not all functionality is supported. Sets are not implemented yet.
Tested on Linux 2.7+, Windows 3.5+, MacOS 2.7+. It should work on Windows 2.7 also, however it's tricky to compile.## Install
- `pip install hat-trie-python` (requires Cython and a C++11 compiler)
## Example usage:
```
from hattrie import HatTrieMap
htm = HatTrieMap()
htm[b"/foo"] = b"1"
htm[b"/foo/bar"] = b"2"
print(list(htm.longest_prefix(b"/foo"))) # returns [(b'/foo', b'1')]
print(list(htm.longest_prefix(b"/foo/baz"))) # returns [(b'/foo', b'1')]
print(list(htm.longest_prefix(b"/foo/bar/baz"))) # returns [(b'/foo/bar', b'2'), (b'/foo', b'1')]
print(list(htm.longest_prefix(b"/foo/bar/"))) # returns [(b'/foo/bar', b'2'), (b'/foo', b'1')]
print(list(htm.longest_prefix(b"/bar"))) # returns []
print(list(htm.longest_prefix(b""))) # returns []
```Any Python object is supported as value, however only bytes are supported as keys.