VAST 8.5.2 - Set hash and equality are incompatible/incorrect

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

VAST 8.5.2 - Set hash and equality are incompatible/incorrect

Richard Sargent
Administrator
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

bgridley-2
It looks like the problem is in the #with:with: method.  (Set with: s1) add: s2 works as expected.  If I was you, I'd report the #with:with: method as a bug according to the info on http://www.instantiations.com/support/index.html#contact .

All the with:with:...with: methods are a problem.  Inside those methods for the Set class it should not call "self new:" but  "self new".

On Wednesday, September 11, 2013 6:24:02 PM UTC-4, Richard Sargent wrote:
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

John O'Keefe-3
In reply to this post by Richard Sargent
Richard -

The problem is that Set is missing an implementation of #hash. Try adding this method to Collection (you will then get (1 true)):
hash
"Synopsis
Return an integer hash code that can be used in conjunction with an #= comparison.

Definition: <Object>
An integer value that can be used as a hash code for the receiver is returned. The hash code is
intended for use in conjunction with an #= comparison.
The range, minimum, and maximum values of the result is implementation defined.
Any two objects that are considered equivalent using the #= message must have the same hash
value. More formally:
receiver = comparand iff
receiver hash = comparand hash
The hash value of an object need not be temporally invariant. Two independent invocations of
#hash with the same receiver may not always yield the same results. But note that collections
that use #= to discriminate objects may only reliably store objects whose hash values do not
change while the objects are contained in the collection.

Return Value
<integer>unspecified

Errors
none
Implementation Notes:
It would be more correct to include all elements of the receiver in the hash calculation, but we
don't want the calculation to take a significant length of time, so an arbitrary limit of 8
elements is used. If there are more than 8 elements, the hash gets pretty simple."

| hash |

hash := self species hash.
self size <= 8 ifTrue: [
hash := self inject: hash into: [ :ans :elem | ans bitXor: elem hash ] ].
^ hash bitXor: self size hash

John 

On Wednesday, September 11, 2013 6:24:02 PM UTC-4, Richard Sargent wrote:
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

Richard Sargent
Administrator
Thanks, John. Will this be the official fix in the next version?


On Tue, Sep 24, 2013 at 1:57 PM, John O'Keefe <[hidden email]> wrote:
Richard -

The problem is that Set is missing an implementation of #hash. Try adding this method to Collection (you will then get (1 true)):
hash
"Synopsis
Return an integer hash code that can be used in conjunction with an #= comparison.

Definition: <Object>
An integer value that can be used as a hash code for the receiver is returned. The hash code is
intended for use in conjunction with an #= comparison.
The range, minimum, and maximum values of the result is implementation defined.
Any two objects that are considered equivalent using the #= message must have the same hash
value. More formally:
receiver = comparand iff
receiver hash = comparand hash
The hash value of an object need not be temporally invariant. Two independent invocations of
#hash with the same receiver may not always yield the same results. But note that collections
that use #= to discriminate objects may only reliably store objects whose hash values do not
change while the objects are contained in the collection.

Return Value
<integer>unspecified

Errors
none
Implementation Notes:
It would be more correct to include all elements of the receiver in the hash calculation, but we
don't want the calculation to take a significant length of time, so an arbitrary limit of 8
elements is used. If there are more than 8 elements, the hash gets pretty simple."

| hash |

hash := self species hash.
self size <= 8 ifTrue: [
hash := self inject: hash into: [ :ans :elem | ans bitXor: elem hash ] ].
^ hash bitXor: self size hash

John 

On Wednesday, September 11, 2013 6:24:02 PM UTC-4, Richard Sargent wrote:
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to a topic in the Google Groups "VA Smalltalk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/va-smalltalk/N9iodk_0r5w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.



--
Richard Sargent
Business Development Manager
[hidden email]
GemTalk Systems
15220 NW Greenbrier Parkway #240
Beaverton, OR 97006

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

John O'Keefe-3
Richard -

Yes, unless I did it wrong :-)

John

On Tuesday, September 24, 2013 5:14:07 PM UTC-4, Richard Sargent wrote:
Thanks, John. Will this be the official fix in the next version?


On Tue, Sep 24, 2013 at 1:57 PM, John O'Keefe <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="3cmF3WDAjtYJ">john_...@instantiations.com> wrote:
Richard -

The problem is that Set is missing an implementation of #hash. Try adding this method to Collection (you will then get (1 true)):
hash
"Synopsis
Return an integer hash code that can be used in conjunction with an #= comparison.

Definition: <Object>
An integer value that can be used as a hash code for the receiver is returned. The hash code is
intended for use in conjunction with an #= comparison.
The range, minimum, and maximum values of the result is implementation defined.
Any two objects that are considered equivalent using the #= message must have the same hash
value. More formally:
receiver = comparand iff
receiver hash = comparand hash
The hash value of an object need not be temporally invariant. Two independent invocations of
#hash with the same receiver may not always yield the same results. But note that collections
that use #= to discriminate objects may only reliably store objects whose hash values do not
change while the objects are contained in the collection.

