Definition
A Ctrie (concurrent hash trie) is a lock‑free, concurrent, resizable hash array mapped trie (HAMT) that provides an associative array (map) with efficient, linearizable updates and fast, immutable snapshots. It stores key–value pairs by hashing the keys and navigating a trie whose branching factor is typically 32.
Historical Background
The data structure was introduced by Aleksandar Prokopec, Marko Vukolić, and Martin Odersky in the paper “Concurrent Tries with Efficient Snapshots” (SPAA 2012). The design builds on earlier immutable HAMT structures used in functional languages such as Clojure and Scala, adapting them for lock‑free concurrent access.
Structural Overview
| Node type | Purpose |
|---|---|
| C‑node (branch) | Holds an array of up to 32 child pointers indexed by a segment of the key’s hash. |
| I‑node (indirection) | Provides a mutable atomic reference to a C‑node, enabling lock‑free updates via compare‑and‑set (CAS). |
| S‑node (leaf) | Stores a single key–value entry (or a small bucket for hash collisions). |
| T‑node (tomb) | Marks a logically removed entry during removal operations. |
The trie depth is bounded by the number of bits in the hash code divided by the log₂ of the branching factor (e.g., 5 bits per level for a factor of 32). Typical operations therefore have expected O(log₃₂ n) time, which is effectively constant for practical map sizes.
Core Operations
- lookup (get) – Traverses the trie using hash bits until an S‑node with the sought key is found or a missing path is encountered.
- insert / update (put) – Creates a new version of the affected nodes, using CAS on the I‑node that points to the changed C‑node; the operation is linearizable and proceeds without global locks.
- remove – Replaces the target S‑node with a tomb node and subsequently compresses empty branches, again via lock‑free CAS.
- snapshot – Returns a read‑only view that shares structure with the live map; because updates produce new nodes, the snapshot remains immutable without copying.
Implementations and Usage
- Java – An open‑source library
ctrie(available on Maven Central) provides aConcurrentTrieMap<K,V>class implementing the Ctrie algorithm. - Scala –
scala.collection.concurrent.TrieMapis based on the Ctrie design and is part of the Scala standard library. - Clojure – While Clojure’s default persistent maps are immutable and not directly Ctries, the language’s agents and refs can be built atop Ctrie‑based structures for highly concurrent mutable state.
Advantages
- Lock‑free progress – Threads never block each other; progress is guaranteed as long as at least one thread continues to execute.
- Efficient immutable snapshots – Snapshots share most of their structure with the live map, enabling cheap versioning and consistent reads.
- Scalable performance – Empirical benchmarks show that Ctries outperform coarse‑grained locked maps under high contention, while remaining competitive with
java.util.concurrent.ConcurrentHashMapfor moderate contention levels.
Limitations
- Higher constant factors – The indirection and node copying involved in lock‑free updates incur overhead compared with highly optimized hash tables such as
ConcurrentHashMap. - Garbage‑collection pressure – Frequent updates generate short‑lived intermediate nodes, increasing allocation and GC activity, especially in environments without generational GC optimizations.
- Complexity of implementation – Correct lock‑free code requires careful handling of CAS loops and memory ordering, making custom adaptations error‑prone.
Key References
- Prokopec, A., Vukolić, M., & Odersky, M. (2012). Concurrent Tries with Efficient Snapshots. Proceedings of the 24th ACM Symposium on Parallelism in Algorithms and Architectures (SPAA ’12).
- “ctrie – A lock‑free concurrent hash trie for Java”, GitHub repository, https://github.com/aphyr/ctrie.
- “scala.collection.concurrent.TrieMap”, Scala Standard Library Documentation, https://www.scala-lang.org/api/current/scala/collection/concurrent/TrieMap.html.
See Also
- Hash Array Mapped Trie (HAMT) – the immutable functional predecessor of Ctrie.
- Lock‑free data structures – a broader class of non‑blocking concurrent algorithms.
This entry reflects information available in peer‑reviewed literature and maintained open‑source implementations as of August 2026.