Git Product home page Git Product logo

trie's Introduction

Trie.js

My take on an efficient implementation of a Trie in Javascript

Short story

A Trie is a kind of digital search tree. (See [Knuth1972] for more details on digital search trees.)

[Fredkin1960] introduced the trie terminology, which is abbreviated from "Retrieval".

[Knuth1972] Knuth, D. E. The Art of Computer Programming Vol. 3, Sorting and Searching. Addison-Wesley. 1972.

[Fredkin1960] Fredkin, E. Trie Memory. Communication of the ACM. Vol. 3:9 (Sep 1960). pp. 490-499.

(source)

The trie implementation of Dennis Byrne served as a starting point and inspiration.

For more information, please take a look at the Wikipedia article

Usage

Please take a look at the file

  test/test.html

which pretty much explains the things you can do with Trie.js in code. The test.html file uses a pure JS dataset of 44.830 records, which you can find in

  data/people_44830.js

More information and full documentation of the API can be found in

  docs/index.html

Or read them online at https://mikedeboer.github.io/trie/.

License

MIT.

Amsterdam, 2010. Mike de Boer.

trie's People

Contributors

mikedeboer avatar

Stargazers

Yaroslav Serhieiev avatar Vitaly Zadorozhny avatar  avatar Antony Rafael avatar zlrs avatar Rubén Salvador García San Juan avatar GAURAV avatar weituotian avatar  avatar Spades avatar Kiagus Arief Adriansyah avatar Zhang Zhi avatar Jong Hyeon Yeo avatar Tom avatar Sergey Semushin avatar RYeah Sh avatar Matthew Voss avatar xcv58 avatar Adrian Kropp avatar Jeremy Sarda avatar fangxing avatar Nano Miratus avatar Marcus Vinicius Monteiro de Souza avatar strong avatar  avatar Toshiyuki Nakamura avatar Emmanuel Garcia avatar Tim Feuerbach avatar William Laffin avatar Cale Hoopes avatar Maximiliano Ruani avatar  avatar Sirko B avatar Josema avatar Eric Rovelli Lambart avatar Osman Hernandez avatar Tao PR avatar Najam avatar Nikos M. avatar Hugh Winkler avatar Ivan avatar Xav Laumonier avatar Lauri Lehmijoki avatar Roman Shterenzon avatar Stanley Ng avatar Yisha Wu avatar Sjoerd de Jong avatar Alix Axel avatar Pavlo Osadchyi avatar Dario Guarascio avatar Nick Desaulniers (paternity leave) avatar Abdulkadir N. A. avatar uplanning avatar Adams avatar rho avatar Daniel Blanco avatar Brian McCann avatar  avatar  avatar  avatar Mario Pietsch avatar Daniel Lopretto avatar  avatar Greg Weng avatar Ryan Tenney avatar Gabriel Reitz Giannattasio avatar Roderic Page avatar Mike Koss avatar Maxime Liron avatar Josh Nesbitt avatar Andrew Coldham avatar arden avatar Bruno Melo avatar

Watchers

Hugh Winkler avatar  avatar  avatar

trie's Issues

An string is not a prefix of itself

Hi, testing the example you provide with the implementation I found that when you type "aaron wall" in you "search for a contact" it says "No contact found" but there is a "aaron wall" in the list. Is this the desired behaviour? I though that any string is a prefix of itself.

getWords does not fully traverse tree

Had two words in the trie:

week
weekend

trie.getWords('wee') only returns 'week'

I hacked getWords, removed the else in the for loop and it works fine for me

for (; i < l; ++i) {
    if (c[i].wordCount)
        words.push(s + c[i].stem);
    else
        words = words.concat(c[i].getWords(s + c[i].stem));
}

changed to:

for (; i < l; ++i) {
    if (c[i].wordCount)
        words.push(s + c[i].stem);
    words = words.concat(c[i].getWords(s + c[i].stem));
}

`toJSON` should persist minimal data

Hi, This is in fact a very nice implementation thanks a lot !!!

However these is one major problem, if someone wants to store a giant list of words in the Trie, then reusing it is the real deal I guess (transferred over the wire for example).
thus, toJSON must to my opinion really output as minimal data as possible. the bet if possible is to have a model lighter than the array of strings in ascci.

I don't know what's meta associated with each token, if not necessary, omit that for instance.

Thanks anyway :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.