A trie is a data structure that enables very fast lookups, while taking up quite a small amount of space. Here's an implementation in Rust:
use ...
For further actions, you may consider blocking this person and/or reporting abuse
Nice example, Tim! I personally love tries, possibly because a trie was the first "cool" datastructure I got to apply to a real job.
I tried this myself, with a different
main()function that includes thewordsandcracklib-smallword files from my Ubuntu install. These are ~1MB and ~500KB respectively, and whilewordscontains only English words,cracklib-smallcontains many non-English tokens likezlzfrhand omits many real words.This program uses your
Trieimplementation to check how many of thecracklib-smalltokens are in the Englishwordsfile. (It's about 75%.)I ran this through
hyperfine, a really excellent Rust benchmarking program, and on my T480, the defaultHashMapimplementation takes about 92.7 ms to insert and check all 1.5MB of data, while theFxHashMapimplementation only takes about 70.5 ms.Neat stuff, thank you for sharing!