Date: April 21, 2008 8:48:48 PM EDT
Subject: Otago academic download of Cincom Smalltalk vw7.5nc
Name: Dr Richard A. O'Keefe
Org: Computer Science Department, The University of Otago
Web: http://www.cs.otago.ac.nz/
E-mail: [hidden email]
There seems to be a bug in Collection>>groupedBy:
If the collection being grouped is "pluggable", as SortedCollection is,
the instance variables of the receiver are not copied to the new
collections. In the case of SortedCollection, this results in the
new collections being sorted the wrong way. Here is a simple example:
a := SortedCollection withAll: (1 to: 20) sortBlock: [:x :y | x >= y].
"PrintIt shows
SortedCollection (20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1)"
a groupedBy: [:x | x \\ 4]
"PrintIt shows
Dictionary (0 -> SortedCollection (4 8 12 16 20)
1 -> SortedCollection (1 5 9 13 17)
2 -> SortedCollection (2 6 10 14 18)
3 -> SortedCollection (3 7 11 15 19))"
It's possible to fix this case by adding
SortedCollection>>
groupedBy: keyBlock
"Same as Collection>>groupedBy: but converts the subcollections
to collections just like the receiver, including sortblock."
| result |
result := Dictionary new.
self do: [:each |
(result at: (keyBlock value: each)
ifAbsentPut: [OrderedCollection new]
) addLast: each].
result keysAndValuesDo: [:key :value |
result at: key put: (
(self copyEmpty: value size) addAll: value; yourself)].
^result
Presumably other collection types may be affected as well.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc