OrdColl.st
changeset 329 f14fc5ac11b7
parent 293 31df3850e98c
child 345 cf2301210c47
--- a/OrdColl.st	Mon May 01 23:30:32 1995 +0200
+++ b/OrdColl.st	Mon May 01 23:40:01 1995 +0200
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.22 1995-03-06 19:17:25 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.23 1995-05-01 21:38:19 claus Exp $
 '!
 
 !OrderedCollection class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.22 1995-03-06 19:17:25 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.23 1995-05-01 21:38:19 claus Exp $
 "
 !
 
@@ -192,6 +192,7 @@
     anObject := contentsArray at:firstIndex.
     contentsArray at:firstIndex put:nil.
     firstIndex := firstIndex + 1.
+
     firstIndex > lastIndex ifTrue:[
 	"reset to avoid ever growing"
 	firstIndex := 1.
@@ -216,6 +217,7 @@
     anObject := contentsArray at:lastIndex.
     contentsArray at:lastIndex put:nil.
     lastIndex := lastIndex - 1.
+
     firstIndex > lastIndex ifTrue:[
 	"reset to avoid ever growing"
 	firstIndex := 1.
@@ -235,13 +237,16 @@
     |nDeleted|
 
     nDeleted := stopIndex - startIndex + 1.
-    contentsArray replaceFrom:(firstIndex + startIndex - 1)
-			   to:(lastIndex - nDeleted)
-			 with:contentsArray 
-		   startingAt:(firstIndex + stopIndex).
-    contentsArray from:(lastIndex - nDeleted + 1)
-		    to:lastIndex
-		   put:nil.
+    contentsArray 
+	replaceFrom:(firstIndex + startIndex - 1)
+	to:(lastIndex - nDeleted)
+	with:contentsArray 
+	startingAt:(firstIndex + stopIndex).
+
+    contentsArray
+	from:(lastIndex - nDeleted + 1)
+	to:lastIndex
+	put:nil.
 
     lastIndex := lastIndex - nDeleted.
     firstIndex > lastIndex ifTrue:[
@@ -265,8 +270,11 @@
     index := firstIndex.
     [index <= lastIndex] whileTrue:[
 	anObject = (contentsArray at:index) ifTrue:[
-	    contentsArray replaceFrom:index to:(contentsArray size - 1)
-			    with:contentsArray startingAt:(index + 1).
+	    contentsArray 
+		replaceFrom:index
+		to:(contentsArray size - 1)
+		with:contentsArray 
+		startingAt:(index + 1).
 	    contentsArray at:lastIndex put:nil.
 	    lastIndex := lastIndex - 1.
 	    firstIndex > lastIndex ifTrue:[
@@ -651,7 +659,11 @@
     oldSize := contentsArray size.
     sz := lastIndex - firstIndex + 1.
 
-    "if there is lots of room at the beginning (> 50%), shift instead of growing"
+    "
+     if there is lots of room at the beginning (> 50%), 
+     shift instead of growing. This helps collections which get
+     elements removed at front and added at the end.
+    "
     oldSize > (sz * 2) ifTrue:[
 	startIndex := firstIndex // 4.
 	contentsArray 
@@ -665,9 +677,13 @@
 	^ self
     ].
     newSize := oldSize * 2.
-    newSize == 0 ifTrue:[ newSize := 1].
+    newSize == 0 ifTrue:[newSize := 3].
     newContents := Array basicNew:newSize.
-    newContents replaceFrom:1 to:oldSize with:contentsArray.
+    newContents 
+	replaceFrom:1 
+	to:oldSize 
+	with:contentsArray
+	startingAt:1.
     contentsArray := newContents
 !
 
@@ -692,7 +708,11 @@
 
     sz := lastIndex - firstIndex + 1.
 
-    "if there is lots of room at the end (> 50%), shift instead of growing"
+    "
+     if there is lots of room at the end (> 50%), 
+     shift instead of growing. This helps collections
+     which get elements removed at the end and added at front.
+    "
     oldSize > (sz * 2) ifTrue:[
 	startIndex := oldSize // 4.
 	contentsArray
@@ -706,7 +726,7 @@
 	^ self
     ].
     newSize := oldSize * 2.
-    newSize == 0 ifTrue:[ newSize := 1].
+    newSize == 0 ifTrue:[ newSize := 3].
     newContents := Array basicNew:newSize.
     newContents
 	replaceFrom:(oldSize + 1)
@@ -762,11 +782,14 @@
 
     newSize := oldSize * 2.
     newContents := Array basicNew:newSize.
-    index == 1 ifFalse:[
-	newContents replaceFrom:1 to:index-1 
-			   with:contentsArray startingAt:1.
+    index ~~ 1 ifTrue:[
+	newContents 
+	    replaceFrom:1 
+	    to:index-1 
+	    with:contentsArray
+	    startingAt:1.
     ].
-    index == newSize ifFalse:[
+    index ~~ newSize ifTrue:[
 	newContents
 	    replaceFrom:index + 1
 	    to:oldSize + 1