[chuck-users] object / class hacking

Andrew C. Smith acsmith at willamette.edu
Wed Sep 30 10:16:19 EDT 2009

But with this, you can't easily return the contents (which in this
case is the list of names, not the "contents" in the normal sense) of
the associative arrays. If you can iterate, deleting is pretty easy.
The problem there is just that everything has to be re-sorted. Without
easy pointers, it's much more difficult to insert something into a
sorted list, but luckily an array is basically just a series of
pointers (right?).

If you had a sortable list (like note numbers of a chord or something)
then you could drop the search function into the middle and get to
your destination quite a bit faster. If you wanted to hack the array
class to create .insert() and .remove() methods (where .remove() keeps
the order without any null pointers) then please, do share. It could
probably be done in ChucK sans-hacking, but where's the fun in that?

What is the difference exactly between .cap() and .size() ?


On Wed, Sep 30, 2009 at 9:52 AM, Hans Aberg <haberg at math.su.se> wrote:
> 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
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list