SortColl.st
changeset 159 514c749165c3
parent 95 d22739a0c6e9
child 184 d795f0b1934a
--- a/SortColl.st	Mon Oct 10 01:29:01 1994 +0100
+++ b/SortColl.st	Mon Oct 10 01:29:28 1994 +0100
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -11,17 +11,17 @@
 "
 
 OrderedCollection subclass:#SortedCollection
-         instanceVariableNames:'sortBlock'
-         classVariableNames:'DefaultSortBlock'
-         poolDictionaries:''
-         category:'Collections-Ordered'
+	 instanceVariableNames:'sortBlock'
+	 classVariableNames:'DefaultSortBlock'
+	 poolDictionaries:''
+	 category:'Collections-Sequenceable'
 !
 
 SortedCollection comment:'
 COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Attic/SortColl.st,v 1.10 1994-08-05 01:02:42 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/SortColl.st,v 1.11 1994-10-10 00:28:38 claus Exp $
 '!
 
 !SortedCollection class methodsFor:'documentation'!
@@ -29,7 +29,7 @@
 copyright
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Attic/SortColl.st,v 1.10 1994-08-05 01:02:42 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/SortColl.st,v 1.11 1994-10-10 00:28:38 claus Exp $
 "
 !
 
@@ -136,24 +136,24 @@
     mySize := self size.
     otherSize := aCollection size.
     ((mySize == 0) or:[otherSize > 5]) ifTrue:[
-        newSize := mySize + otherSize.
-        newContents := Array new:newSize.
-        newContents replaceFrom:1 to:mySize with:contentsArray startingAt:1.
-        aCollection isSequenceableCollection ifTrue:[
-            "maybe we can do it in one big move"
-            newContents replaceFrom:(mySize + 1) to:newSize with:aCollection startingAt:1.
-        ] ifFalse:[
-            dstIndex := mySize + 1.
-            aCollection do:[:element |
-                newContents at:dstIndex put:element.
-                dstIndex := dstIndex + 1
-            ]
-        ].
-        firstIndex := 1.
-        lastIndex := newSize.
-        contentsArray := newContents.
-        contentsArray sort:sortBlock.
-        ^ self
+	newSize := mySize + otherSize.
+	newContents := Array new:newSize.
+	newContents replaceFrom:1 to:mySize with:contentsArray startingAt:1.
+	aCollection isSequenceableCollection ifTrue:[
+	    "maybe we can do it in one big move"
+	    newContents replaceFrom:(mySize + 1) to:newSize with:aCollection startingAt:1.
+	] ifFalse:[
+	    dstIndex := mySize + 1.
+	    aCollection do:[:element |
+		newContents at:dstIndex put:element.
+		dstIndex := dstIndex + 1
+	    ]
+	].
+	firstIndex := 1.
+	lastIndex := newSize.
+	contentsArray := newContents.
+	contentsArray sort:sortBlock.
+	^ self
     ].
     super addAll:aCollection
 
@@ -169,11 +169,11 @@
     |index|
 
     lastIndex < firstIndex "i.e. self size == 0" ifTrue:[
-        super add:anObject
+	super add:anObject
     ] ifFalse:[
-        index := self indexForInserting:anObject. 
-        self makeRoomAtIndex:index.
-        contentsArray at:index put:anObject
+	index := self indexForInserting:anObject. 
+	self makeRoomAtIndex:index.
+	contentsArray at:index put:anObject
     ].
     ^ anObject
 
@@ -186,17 +186,18 @@
 
 !SortedCollection methodsFor:'copying'!
 
-finalizeCopyFrom:aSortedCollection
-    "sent after a deepCopy or when a new collection species has been created.
+postCopyFrom:anOriginal
+    "sent after a copy or when a new collection species has been created.
      The new collection should have the same sortBlock as the original."
 
-    sortBlock := aSortedCollection sortBlock
+    sortBlock := anOriginal sortBlock
 
     "
      #(4 7 1 99 -1 17) asSortedCollection inspect
-     #(4 7 1 99 -1 17) asSortedCollection deepCopy inspect
+     #(4 7 1 99 -1 17) asSortedCollection copy inspect
      (#(4 7 1 99 -1 17) asSortedCollection sortBlock:[:a :b | a > b]) inspect
-     (#(4 7 1 99 -1 17) asSortedCollection sortBlock:[:a :b | a > b]) deepCopy inspect
+     (#(4 7 1 99 -1 17) asSortedCollection sortBlock:[:a :b | a > b]) copy inspect
+     (#(4 7 1 99 -1 17) asSortedCollection select:[:e| e even]) inspect
     "
 ! !
 
@@ -207,7 +208,7 @@
 
     "could be an instance of a subclass..."
     self class == SortedCollection ifTrue:[
-        ^ self
+	^ self
     ].
     ^ super asSortedCollection
 ! !
@@ -244,8 +245,8 @@
 
     tally := 0.
     [(index <= lastIndex) and:[(contentsArray at:index) = anObject]] whileTrue:[
-        tally := tally + 1.
-        index := index + 1
+	tally := tally + 1.
+	index := index + 1
     ].
     ^ tally
 
@@ -262,7 +263,7 @@
     "return the element before the argument, anObject; or nil if there is none.
      If the receiver does not contain anObject, report an error"
 
-    ^ self before:anObject ifAbsent:[self error:'no such element']
+    ^ self before:anObject ifAbsent:[self errorNotFound]
 
     "
      #(7 3 9 10 99) asSortedCollection before:50
@@ -304,7 +305,7 @@
     "return the element after the argument, anObject; or nil if there is none.
      If the receiver does not contain anObject, report an error"
 
-    ^ self after:anObject ifAbsent:[self error:'no such element']
+    ^ self after:anObject ifAbsent:[self errorNotFound]
 
     "
      #(7 3 9 10 99) asSortedCollection after:50
@@ -331,7 +332,7 @@
     "skip multiple occurences of the same ..."
 
     [(index <= lastIndex) and:[(contentsArray at:index) = anObject]] whileTrue:[
-        index := index + 1
+	index := index + 1
     ].
     (index > lastIndex) ifTrue:[^ nil].
     ^ contentsArray at:index
@@ -353,7 +354,7 @@
 
     sortBlock := aSortBlock.
     lastIndex > firstIndex ifTrue:[
-        contentsArray quickSortFrom:firstIndex to:lastIndex sortBlock:aSortBlock
+	contentsArray quickSortFrom:firstIndex to:lastIndex sortBlock:aSortBlock
     ]
 
     "
@@ -391,14 +392,14 @@
     low := firstIndex.
     high := lastIndex.
     [low <= high] whileTrue:[
-        middle := (low + high) // 2.
-        element := contentsArray at:middle.
-        (sortBlock value:element value:anObject) ifTrue:[
-            "middleelement is smaller than object"
-            low := middle + 1
-        ] ifFalse:[
-            high := middle - 1
-        ]
+	middle := (low + high) // 2.
+	element := contentsArray at:middle.
+	(sortBlock value:element value:anObject) ifTrue:[
+	    "middleelement is smaller than object"
+	    low := middle + 1
+	] ifFalse:[
+	    high := middle - 1
+	]
     ].
     ^ low