Array map, a persistent collection for small maps.

Array map is an implementation of IPersistentMap where items are stored internally in a host array. Whole array is copied on each update operation (conj, assoc, etc). This absence of structural sharing is efficient only for small maps. Use hamt-map for larger maps. Array maps have support for transients, folding and efficient unpacked reduce.

Current implementation switches to the hamt-map when number of items ([key value] pairs) exceeds 8.
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
28
29
;;; Array map is a default map implementation in Dunaj

;;; CLJ format provides syntax for 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])
;;=> {:a 1, :b 2, :c 3}

;;; 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]])
;;=> {:a 1, :b 2, :c 3}

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

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

array-map-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type (U ICollectionFactory IConvolutionFactory)

An Array Map factory instance. Currently there are no options.

This factory implements IConvolutionFactory and ICollectionFactory factory protocols.

New instances of Array 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.array-map :refer [array-map-factory]]))

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

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

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

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

empty-array-map

Available since version 1.0 (view source)

not referred automatically

VAR of type ArrayMap

An empty array map.