What is the difference between clojure's APersistentMap implementations -
i'm trying figure out difference between persistenthashmap, persistentarraymap, persistenttreemap, , persistentstructmap.
also if use {:a 1}
gives me persistentarraymap can change of other ones if give objects or things other keys?
the 4 implementations list fall 3 groups:
"literal":
persistentarraymap
,persistenthashmap
: basic map types used when dealing map literals (though constructor functions available different behaviour around handling duplicate keys -- in clojure 1.5.x literals throw exceptions when discover duplicate keys, constructor functions work left-to-right repeatedconj
ing; behaviour has been evolving version version). array maps promoted hash maps when growing beyond number of entries (9 iirc). array maps exist because faster small maps; differ hash maps in keep entries in insertion order prior promotion hash map (you can useclojure.core/array-map
arbitrarily large array maps, may useful if know you'd benefit insertion-order traversals , map won't large, perhaps bit on usual threshold; nb. subsequentassoc
such oversized array map return hash map). array maps use arrays keys , values interleaved; phm uses persistent version of phil bagwell's hash array mapped trie separate chaining hash collisions , separate node types mostly-empty , at-least-half-full nodes , complex data structure in clojure.sorted:
persistenttreemap
instances created special request (a callsorted-map
orsorted-map-by
). implemented red-black trees , maintain entries in particular order, specified defaultcompare
comparator if createdsorted-map
or user-supplied comparator if createdsorted-map-by
.special-purpose, deprecated:
persistentstructmap
not used , viewed deprecated in favour of records, although can't remember right if there ever official deprecation notice. original purpose provide maps particularly fast access often-used keys. can accomplished records when using keywords field access (with keyword in operator position:(:foo instance-of-some-record-with-field-foo)
), though it's important note records not=
regular maps same entries.
all these 4 built-in map types fall same "equality partition", is, 2 maps of 1 of 4 classes mentioned above equal if (and if) contain same keys (as determined clojure's =
) same corresponding values. records, mentioned in 3. above, map-like, each record type forms own equality partition.
Comments
Post a Comment