Clojure has an array-map and hash-map, I couldn't figure out the difference between the two. Could anyone explain if possible with an example as to when either of them would be used?
array-maps keep the insertion order but you shouldn't rely on that behaviour except for very simple cases where you know the map is not going to be modified. Use an ordered collection if you really need this behaviour.
array-maps should be used for very small maps (8 keys currently) as the lookup and "modification" performance is better than a hash-map of the same size:
(def arraymap (array-map :f 1 :g 2 :h 4 :y 5 :w 4))
(def hashmap (hash-map :f 1 :g 2 :h 4 :y 5 :w 4))
(defn add-2-keys [m]
(assoc m :new 2 :w 4))
(defn access-all-keys [m]
(mapv m [:f :g :h :y :w :not-there]))
(use 'criterium.core)
; Modification
(bench (add-2-keys array map))
Execution time mean : 125.640082 ns
(bench (add-2-keys hashmap))
Execution time mean : 150.918197 ns
; Access
(bench (access-all-keys arraymap))
Execution time mean : 260.547035 ns
(bench (access-all-keys hashmap))
Execution time mean : 305.350156 ns