I don't think there are iterators for associative arrays, and cap() keeps returning zero even though you've added stuff.<br><br>/Stefan<br><br><div class="gmail_quote">On Wed, Sep 30, 2009 at 3:52 PM, Hans Aberg <span dir="ltr"><<a href="mailto:haberg@math.su.se">haberg@math.su.se</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On 30 Sep 2009, at 14:26, Robert Poor wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>
</blockquote>
<br></div>
You want something like std::set, right? ONe can use the chuck associative arrays as follows:<br>
<br>
int set[0];<br>
<br>
1 => set["hello"];<br>
1 => set["world"];<br>
<br>
if (set["this"] == 1)<br>
<<< "ok" >>>;<br>
else<br>
<<< "nope" >>>;<br>
<br>
if (set["hello"] == 1)<br>
<<< "ok" >>>;<br>
else<br>
<<< "nope" >>>;<br>
<br>
I got the printout:<br>
$ chuck <a href="http://set.ck" target="_blank">set.ck</a><br>
"nope" : (string)<br>
"ok" : (string)<br>
<br>
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.<br>
<br>
Insertion and deletion is easy. For deletion, just set the value to 0 - it will remain there, but checks will say it is empty.<br>
<br>
I couldn't find iterators for these associative arrays. I think they are implemented using std::map, though.<div><div></div><div class="h5"><br>
<br>
Hans<br>
<br>
<br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Release me, insect, or I will destroy the Cosmos!<br>