OrderedCollection.st
changeset 93 e31220cb391f
parent 88 81dacba7a63a
child 114 0353ec6749c8
--- a/OrderedCollection.st	Fri Aug 05 02:55:07 1994 +0200
+++ b/OrderedCollection.st	Fri Aug 05 02:59:40 1994 +0200
@@ -20,6 +20,8 @@
 OrderedCollection comment:'
 COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
+
+$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.14 1994-08-05 00:59:17 claus Exp $
 '!
 
 !OrderedCollection class methodsFor:'documentation'!
@@ -40,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.13 1994-06-02 16:21:11 claus Exp $
+$Header: /cvs/stx/stx/libbasic/OrderedCollection.st,v 1.14 1994-08-05 00:59:17 claus Exp $
 "
 !
 
@@ -95,6 +97,7 @@
     |newCollection|
 
     newCollection := self species new:(self size + aCollection size).
+    newCollection finalizeCopyFrom:self.
     self do:[:element |
         newCollection add:element
     ].
@@ -103,7 +106,10 @@
     ].
     ^ newCollection
 
-    "#(1 2 3) asOrderedCollection , #(4 5 6) asOrderedCollection"
+    "
+     #(1 2 3) asOrderedCollection , #(4 5 6) asOrderedCollection
+     #(1 2 3) asSortedCollection , #(99 101 100) asSortedCollection
+    "
 !
 
 copyWith:newElement
@@ -114,16 +120,19 @@
 
     mySize := self size.
     newSize := mySize + 1.
-    newCollection := self species new:newSize.
+"/    newCollection := self species new:newSize.
+    newCollection := (self species new:newSize) finalizeCopyFrom:self.
     newCollection grow:newSize.
     newCollection replaceFrom:1 to:mySize with:self startingAt:1.
     newCollection at:newSize put:newElement.
     ^newCollection
 
-    "#(1 2 3 4 5) copyWith:$a"
-    "'abcdefg' copyWith:$h"
-    "'abcdefg' copyWith:'123'"  "-- will fail: string cannot be stored into string"
-    "'abcdefg' copyWith:1"      "-- will fail: integer cannot be stored into string"
+    "
+     #(1 2 3 4 5) copyWith:$a
+     'abcdefg' copyWith:$h
+     'abcdefg' copyWith:'123'    -- will fail: string cannot be stored into string
+     'abcdefg' copyWith:1        -- will fail: integer cannot be stored into string
+    "
 !
 
 copy
@@ -143,7 +152,8 @@
     |newCollection sz|
 
     sz := stop - start + 1.
-    newCollection := self species new:sz.
+"/    newCollection := self species new:sz.
+    newCollection := (self species new:sz) finalizeCopyFrom:self.
     newCollection grow:sz.
     newCollection replaceFrom:1 to:sz with:self startingAt:start.
     ^ newCollection
@@ -285,8 +295,16 @@
 
     "
      |c|
-     c := #(4 3 2 1) asOrderedCollection.
-     c addFirst:'here'
+     c := #(1 2 3 4) asOrderedCollection.
+     c addFirst:'here'.
+     c
+    "
+
+    "
+     |c|
+     c := #() asOrderedCollection.
+     c addFirst:'here'.
+     c
     "
 !
 
@@ -560,6 +578,12 @@
      sz         "{ Class:SmallInteger }"|
 
     oldSize := contentsArray size.
+    oldSize == 0 ifTrue:[ 
+        contentsArray := Array new:3.
+        firstIndex := 2. lastIndex := 1.
+        ^ self
+    ].
+
     sz := self size.
 
     "if there is lots of room at the end (> 50%), shift instead of growing"
@@ -758,7 +782,8 @@
      start  "{ Class:SmallInteger }"
      stop   "{ Class:SmallInteger }" |
 
-    newCollection := (self species new).
+"/    newCollection := (self species new).
+    newCollection := (self species new) finalizeCopyFrom:self.
     stop := lastIndex.
     start := firstIndex.
     start to:stop do:[:index |