basicHash and abtHash32 - how useful ?

26 views
Skip to first unread message

Marten Feldtmann

unread,
Jul 31, 2011, 4:56:35 AM7/31/11
to va-sma...@googlegroups.com
Consider the following code:

| anIdentitySet anObject anObject2 |

anIdentitySet := IdentitySet new.
anObject := Point new x: 2.
anObject2 := Point new x: 2.
Transcript cr ; show: 'Hash-Value of first object: ', anObject basicHash asString.
Transcript cr ; show: 'Hash-Value of second object: ', anObject2 basicHash asString.

anObject y: 2.
Transcript cr ; show: 'Hash-Value of first object after change', anObject basicHash asString.

anObject := Point new x: 2.
anObject2 := Point new x: 2.
Transcript cr ; show: 'Hash32-Value of first object: ', anObject abtHash32 asString.
Transcript cr ; show: 'Hash32-Value of second object ', anObject2 abtHash32 asString.
anObject y: 2.
Transcript cr ; show: 'Hash32-Value of first object after change ', anObject abtHash32 asString.



the output is:

Hash-Value of first object: 31153
Hash-Value of second object: 31158
Hash-Value of first object after change31153
Hash32-Value of first object: 841485990
Hash32-Value of second object 841485990
Hash32-Value of first object after change 264182029

Several  remarks about this:

1) The method comment for basicHash is wrong and should be changed to " ... Objects that are identical (==) must ....."

       "Answer a SmallInteger that represents the receiver. Objects that are equivalent (=) must
        answer the same value for the message #basicHash."

2) In the past several users had problems with the 16-bit limitatons of basicHash and the idea was to use abtHash32 as a replacement for basicHash. But as you can see from the output and the code above: this is not useable. The value changes even when you change a simple attribute.


Therefore the question: You can we get IdentitySet, but with 32-bit wide keys ....

Marten Feldtmann

unread,
Jul 31, 2011, 5:37:42 AM7/31/11
to va-sma...@googlegroups.com
Could a primitive like this work (Of course the EsPrimArgNumNoArg is wrong here ..) to return true 32 it hash values ?

EsUserPrimitive(MSKHash32)
{
    U_32 rc;
    U_32 hashValue;
    EsObject retVal;

    hashValue = (EsFlags(EsPrimReceiver) & 0x7FFFFFFF);
    rc = EsI32ToInteger(hashValue, &retVal);
    if (rc != EsPrimErrNoError)
        EsPrimFail(rc, EsPrimArgNumNoArg);
    EsPrimSucceed(retVal);
}
Reply all
Reply to author
Forward
0 new messages