1.1.3 • Published 9 years ago

trie-array v1.1.3

Weekly downloads
3
License
GPL
Repository
github
Last release
9 years ago

trie-array

Simple and fast implementation of a trie, https://en.wikipedia.org/wiki/Trie. Using it you keep your collection sorted by key and indexed as in array.

To install:

npm install trie-array

To use in coffee script:

trieFactory = require "./index.coffee"
trie = trieFactory (obj) ->
  key = obj.word.toUpperCase()

for word, index in ['A','character','is','that','of','a','typical','hero']
  trie.add {word,index}

trie.add elem = { word: "IS", status: "transient" }

trie.findByKey 'IS'
## finds all objects with key 'IS'
## -> {"pos":4,"res":[{"word":"is","index":2},{"word":"IS","status":"transient"}]}

trie.del elem

trie.getNth 3
## gets the 3rd element in 'key' order
## -> {"word":"hero","index":7}

trie.getAt 4, 2
## gets 2 elements starting at position 4
## -> [{"word":"is","index":2},{"word":"of","index":4}]
1.1.3

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago