Composite keys in Dictionary

Brian T. Rice water at tunes.org
Sun Sep 26 11:27:40 PDT 2004


Daniel John Crowe wrote:
> 
> Hi,
> 
> I'm just introducing myself to the slate world (0.3) and I've come up against an issue.

Hi. Welcome to it.

> I've been trying to add composite keys to a dictionary.
> ie:    dict at: (keya , keyb) put: val.
> 
> The dictionary uses an identity hash on the tuple, and this prevents me from using a new tuple to read the value from the dictionary.

I presume here that this means you used an IdentityDictionary to create 
a dictionary instead of the default Dictionary. If you didn't, then 
there'd be either a bug or a missing = and hash method on Tuples (which 
it seems to inherit from Sequence, but there may be a surprise). Or 
maybe some other mis-understanding.

> ie:   dict at: (keya, keyb). "fails"
> 
> What is the best way around this?

If you don't want this behavior, don't use an IdentityDictionary. :) You 
either pay the cost to resolve every tuple into a unique value-instance 
or you pay the cost of equality-comparison versus identity-comparison. 
Tuples are not worth this; not as they are now, anyway. So just use a 
regular dictionary.

> Thanks, Daniel Crowe.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: water.vcf
Type: text/x-vcard
Size: 265 bytes
Desc: not available
Url : /archives/slate/attachments/20040926/817f0140/water.vcf


More information about the Slate mailing list