A hash array mapped trie[1] (HAMT, /ˈhæmt/) is an implementation of an associative array that combines the characteristics of a hash table and an array mapped trie.[1] It is a refined version of the more general notion of a hash tree.

Operation

edit

A HAMT is an array mapped trie where the keys are first hashed to ensure an even distribution of keys and a constant key length.

In a typical implementation of HAMT's array mapped trie, each node contains a table with some fixed number N of slots with each slot containing either a nil pointer or a pointer to another node. N is commonly 32. As allocating space for N pointers for each node would be expensive, each node instead contains a bitmap which is N bits long where each bit indicates the presence of a non-nil pointer. This is followed by an array of pointers equal in length to the number of ones in the bitmap (its Hamming weight).

Advantages of HAMTs

edit

The hash array mapped trie achieves almost hash table-like speed while using memory much more economically.[citation needed] Also, a hash table may have to be periodically resized, an expensive operation, whereas HAMTs grow dynamically. Generally, HAMT performance is improved by a larger root table with some multiple of N slots; some HAMT variants allow the root to grow lazily[1] with negligible impact on performance.

Implementation details

edit

Implementation of a HAMT involves the use of the population count function, which counts the number of ones in the binary representation of a number. This operation is available in many instruction set architectures, but it is available in only some high-level languages. Although population count can be implemented in software in O(1) time using a series of shift and add instructions, doing so may perform the operation an order of magnitude slower.[citation needed]

Implementations

edit

The programming languages Clojure,[2] Scala, and Frege[3] use a persistent variant of hash array mapped tries for their native hash map type. The Haskell library "unordered-containers" uses the same to implement persistent map and set data structures.[4] Another Haskell library "stm-containers" adapts the algorithm for use in the context of software transactional memory.[5] A JavaScript HAMT library [6] based on the Clojure implementation is also available. The Rubinius[7] implementation of Ruby includes a HAMT, mostly written in Ruby but with 3[8] primitives. Large maps in Erlang use a persistent HAMT representation internally since release 18.0.[9] The Pony programming language uses a HAMT for the hash map in its persistent collections package.[10] The im and im-rc crates, which provide persistent collection types for the Rust programming language, use a HAMT for their persistent hash tables and hash sets. [11]

The concurrent lock-free version[12] of the hash trie called Ctrie is a mutable thread-safe implementation which ensures progress. The data-structure has been proven to be correct[13] - Ctrie operations have been shown to have the atomicity, linearizability and lock-freedom properties.

Subsequent work

edit

In 2017, Michael Steindorfer introduced CHAMP (Compressed Hash-Array Mapped Prefix-tree)[14], an evolution of the HAMT that uses less space and improves performance for some operations, primarily iteration and equality testing (comparison of two collections). The primary difference is that where a HAMT node uses a single bitmap and storage vector for both elements and child nodes, CHAMP uses separate bitmaps for the elements and child nodes (they must have no 1 bits in common), and stores elements and child nodes in different regions of the vector.

See also

edit

References

edit
  1. ^ a b c Phil Bagwell (2000). Ideal Hash Trees (PDF) (Report). Infoscience Department, École Polytechnique Fédérale de Lausanne.
  2. ^ "clojure/clojure". GitHub. 8 December 2022.
  3. ^ "Frege/frege". GitHub. 7 December 2022.
  4. ^ Johan Tibell, A. Announcing unordered-containers 0.2
  5. ^ Nikita Volkov, Announcing the "stm-containers" library, 2014
  6. ^ "mattbierner/hamt". GitHub. 27 November 2022.
  7. ^ "Ruby source file of Rubinius's HAMT". GitHub.
  8. ^ https://github.com/rubinius/rubinius/blob/master/machine/builtin/system.cpp#L1724-L1802 [dead link]
  9. ^ "Erlang Programming Language".
  10. ^ "horse: Pony is an open-source, actor-model, capabilities-secure, high performance programming language: Ponylang/ponyc". GitHub. 2018-11-26.
  11. ^ "API docs for Rust im-rc crate".
  12. ^ Prokopec, A. Implementation of Concurrent Hash Tries on GitHub
  13. ^ Prokopec, A. et al. (2011) Cache-Aware Lock-Free Concurrent Hash Tries. Technical Report, 2011.
  14. ^ Steindorfer, Michael (2017). Efficient Immutable Collections (PDF) (Ph.D. thesis). Centrum Wiskunde & Informatica. Retrieved 2026-02-02.

📚 Artikel Terkait di Wikipedia

Trie

Suffix tree Hash trie Hash array mapped trie Prefix hash tree Ctrie HAT-trie Aho–Corasick algorithm Maabar, Maha (17 November 2014). "Trie Data Structure"

Persistent data structure

programming languages. A persistent hash array mapped trie is a specialized variant of a hash array mapped trie that will preserve previous versions

Hash table

Extendible hashing Hash array mapped trie Lazy deletion Pearson hashing PhotoDNA Rabin–Karp string search algorithm Search data structure Stable hashing Succinct

Radix tree

finite automata Judy array Search algorithm Extendible hashing Hash array mapped trie Prefix hash tree Burstsort Luleå algorithm Huffman coding Morin, Patrick

Hash trie

tries) in order to perform efficient lookups and updates" Hash array mapped trie Hashed array tree Merkle tree Liang, Frank Mark (June 1983). Word hy-phen-a-tion

Ctrie

concurrent hash-trie or Ctrie is a concurrent thread-safe lock-free implementation of a hash array mapped trie. It is used to implement the concurrent map abstraction

List of data structures

Distributed hash table Double hashing Dynamic perfect hash table Hash array mapped trie Hash list Hash table Hash tree Hash trie Koorde Prefix hash tree Rolling

Bitwise trie with bitmap

efficient solution for tries named Array Mapped Tree (AMT). The Hash array mapped trie (HAMT) is based on AMT. The compact trie node representation uses a bitmap