Why are hash maps better than trie maps?

前端 未结 2 949

By trie map I mean an associative array, where the payloads are stored in a trie instead of a hash table.

When I\'m using a hash map/table, the keys I use are typica

相关标签:
2条回答
  • 2020-12-19 10:14

    Hash maps are more common than trie maps because they are more generic: they can be made to work on any object that is hashable, while a trie works on sequences. Hash tables also have better locality of reference in common implementations because they store elements close together.

    (Strictly speaking, every object is a sequence of bits, but then a generic trie would require the user to serialize their object before storing it in the trie. That's pretty inconvenient compared to defining custom hash functions.)

    0 讨论(0)
  • 2020-12-19 10:15

    Just in case you are a Scala programmer, TrieMap is a "concurrent thread-safe lock-free implementation of a hash array mapped trie". There's none in Java standard lib this moment.

    0 讨论(0)
提交回复
热议问题