Skip to content

Yay295/Compiled-Trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Compiled Trie

This function takes a start index and a list of keys, and returns a function capable of determining if one of those keys is at the given index into some string. The compiled function takes the string to check and returns the length of the found key.

I have created a jsPerf at https://jsperf.com/object-vs-compiled-trie. My new code is about three times faster than what I was using before (creating slices and checking against an object).

To-Do

This is a list of things I think could be done. Don't plan on me doing them any time soon (or ever).

  1. Speed up compilation. Currently it uses recursion because it was easier to write, but I think it could be written iteratively.
  2. Simplify the generated function. Currently it uses mostly switches, and it puts a break on every case. However, some of the cases have the same code inside them, so it could be optimized to fall-through in some places. I think this could be done either before the code is generated by optimizing the trie (and then handling those optimizations when generating the code), or while the code is being created by comparing the generated strings. I don't know which would be easier, but the second is probably slower. If a switch was optimized down to only one case body (not including a default), it could even be turned into an if statement. Since if statements are used when there's only one option, it sometimes generates nested if statements. These could be combined fairly easily, though I don't think it would actually affect performance much.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published