Re: Order of keys within a map?

2009-09-02 Thread Richard Newman
> Maybe it's premature optimization, but I don't want the overhead of a > sorted map structure when a minimal (and ideally, optimized for few > keys) map will do better. Then you might want to look at struct-map... predefined keys are in a fixed order. --~--~-~--~~~

Re: Order of keys within a map?

2009-09-02 Thread Howard Lewis Ship
Maybe it's premature optimization, but I don't want the overhead of a sorted map structure when a minimal (and ideally, optimized for few keys) map will do better. On Tue, Sep 1, 2009 at 11:46 AM, Rob Lachlan wrote: > > As, Patrick Sullivan, said, the built-in sorted-map guarantees that > the key

Re: Order of keys within a map?

2009-09-01 Thread Rob Lachlan
As, Patrick Sullivan, said, the built-in sorted-map guarantees that the keys will be in order. I'm probably missing something here, but wouldn't that fit the bill? http://clojure.org/api#sorted-map Rob Lachlan On Aug 27, 12:35 pm, Howard Lewis Ship wrote: > Is the order of keys in a map predi

Re: Order of keys within a map?

2009-08-29 Thread Christophe Grand
On Sat, Aug 29, 2009 at 3:19 AM, Travis 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 st

Re: Order of keys within a map?

2009-08-28 Thread Travis
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. I am particularly annoyed by how the function into changes my array maps into hash maps when they grow. The type of the first argument is an array map, so

Re: Order of keys within a map?

2009-08-27 Thread Sean Devlin
Howard, I ran into the exact same problem. Check out the discussion on fn- tuple here: http://groups.google.com/group/clojure-dev/browse_thread/thread/155c8b9893d673bc# This should do what you need. Sean On Aug 27, 3:35 pm, Howard Lewis Ship wrote: > Is the order of keys in a map predictabl

Re: Order of keys within a map?

2009-08-27 Thread Christophe Grand
On Thu, Aug 27, 2009 at 9:35 PM, Howard Lewis Ship wrote: > Literally: when iterating over the key/value pairs, the order seems to > be the order in which the key/values are defined in the map. Is this > true? user=> {"0" 0 "1" 1 "2" 2 "3" 3 "4" 4 "5" 5 "6" 6 "7" 7 "8" 8 "9" 9 "10" 10 "11" 11 "

Re: Order of keys within a map?

2009-08-27 Thread Jeremy Gailor
Traditionally, there is no guarantee for the sorting order of keys in a map. There are sorted map implementations around though if you are in need of this functionality (I'm not sure if there is a Clojure sorted map, but the algorithm is out there). On Thu, Aug 27, 2009 at 12:35 PM, Howard Lewis

Re: Order of keys within a map?

2009-08-27 Thread Richard Newman
> Literally: when iterating over the key/value pairs, the order seems to > be the order in which the key/values are defined in the map. Is this > true? For small numbers of keys (<7 I think) they're stored in a linear format (analogous to an associative list), and the insertion order is effec

Re: Order of keys within a map?

2009-08-27 Thread John Harrop
On Thu, Aug 27, 2009 at 3:35 PM, Howard Lewis Ship wrote: > > Is the order of keys in a map predictable? I have some tests I'm > concerned about, where the keys and values in a map are converted to a > string (ultimately, a URL, as query parameters) and the order will > affect the output string.

Re: Order of keys within a map?

2009-08-27 Thread Richard Newman
> Key order is preserved for array-maps. Map literals up to 8 pairs > are array-maps. Beginning with 9 pairs you get a hash-map. I'm not > aware of a rule how to determine the order of keys of a hash-map. > This is implementation specific, I would assume. (Thus can change at > any arbitrar

Re: Order of keys within a map?

2009-08-27 Thread Meikel Brandmeyer
Hi, Am 27.08.2009 um 21:35 schrieb Howard Lewis Ship: Is the order of keys in a map predictable? I have some tests I'm concerned about, where the keys and values in a map are converted to a string (ultimately, a URL, as query parameters) and the order will affect the output string. I could so

Re: Order of keys within a map?

2009-08-27 Thread Patrick Sullivan
If you look at the data_structures page on clojure.org you'll see there are sorted maps available to allow guarantees of being sorted by Key. ~Patrick On Aug 27, 1:40 pm, Jeremy Gailor wrote: > Traditionally, there is no guarantee for the sorting order of keys in a map. > > There are sorted map

Order of keys within a map?

2009-08-27 Thread Howard Lewis Ship
Is the order of keys in a map predictable? I have some tests I'm concerned about, where the keys and values in a map are converted to a string (ultimately, a URL, as query parameters) and the order will affect the output string. I could sort the keys, but then I'm changing my code to support the