[chuck-users] object / class hacking
Hans Aberg
haberg at math.su.se
Wed Sep 30 09:52:18 EDT 2009
On 30 Sep 2009, at 14:26, Robert Poor wrote:
> Of course I'd love to use a hashmap. But how do you get one in
> Chuck? AFIK, the existing chuckain "hash array" lacks a means to
> iterate over its contents.
You want something like std::set, right? ONe can use the chuck
associative arrays as follows:
int set[0];
1 => set["hello"];
1 => set["world"];
if (set["this"] == 1)
<<< "ok" >>>;
else
<<< "nope" >>>;
if (set["hello"] == 1)
<<< "ok" >>>;
else
<<< "nope" >>>;
I got the printout:
$ chuck set.ck
"nope" : (string)
"ok" : (string)
It means that chuck treats an empty index as returning the int 0. So
by setting the other entries to a non-zero value, one can make use of
that implementation.
Insertion and deletion is easy. For deletion, just set the value to 0
- it will remain there, but checks will say it is empty.
I couldn't find iterators for these associative arrays. I think they
are implemented using std::map, though.
Hans
More information about the chuck-users
mailing list