[chuck-users] implementing a set (was object / class hacking)

Stefan Blixt stefan.blixt at gmail.com
Thu Oct 1 02:52:02 EDT 2009


On Wed, Sep 30, 2009 at 10:12 PM, Robert Poor <rdpoor at gmail.com> wrote:

>
>
> So what I'll probably end up doing is to create a unique ID for each of my
> objects (either via toString() or some other construction-time device), and
> keeping the objects sorted in an array using the ID for a binary search
> function.  It's not as fast as a hashmap, but it's faster than linear
> search.
>
> - rob
>

Hmm, toString() (giving the memory pointer thingie) won't work if you want
to be able to create two equal objects and use them like:

A x1;
"x" => x1.id;
hashset.put(x1);
A y;
"y" => y.id;
hashset.put(y);
A x2;
"x" => x2.id; // same as x1
if (hashset.contains(x2)) {
    // You want this code to run here
}


-- 
Release me, insect, or I will destroy the Cosmos!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20091001/5125b316/attachment.htm>


More information about the chuck-users mailing list