Re: [Vala] Does Vala.HashMap works ?

On Mon, Jan 04, 2010 at 14:05:34 +0800, G.S.Alex wrote:
this code is almost the same with the  libgee example.
but the value haspmap will always be 0 for int , (null) for string.

using Vala;

What are you writing? Unless it's something related to the vala language
itself, you should be using libgee, NOT libvala. Also note, that libvala
is still based on libgee 0.3 and libgee 0.5 has different, significantly
improved API.

static int main (string[] args) {

    var map = new Vala.HashMap<string, int> ();

Default hash and equal functions are direct hash and direct equal -- that
won't work for string keys!

You need to do: new Vala.HashMap<string, int> (GLib.str_hash, GLib.str_equal);

    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["two"]);       // same as map.get (key)
//  }

Should return 0, because the "two" is not there. Only the previous "two",
which is different pointer, is. It should actually work with the foreach,

    return 0;

                                                 Jan 'Bulb' Hudec <bulb ucw cz>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]