fix topologicalSort:
authorStefan Vogel <sv@exept.de>
Mon, 15 Jan 1996 18:09:30 +0100
changeset 862 007dccfb6cb0
parent 861 2b4dc0a4f65a
child 863 2c83fe958ca7
fix topologicalSort:
SeqColl.st
SequenceableCollection.st
--- a/SeqColl.st	Mon Jan 15 15:12:46 1996 +0100
+++ b/SeqColl.st	Mon Jan 15 18:09:30 1996 +0100
@@ -11,10 +11,10 @@
 "
 
 Collection subclass:#SequenceableCollection
-	 instanceVariableNames:''
-	 classVariableNames:''
-	 poolDictionaries:''
-	 category:'Collections-Abstract'
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Collections-Abstract'
 !
 
 !SequenceableCollection class methodsFor:'documentation'!
@@ -2348,22 +2348,37 @@
     "this is just a q&d hack - there must be better implementations for this ;-)"
 
     end := self size.
-    1 to:end do:[:index |
-	smallest := self at:index.
-	smallestIndex := index.
-
-	(index + 1) to:end do:[:index2 |
-	    thisOne := self at:index2.
-	    (sortBlock value:thisOne value:smallest) ifTrue:[
-		smallestIndex := index2.
-		smallest := thisOne
-	    ].
-	].
-	(smallestIndex ~~ index) ifTrue:[
-	    thisOne := self at:index.
-	    self at:index put:smallest.
-	    self at:smallestIndex put:thisOne
-	].
+    1 to:end-1 do:[:index |
+        |index2|
+
+        smallest := self at:index.
+        smallestIndex := index.
+
+        index2 := index + 1.
+        [
+            thisOne := self at:index2.
+            (index2 ~~ smallestIndex and:[(sortBlock value:thisOne value:smallest)]) ifTrue:[
+                smallestIndex := index2.
+                smallest := thisOne.
+                index2 := index + 1.
+            ] ifFalse:[
+                index2 := index2 + 1..
+            ].
+            index2 <= end
+        ] whileTrue.
+
+"/        (index + 1) to:end do:[:index2 |
+"/            thisOne := self at:index2.
+"/            (sortBlock value:thisOne value:smallest) ifTrue:[
+"/                smallestIndex := index2.
+"/                smallest := thisOne
+"/            ].
+"/        ].
+        (smallestIndex ~~ index) ifTrue:[
+            thisOne := self at:index.
+            self at:index put:smallest.
+            self at:smallestIndex put:thisOne
+        ].
     ]
 
     "
@@ -2377,5 +2392,5 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.43 1995-11-23 16:58:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.44 1996-01-15 17:09:30 sv Exp $'
 ! !
--- a/SequenceableCollection.st	Mon Jan 15 15:12:46 1996 +0100
+++ b/SequenceableCollection.st	Mon Jan 15 18:09:30 1996 +0100
@@ -11,10 +11,10 @@
 "
 
 Collection subclass:#SequenceableCollection
-	 instanceVariableNames:''
-	 classVariableNames:''
-	 poolDictionaries:''
-	 category:'Collections-Abstract'
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Collections-Abstract'
 !
 
 !SequenceableCollection class methodsFor:'documentation'!
@@ -2348,22 +2348,37 @@
     "this is just a q&d hack - there must be better implementations for this ;-)"
 
     end := self size.
-    1 to:end do:[:index |
-	smallest := self at:index.
-	smallestIndex := index.
-
-	(index + 1) to:end do:[:index2 |
-	    thisOne := self at:index2.
-	    (sortBlock value:thisOne value:smallest) ifTrue:[
-		smallestIndex := index2.
-		smallest := thisOne
-	    ].
-	].
-	(smallestIndex ~~ index) ifTrue:[
-	    thisOne := self at:index.
-	    self at:index put:smallest.
-	    self at:smallestIndex put:thisOne
-	].
+    1 to:end-1 do:[:index |
+        |index2|
+
+        smallest := self at:index.
+        smallestIndex := index.
+
+        index2 := index + 1.
+        [
+            thisOne := self at:index2.
+            (index2 ~~ smallestIndex and:[(sortBlock value:thisOne value:smallest)]) ifTrue:[
+                smallestIndex := index2.
+                smallest := thisOne.
+                index2 := index + 1.
+            ] ifFalse:[
+                index2 := index2 + 1..
+            ].
+            index2 <= end
+        ] whileTrue.
+
+"/        (index + 1) to:end do:[:index2 |
+"/            thisOne := self at:index2.
+"/            (sortBlock value:thisOne value:smallest) ifTrue:[
+"/                smallestIndex := index2.
+"/                smallest := thisOne
+"/            ].
+"/        ].
+        (smallestIndex ~~ index) ifTrue:[
+            thisOne := self at:index.
+            self at:index put:smallest.
+            self at:smallestIndex put:thisOne
+        ].
     ]
 
     "
@@ -2377,5 +2392,5 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.43 1995-11-23 16:58:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.44 1996-01-15 17:09:30 sv Exp $'
 ! !