Hash Array Mapped Trie map, a persistent collection.

Based on Phil Bagwell’s Hash Array Mapped Tries, this collection type stores items in a trie (pronounced /ˈtriː/), which offers both persistency and efficient item lookup. For small maps however, array maps can be more efficient.

HAMT maps have support for transients, folding and efficient unpacked reduce.

Except for very special cases, it is idiomatic to use map literal or functions defined in coll.default rather than ones in this namespace.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;;; CLJ format provides syntax for maps. HAMT maps are used only for larger maps.

{:a 1 :b 2 :c 3}

;;; convenience functions for maps

(->map :a 1 :b 2 :c 3)
;;=> {:c 3, :b 2, :a 1}

(zipmap [:a :b :c] [1 2 3])
;;=> {:c 3, :b 2, :a 1}

;;; Using empty-map

(assoc empty-map :a 1 :b 2 :c 3)
;;=> {:c 3, :b 2, :a 1}

(conj empty-map [:a 1] [:b 2] [:c 3])
;;=> {:c 3, :b 2, :a 1}

(into empty-map [[:a 1] [:b 2] [:c 3]])
;;=> {:c 3, :b 2, :a 1}

;;; using {} has the same effect as using empty-map

(assoc {} :a 1 :b 2 :c 3)
;;=> {:c 3, :b 2, :a 1}

empty-hamt-map

Available since version 1.0 (view source)

not referred automatically

VAR of type HamtMap

An empty HAMT map.

hamt-map-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type (U ICollectionFactory IConvolutionFactory)

A HAMT map factory instance. Currently there are no options.

This factory implements IConvolutionFactory and ICollectionFactory factory protocols.

New instances of HAMT map can be created with collection, ->collection, convolution and ->convolution.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(ns foo.bar
  (:api dunaj)
  (:require [dunaj.coll :refer [->collection collection ->convolution convolution]]
            [dunaj.coll.hamt-map :refer [hamt-map-factory]]))

(->collection hamt-map-factory [:a 1] [:b 2] [:c 3])
;;=> {:c 3, :b 2, :a 1}

(collection hamt-map-factory [[:a 1] [:b 2] [:c 3]])
;;=> {:c 3, :b 2, :a 1}

(->convolution hamt-map-factory :a 1 :b 2 :c 3)
;;=> {:c 3, :b 2, :a 1}

(convolution hamt-map-factory [:a :b :c] [1 2 3])
;;=> {:c 3, :b 2, :a 1}