realbasic-nug
[Top] [All Lists]

Re: How to use custom comparison for matching in Dictionary?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: How to use custom comparison for matching in Dictionary?
From: Charles Yeomans <charles@declareSub.com>
Date: Mon, 29 Mar 2010 14:49:01 -0400
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <89fe53801003280811p4ae8b564y24049aa8d4c34908@mail.gmail.com>
References: <89fe53801003280811p4ae8b564y24049aa8d4c34908@mail.gmail.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

On Mar 28, 2010, at 11:11 AM, Thomas Tempelmann wrote:

I believe to have once been explained (by oe Strout, IIRC) that the
Dictionary class uses the object's compare function in order to match
up equal keys. That's, for instance, why Strings, even if they not
point to the same memory "object" (i.e address), are still matched up
as keys in a directory.

Now, I've written a little class that combines two values, and I've
implemented the Operator_Compare function adequately.

However, when I insert or lookup objects of this class in a
Dictionary, Operator_Compare is not invoked, meaning I can not match
up objects containing the same values.

Do I do something wrong or did I misunderstand how Dictionary is implemened?


The latter --  I reported this issue years ago.

As best as I can tell, the root of the problem is the refusal of RS to add an actual Object class with virtual methods. This prevents Operator_Compare (and other such methods) from working as expected when the declared type of the first argument lacks an Operator_Compare method. For Dictionary, probably one would need to be able to override a Hash method so that objects defined to be equal via Operator_Compare have the same hash.


Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>