On Sat, Feb 13, 2010 at 3:39 AM, Jan Hudec <[email protected]> wrote:
> On Sat, Feb 13, 2010 at 02:54:21 +0530, Martin DeMello wrote:
>> What's the most efficient (in terms of speed) way to iterate over a
>> hash in sorted order of the keys? The keys are strings.
>
> To use a balanced tree.
>
> Hash can only ever be iterated in the hash order, which is fixed but
> pseudo-random.

Well, here's my exact problem: I have a TreeMap that I add (string,
string) pairs to. The desired output is a sorted list of these pairs.
Now I'm wondering if it'd be more efficient to use a HashMap instead,
since I don't really need to maintain the sorted property as the list
is built up, just have it sorted when I return it. Roughly, I want

for i in map.keys.sort() {
  retval.append (i, map[i])
}

return retval

except I've been through the API and I can't find a good way to sort
the keys, or to push the pairs into a list and sort the list.

martin
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to