Hash Array Mapped Trie set, 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.

HAMT sets have support for transients and folding.

Except for very special cases, it is idiomatic to use set 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
;;; CLJ format provides syntax for set literals.

{:a :b :c}

;;; convenience functions for sets

(->set :a :b :c)
;;=> #{:c :b :a}

(set [:a :b :c])
;;=> #{:c :b :a}

;;; Using empty-set

(conj empty-set :a :b :c)
;;=> #{:c :b :a}

(into empty-set [:a :b :c])
;;=> #{:c :b :a}

;;; using #{} has the same effect as using empty-set

(conj #{} :a :b :c)
;;=> #{:c :b :a}

empty-hamt-set

Available since version 1.0 (view source)

not referred automatically

VAR of type HamtSet

An empty HAMT set.

hamt-set-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type ICollectionFactory

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

This factory implements ICollectionFactory factory protocol.

New instances of HAMT set can be created with collection and ->collection.

1
2
3
4
5
6
7
8
9
10
(ns foo.bar
  (:api dunaj)
  (:require [dunaj.coll :refer [->collection collection]]
            [dunaj.coll.hamt-set :refer [hamt-set-factory]]))

(->collection hamt-set-factory :a :b :c)
;;=> #{:c :b :a}

(collection hamt-set-factory [:a :b :c])
;;=> #{:c :b :a}