[squeak-dev] identityHash or scaledIdentityHash ?

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Dec 23 23:09:41 UTC 2009


Maybe Levente will help me clarifying this...
I encountered several different implementations:

MessageTally, Semaphore, FutureMaker, LocatedMethod, TextAnchor
hash
    ^self identityHash
(or ^someInstVar identityHash, which is equivalent)

Object
hash
   ^self scaledIdentityHash

The first does not scale well for large Set/Dictionary, and the second
costs a little overhed on small (Set/Dictionary).
My questions are:
- are these different implementations deliberate ? For example knowing
there won't be any large Set... In which case a comment would help
- or should we always use the scaledIdentityHash to hash ? (and let
identityHash for printing and a few well commented exceptional cases)

Beside, apart printing usage, I note these two usages of IdentityHash as hash:
MethodDictionary scanFor: (I guess we don't expect more than 4096
messages too often).
Player recaptureUniqueCostumes

I also noted that MethodDictionary does not override
scanForEmptySlotFor: which is defined in term either of hash or
scaledIdentityHash, rather than IdentityHash
This is currently OK, because the unique path I found was:

MethodDictionary>>#at:put
-> HashCollection>>atNewIndex:put:
-> MethodDictionary>>#grow
OK, grow overrides super, otherwise:
-> HashCollection>>#grow
-> HashCollection>>#growTo:
-> Dictionary>>#noCheckNoGrowFillFrom:
-> HashCollection>>#scanForEmptySlotFor:
-> Symbol>>#hash

But it's a potential tricky trap for future.

Nicolas



More information about the Squeak-dev mailing list