Home

Awesome

Trie

Trie tree implementation in Java

Build Status Coverage Status

Setup

Add the module to your project:

<dependency>
  <groupId>io.jmnarloch</groupId>
  <artifactId>trie</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Features

Trie

The Trie is a R way tree that is designed for efficient string searches.

At this moment this component defines four different implementation of the Trie, all of which differs slightly in performance, but far most with the memory consumption.

The available Trie implementations are:

Ternary Trie Tree

In effort to minimize the memory consumption we can design our tree as a 3-way tree with node links corresponding to character being lower, equal or greater then character within given node.

The available implementation:

Benchmark

Project includes simple JMH benchmark that measures the throughput of selected operations on the data structures. For the sake of the benchmark every Trie instance has been populated with 1024 unique entries. The benchmark measures the throughput of retrieving a key value and inserting a new one.

Data structureput() (ops/sec)get() (ops/sec)
Tst2299545,30810051031,796
ArrayTrie3420565,5376006965,043
HashMapTrie1934020,7192256343,001
TroveCharHashMapTrie1455906,5201823093,485
KolobokeCharHashMapTrie1824541,5773263378,461

Memory footprint

Tested on 64 bit JVM with enabled pointer compression (-XX:+UseCompressedOops - which is enabled by default for Java 8) Measured using JAMM. The memory size includes the object overhead and padding.

Size of single tree node

Data structureMemory (bytes)
Tst56
ArrayTrie - Unicode262184
ArrayTrie - Extended ASCII1064
ArrayTrie - ASCII552
HashMapTrie72*
TroveCharHashMapTrie320
KolobokeCharHashMapTrie376

After populating the Trie trees with 1024 random 36 character length strings we may expect fallowing results:

Data structureMemory (bytes)
Tst1553584
ArrayTrie - Unicode-
ArrayTrie - Extended ASCII37300464
ArrayTrie - ASCII19406576
HashMapTrie6464752
TroveCharHashMapTrie11301264
KolobokeCharHashMapTrie6826752

TODO

License

Apache 2.0