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:

  1. "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 repeated conjing; 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 use clojure.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. subsequent assoc 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.

  2. sorted: persistenttreemap instances created special request (a call sorted-map or sorted-map-by). implemented red-black trees , maintain entries in particular order, specified default compare comparator if created sorted-map or user-supplied comparator if created sorted-map-by.

  3. 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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -