basicHash and abtHash32 - how useful ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

basicHash and abtHash32 - how useful ?

Marten Feldtmann-2
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 ....

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/va-smalltalk/-/UjB-yOuHIhkJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/va-smalltalk?hl=en.
Reply | Threaded
Open this post in threaded view
|

Aw: basicHash and abtHash32 - how useful ?

Marten Feldtmann-2
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);
}

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/va-smalltalk/-/KIAhtnt4SI4J.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/va-smalltalk?hl=en.