Return Value
<integer>unspecified

Errors
none
Implementation Notes:
It would be more correct to include all elements of the receiver in the hash calculation, but we
don't want the calculation to take a significant length of time, so an arbitrary limit of 8
elements is used. If there are more than 8 elements, the hash gets pretty simple."

| hash |

hash := self species hash.
self size <= 8 ifTrue: [
hash := self inject: hash into: [ :ans :elem | ans bitXor: elem hash ] ].
^ hash bitXor: self size hash

John 

On Wednesday, September 11, 2013 6:24:02 PM UTC-4, Richard Sargent wrote:
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to a topic in the Google Groups "VA Smalltalk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/va-smalltalk/N9iodk_0r5w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="3cmF3WDAjtYJ">va-smalltalk...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="3cmF3WDAjtYJ">va-sma...@....
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.



--
Richard Sargent
Business Development Manager
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="3cmF3WDAjtYJ">richard...@gemtalksystems.com
GemTalk Systems
15220 NW Greenbrier Parkway #240
Beaverton, OR 97006

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

John O'Keefe-3
In reply to this post by bgridley-2
Brian -

I do see a difference in results between Set with:with: and (Set with:) with: -- at the moment I am unable to explain this, but I will study a little more and the answer should come clear.

John

On Tuesday, September 24, 2013 12:20:48 PM UTC-4, [hidden email] wrote:
It looks like the problem is in the #with:with: method.  (Set with: s1) add: s2 works as expected.  If I was you, I'd report the #with:with: method as a bug according to the info on http://www.instantiations.com/support/index.html#contact .

All the with:with:...with: methods are a problem.  Inside those methods for the Set class it should not call "self new:" but  "self new".

On Wednesday, September 11, 2013 6:24:02 PM UTC-4, Richard Sargent wrote:
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

John O'Keefe-3
In reply to this post by John O'Keefe-3
Richard -

I'm still playing around with the arbitrary number of elements to see if I can get a better hash distribution without spending too many cycles, so this may change also.

John

On Tuesday, September 24, 2013 5:20:35 PM UTC-4, John O'Keefe wrote:
Richard -

Yes, unless I did it wrong :-)

John

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: VAST 8.5.2 - Set hash and equality are incompatible/incorrect

John O'Keefe-3
In reply to this post by John O'Keefe-3
Richard -
 
Sorry, I've found a failing case with the code I posted -- it gets a StackOverflow exception if a set recursively includes itself. Back to the drawing board.
 
John

On Tuesday, September 24, 2013 5:20:35 PM UTC-4, John O'Keefe wrote:
Richard -

Yes, unless I did it wrong :-)

John

On Tuesday, September 24, 2013 5:14:07 PM UTC-4, Richard Sargent wrote:
Thanks, John. Will this be the official fix in the next version?


On Tue, Sep 24, 2013 at 1:57 PM, John O'Keefe <[hidden email]> wrote:
Richard -

The problem is that Set is missing an implementation of #hash. Try adding this method to Collection (you will then get (1 true)):
hash
"Synopsis
Return an integer hash code that can be used in conjunction with an #= comparison.

Definition: <Object>
An integer value that can be used as a hash code for the receiver is returned. The hash code is
intended for use in conjunction with an #= comparison.
The range, minimum, and maximum values of the result is implementation defined.
Any two objects that are considered equivalent using the #= message must have the same hash
value. More formally:
receiver = comparand iff
receiver hash = comparand hash
The hash value of an object need not be temporally invariant. Two independent invocations of
#hash with the same receiver may not always yield the same results. But note that collections
that use #= to discriminate objects may only reliably store objects whose hash values do not
change while the objects are contained in the collection.

Return Value
<integer>unspecified

Errors
none
Implementation Notes:
It would be more correct to include all elements of the receiver in the hash calculation, but we
don't want the calculation to take a significant length of time, so an arbitrary limit of 8
elements is used. If there are more than 8 elements, the hash gets pretty simple."

| hash |

hash := self species hash.
self size <= 8 ifTrue: [
hash := self inject: hash into: [ :ans :elem | ans bitXor: elem hash ] ].
^ hash bitXor: self size hash

John 

On Wednesday, September 11, 2013 6:24:02 PM UTC-4, Richard Sargent wrote:
| s1 s2 ss |
s1 := Set with: #ActionButtonSpec.
s2 := Set with: #ActionButtonSpec.
ss := Set with: s1 with: s2.
Array
    with: ss size
    with: s1 = s2

This answers (2 true) when it should answer either (2 false) or (1 true). The latter is the preferred answer.

--
You received this message because you are subscribed to a topic in the Google Groups "VA Smalltalk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/va-smalltalk/N9iodk_0r5w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to va-smalltalk...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.



--
Richard Sargent
Business Development Manager
[hidden email]
GemTalk Systems
15220 NW Greenbrier Parkway #240
Beaverton, OR 97006

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/groups/opt_out.