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 repeatedconjing; 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-maparbitrarily large array maps, may useful if know you'd benefit insertion-order traversals , map won't large, perhaps bit on usual threshold; nb. subsequentassocsuch 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:
persistenttreemapinstances created special request (a callsorted-maporsorted-map-by). implemented red-black trees , maintain entries in particular order, specified defaultcomparecomparator if createdsorted-mapor user-supplied comparator if createdsorted-map-by.special-purpose, deprecated:
persistentstructmapnot 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