Mantis - Squeak
Viewing Issue Advanced Details
6943 Collections minor always 02-21-08 21:18 02-06-11 23:48
nicolas cellier  
nicolas cellier  
normal  
closed 3.10  
fixed  
none    
none trunk  
0006943: Heap equality should be associative
"This example shows that equality is not associative"

    | anArray heap1 heap2 |
    anArray := #(1 2 3).
    heap1 := Heap withAll: (1 to: 3) sortBlock: [:a :b | a < b].
    heap2 := Heap withAll: (1 to: 3) sortBlock: [:a :b | b > a].
    self assert: (heap1 = anArray) & (heap2 = anArray) ==> (heap1 = heap2)

Heaps do compare their sortBlock.
They are more relax when comparing with their species.

This does happen since their species is Array...
http://lists.squeakfoundation.org/pipermail/squeak-dev/2000-March/011043.html [^]

As noted by Klaus Witzel, why did species change?
Correcting which bug?
 Heap-Equality-IsNotAssociative-M6943-Test.1.cs [^] (733 bytes) 02-21-08 21:28
 M6943-Heap-Equality-IsNotTransitive-Fix .1.cs [^] (831 bytes) 08-21-10 14:03

Notes
(0011858)
nicolas cellier   
02-21-08 22:12   
I'm loosing my maths, #= should be an equivalence relation,

  reflexive, self assert: (a = a),
  symmetric, self assert: (a = b) ==> (b = a),
  transitive, self assert: (a = b) & (b = c) ==> (a = c)

Yes Transitive rather than Associative...
(0013836)
nicolas cellier   
08-21-10 14:07   
The fix makes Heap behave like a SortedCollection:
1) re-establish the Heap species -> Heap.
2) collect: does collect:as: Array because there is no guarantee the sortBlock works after transformation
3) select: use #copyEmpty strategy (like OrderedCollection)

Beware of load order, a Heap is used in your morphic world...
(0013837)
nicolas cellier   
08-21-10 15:47   
http://source.squeak.org/trunk/Collections-nice.370.mcz [^]
http://source.squeak.org/trunk/CollectionsTests-nice.170.mcz [^]