4 ms·
> in fact, my algorithms knowledge is still rubbish, and I've never implemented a hash map, I just use tries If you need to write an associative data structure
by aidenn0 3y ago
> in fact, my algorithms knowledge is still rubbish, and I've never implemented a hash map, I just use tries
If you need to write an associative data structure, write a trie. There are too many pitfalls when implementing a hash-table. e.g. It's really hard to accidentally write a trie with linear lookup performance or quadratic space usage, but it's really easy to accidentally write a hash-table that does one of those.
A well implemented hash-table will beat a well-implemented trie for pretty much all unordered operations, but a quick and dirty trie will usually be far more robust to corner cases than a quick and dirty hash-table.