On Sat, Aug 29, 2009 at 3:19 AM, Travis <twell...@gmail.com> wrote:

> Is the number 8 just a magic number? Can it be changed with an
> environment variable or system variable or binding? I would definitely
> like to.


You can't change it.
Clojure's ArrayMap is really designed for a small number of kv pairs (eg no
structural sharing and lookup, assoc, dissoc are O(1) only because the
length is bounded).
I think ArrayMap should be considered as an optimization.

What is your use case?


> I am particularly annoyed by how the function into changes my array
> maps into hash maps when they grow.


Speaking of 8 and small inconsistencies that can bite you with arraymaps :
- map literals with strictly more than 8 pairs are hashmaps,
- but an arraymap can grow up to 9 pairs: (class (reduce #(assoc %1 %2 %2)
{} (range 9)))
- when created with array-map an array-map can have as many pairs as you
want but (if count >= 9) conj/assoc returns a hashmap
- dissoc always returns an array-map: (class (dissoc (apply array-map (range
32)) 13))
- insertion order depends on how you build your array-map
(literal/persistently/transiently), see:
user=> {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7} ; literal
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
user=> (reduce #(assoc %1 %2 %2) {} (range 8)) ; inserts at front
{7 7, 6 6, 5 5, 4 4, 3 3, 2 2, 1 1, 0 0}
user=> (into {} (for [x (range 8)] [x x])) ; appends
{0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
user=> (reduce #(assoc %1 %2 %2) {0 0 1 1 2 2} (range 3 8)) ; happy mix
{7 7, 6 6, 5 5, 4 4, 3 3, 0 0, 1 1, 2 2}

arraymaps should really be used with great care.

Btw array-map is used only once in core.clj mainly as an historical
substitute to (partition 2 coll).

Christophe


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to