Dictionary Lookups in JavaScript
ejohn.org
ejohn.org
The only thing missing was converting the dictionary data into a trie. ;-)
When I benchmarked a Trie implementation using dicts of dicts in Python, and I found that the memory usage was an order of magnitude higher than just having a set or list of strings (2mb vs ~100kb), while the performance difference was negligible. I ended up going with a set.
The issue is that each layer per node has 26+ instances of your core object struct (whether it's a list or a dict), so any overhead gets ballooned really fast.
That stops the object overhead in python from killing memory.
But it's not the prettiest way to do things.
That's what I was thinking. I wonder what the memory and download footprint for that would be in practice. Considering characters are represented by string objects in JavaScript, it could get expensive, unless the runtime interns short strings. If not, you could represent single letters with integers, which are almost certainly interned or even use a non-pointer representation. All those objects at each tree level might be a bit much though.
Technically this is what his final solution converged on, it's just the least fancy "fancy structure" there is.
It's a last resort, certainly, but in certain cases it's the simplest answer. Be aware of encoding issues, though; UTF-8 technically can't carry arbitrary binaries and you may have to work around some things a bit.
https://github.com/mcarter/js.io/blob/master/packages/std/ba...
If you're writing this for client side, it would indeed be preferable to use the native functions.
Yeah... I didn't get that job.
Check out http://stackoverflow.com/questions/396005/word-anagram-hashi... for an example