Package: hat-trie
hat-trieHAT-Trie structure for Python (2.x and 3.x).This package is a Python wrapper forhat-trieC library.Installationpip install hat-trieUsageCreate a new trie:>>> from hat_trie import Trie
>>> trie = Trie()trievariable is a dict-like object that support unicode
keys and can have any Python object as a value. For keys that share prefixes
it usually uses less memory than Python dict.There is alsohat_trie.IntTriewhich only supports positive
integers as values. It can be more efficient when you don’t need
arbitrary objects as values. For example, if you need to store float
values then storing them in an array (either numpy or stdlib’sarray.array)
and using IntTrie values as indices could be more memory efficient
than storing Python float objects directly inhat_trie.Trie.Another way to store float values is to use hat_trie.FloatTrie().
In this case precision is limited to float32.Currently implemented methods are:__getitem__()__setitem__()__contains__()__len__()get()setdefault()keys()iterkeys()Other methods are not implemented - contributions are welcome!PerformancePerformance is measured forhat_trie.Trieagainst Python’s dict with
100k unique unicode words (English and Russian) as keys and ‘1’ numbers
as values.Benchmark results for Python 3.3 (intel i5 1.8GHz,
“1.000M ops/sec” == “1 000 000 operations per second”):dict __getitem__ (hits)      6.874M ops/sec
trie __getitem__ (hits)      3.754M ops/sec
dict __contains__ (hits)     7.035M ops/sec
trie __contains__ (hits)     3.772M ops/sec
dict __contains__ (misses)   5.356M ops/sec
trie __contains__ (misses)   3.364M ops/sec
dict __len__                 785958.286 ops/sec
trie __len__                 574164.704 ops/sec
dict __setitem__ (updates)   6.830M ops/sec
trie __setitem__ (updates)   3.472M ops/sec
dict __setitem__ (inserts)   6.774M ops/sec
trie __setitem__ (inserts)   2.460M ops/sec
dict setdefault (updates)    3.522M ops/sec
trie setdefault (updates)    2.680M ops/sec
dict setdefault (inserts)    4.062M ops/sec
trie setdefault (inserts)    1.866M ops/sec
dict keys()                  189.564 ops/sec
trie keys()                  16.067 ops/secHAT-Trie is about 1.5x faster thatdatrieon all supported operations;
it also supports fast inserts unlike datrie. On the other hand,
datrie has more features (e.g. better iteration support and richer API);
datrie is also more memory efficient.If you need a memory efficient data structure and don’t need inserts
thenmarisa-trieorDAWGshould work better.ContributingDevelopment happens at github:https://github.com/kmike/hat-trieFeel free to submit ideas, bugs, pull requests or regular patches.Please don’t commit changes to generated C files; I will rebuild them myself.Running tests and benchmarksMake suretoxis installed and run$ ./update_c.sh
$ toxfrom the source checkout. You will needCythonto do that.Tests should pass under python 2.7 and 3.3+.$ tox -c bench.iniruns benchmarks.Authors & ContributorsMikhail Korobov <kmike84@gmail.com>Brandon Forehand <b4hand@users.sf.net>https://github.com/yflauMichael Heilman <https://github.com/mheilman/>Michael Phan-Ba <michael@mikepb.com> @mikepbThis module wrapshat-trieC library by Daniel Jones & contributors.LicenseLicensed under MIT License.0.3 (2016-02-08)hat-trie C library is updated to the latest version (thanks Michael Phan-Ba);FloatTrie (thanks Michael Phan-Ba);Python 2.6 and Python 3.2 support is dropped. hat-trie 0.3 likely still works
in 2.6 and 3.2, but this is no longer checked by unit tests, and
future compatibility is not guaranteed;setup.py is switched to setuptools.0.2 (2014-08-22)Installation is simplified: Cython is no longer required;getmethod for tries (thanks Brandon Forehand);iterkeysmethod is fixed (thanks Brandon Forehand);hat_trie.Triecan store any Python object as a value (thanks Brandon Forehand);segfault is fixed for large int values (thanks Brandon Forehand);hat-trie C library is updated to the latest version to fix some issues
with 64bit builds and RHEL (thanks Brandon Forehand and Michael Heilman);0.1 (2014-03-27)Initial release.