On Sun, 2009-10-04 at 16:29 +0200, Nicolas wrote:
> Hi,
>
> I'm trying to use the Gee library, but i have a problem;
> This is the code taken from the vala site:
>
> using Gee;
>
> static int main (string[] args) {
>
> var map = new HashMap<string, int> ();
> map.set ("one", 1);
> map.set ("two", 2);
> map.set ("three", 3);
> map["four"] = 4; // same as map.set ("four", 4)
> map["five"] = 5;
> foreach (string key in map.keys) {
> stdout.printf ("%d\n", map[key]); // same as map.get (key)
> }
>
> return 0;
> }
>
> My question is, why when i execute this, the result is:
> 4
> 3
> 1
> 2
> 5
>
> And not:
> 1
> 2
> 3
> 4
> 5
>
> Thanks in advance for your response.
> Nicolas.
>
>
thats typical for all hash tables. A good hash function will randomly
distribute the keys in the table and so will almost never be in the
order you add them
If you want order, use a list but not a dict or a hash
jamei
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list