I don&#39;t think there are iterators for associative arrays, and cap() keeps returning zero even though you&#39;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">&lt;<a href="mailto:haberg@math.su.se">haberg@math.su.se</a>&gt;</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&#39;d love to use a hashmap.  But how do you get one in Chuck?  AFIK, the existing chuckain &quot;hash array&quot; 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 =&gt; set[&quot;hello&quot;];<br>
1 =&gt; set[&quot;world&quot;];<br>
<br>
if (set[&quot;this&quot;] == 1)<br>
  &lt;&lt;&lt; &quot;ok&quot; &gt;&gt;&gt;;<br>
else<br>
  &lt;&lt;&lt; &quot;nope&quot; &gt;&gt;&gt;;<br>
<br>
if (set[&quot;hello&quot;] == 1)<br>
  &lt;&lt;&lt; &quot;ok&quot; &gt;&gt;&gt;;<br>
else<br>
  &lt;&lt;&lt; &quot;nope&quot; &gt;&gt;&gt;;<br>
<br>
I got the printout:<br>
  $ chuck <a href="http://set.ck" target="_blank">set.ck</a><br>
  &quot;nope&quot; : (string)<br>
  &quot;ok&quot; : (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&#39;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>