Triejs Customizable Trie Data Structure in Javascript

Examples

A simple example is an autocomplete for name detection, like U.S. State names. This can be achieved very simply through the basic implementation of Triejs. With no options passed the trie will default to a simple trie with string data. You can simply add new words using the add function and passing in the name. Likewise, calling find with a partial beginning will return an array of possible full words meeting the desired prefix criteria. This list is limited to 10 words in alphabetic order.

When you start dealing with more complicated data sets, Triejs can grow with you. Passing custom functions into the initialization object for a trie will let you do things like sort a data set on custom parameters like population.

You can use Triejs to enhance an existing data model. Easily plug in Backbone.js models by binding to a collections add events. Then store the ids or cids for referencing later during a find. In this example, we fake new models being added to a collection from a backend service, represented by the green models.

Performance Tests

Web Workers

Choose a performance test to see the results run right in your browser.

Note: Tests will run faster in newer browsers with web workers enabled. Larger dictionary sizes may stall older browsers due to memory consumption.