ArticleslgStudy

science

Hash array mapped trie

Hash array mapped trie is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Hash array mapped trie rather than just read about it. In short: A hash array mapped trie (HAMT, ) is an implementation of an associative array that combines the characteristics of a hash table and an array mapped trie. It is a refined version of the more general notion of a hash tree.

Key takeaways

  • Hash array mapped trie belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Hash array mapped trie to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Hash array mapped trie from memory before moving on to harder problems.

Reference excerpt

A hash array mapped trie (HAMT, ) is an implementation of an associative array that combines the characteristics of a hash table and an array mapped trie. It is a refined version of the more general notion of a hash tree.

Operation 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 The hash array mapped trie achieves almost hash table-like speed while using memory much more economically. 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 with negligible impact on performance.

Implementation details 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.

Implementations The programming languages Clojure, Scala, and Frege 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. Another Haskell library "stm-containers" adapts the algorithm for use in the context of software transactional memory. A JavaScript HAMT library based on the Clojure implementation is also available. The Rubinius implementation of Ruby includes a HAMT, mostly written in Ruby but with 3 primitives. Large maps in Erlang use a persistent HAMT representation internally since release 18.0. The Pony programming language uses a HAMT for the hash map in its persistent collections package. 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.

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

Subsequent work In 2017, Michael Steindorfer introduced CHAMP (Compressed Hash-Array Mapped Prefix-tree), 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 Judy array Radix tree

References

Worked examples

Example 1 — a first encounter with Hash array mapped trie

Start with the simplest possible case. Write down what Hash array mapped trie claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Hash array mapped trie before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Hash array mapped trie ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Hash array mapped trie

In research
Hash array mapped trie appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Hash array mapped trie in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Hash array mapped trie is common in secondary-school and first-year university syllabi. It links to neighbouring topics Associative arrays, Hashing, so understanding it makes those chapters shorter.
In everyday life
Look for Hash array mapped trie outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Hash array mapped trie” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Hash array mapped trie in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Hash array mapped trie means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Hash array mapped trie out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Hash array mapped trie in simple terms?

A hash array mapped trie (HAMT, ) is an implementation of an associative array that combines the characteristics of a hash table and an array mapped trie. It is a refined version of the more general notion of a hash tree.

Why does Hash array mapped trie matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Hash array mapped trie?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Hash array mapped trie.

Tags

  • Associative arrays
  • Hashing

Keep exploring