--- a/OrdColl.st Mon Oct 10 01:29:01 1994 +0100
+++ b/OrdColl.st Mon Oct 10 01:29:28 1994 +0100
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1989 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 @@
"
SequenceableCollection subclass:#OrderedCollection
- instanceVariableNames:'contentsArray firstIndex lastIndex'
- classVariableNames:''
- poolDictionaries:''
- category:'Collections-Sequenceable'
+ instanceVariableNames:'contentsArray firstIndex lastIndex'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Collections-Sequenceable'
!
OrderedCollection comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.15 1994-08-22 12:11:03 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.16 1994-10-10 00:27:12 claus Exp $
'!
!OrderedCollection class methodsFor:'documentation'!
@@ -29,7 +29,7 @@
copyright
"
COPYRIGHT (c) 1989 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/OrdColl.st,v 1.15 1994-08-22 12:11:03 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/OrdColl.st,v 1.16 1994-10-10 00:27:12 claus Exp $
"
!
@@ -90,6 +90,12 @@
!OrderedCollection methodsFor:'copying'!
+postCopyFrom:someOriginal
+ "have to copy the contentsArray too"
+
+ contentsArray := contentsArray shallowCopy
+!
+
, aCollection
"return a new collection formed from concatenating the receiver with
the argument"
@@ -97,12 +103,12 @@
|newCollection|
newCollection := self species new:(self size + aCollection size).
- newCollection finalizeCopyFrom:self.
+ newCollection postCopyFrom:self.
self do:[:element |
- newCollection add:element
+ newCollection add:element
].
aCollection do:[:element |
- newCollection add:element
+ newCollection add:element
].
^ newCollection
@@ -121,7 +127,7 @@
mySize := self size.
newSize := mySize + 1.
"/ newCollection := self species new:newSize.
- newCollection := (self species new:newSize) finalizeCopyFrom:self.
+ newCollection := (self species new:newSize) postCopyFrom:self.
newCollection grow:newSize.
newCollection replaceFrom:1 to:mySize with:self startingAt:1.
newCollection at:newSize put:newElement.
@@ -153,7 +159,7 @@
sz := stop - start + 1.
"/ newCollection := self species new:sz.
- newCollection := (self species new:sz) finalizeCopyFrom:self.
+ newCollection := (self species new:sz) postCopyFrom:self.
newCollection grow:sz.
newCollection replaceFrom:1 to:sz with:self startingAt:start.
^ newCollection
@@ -167,17 +173,16 @@
|anObject |
firstIndex > lastIndex ifTrue:[
- "error if collection is empty"
- self subscriptBoundsError.
- ^ nil
+ "error if collection is empty"
+ ^ self emptyCollectionError.
].
anObject := contentsArray at:firstIndex.
contentsArray at:firstIndex put:nil.
firstIndex := firstIndex + 1.
firstIndex > lastIndex ifTrue:[
- "reset to avoid ever growing"
- firstIndex := 1.
- lastIndex := 0
+ "reset to avoid ever growing"
+ firstIndex := 1.
+ lastIndex := 0
].
^ anObject
@@ -192,17 +197,16 @@
|anObject |
firstIndex > lastIndex ifTrue:[
- "error if collection is empty"
- self subscriptBoundsError.
- ^ nil
+ "error if collection is empty"
+ ^ self emptyCollectionError.
].
anObject := contentsArray at:lastIndex.
contentsArray at:lastIndex put:nil.
lastIndex := lastIndex - 1.
firstIndex > lastIndex ifTrue:[
- "reset to avoid ever growing"
- firstIndex := 1.
- lastIndex := 0
+ "reset to avoid ever growing"
+ firstIndex := 1.
+ lastIndex := 0
].
^ anObject
@@ -219,18 +223,18 @@
nDeleted := stopIndex - startIndex + 1.
contentsArray replaceFrom:(firstIndex + startIndex)
- to:(lastIndex - nDeleted)
- with:contentsArray
- startingAt:(firstIndex + stopIndex + 1).
+ to:(lastIndex - nDeleted)
+ with:contentsArray
+ startingAt:(firstIndex + stopIndex + 1).
contentsArray from:(lastIndex - nDeleted + 1)
- to:lastIndex
- put:nil.
+ to:lastIndex
+ put:nil.
lastIndex := lastIndex - nDeleted.
firstIndex > lastIndex ifTrue:[
- "reset to avoid ever growing"
- firstIndex := 1.
- lastIndex := 0
+ "reset to avoid ever growing"
+ firstIndex := 1.
+ lastIndex := 0
]
"
@@ -247,19 +251,19 @@
index := firstIndex.
[index <= lastIndex] whileTrue:[
- anObject = (contentsArray at:index) ifTrue:[
- contentsArray replaceFrom:index to:(contentsArray size - 1)
- with:contentsArray startingAt:(index + 1).
- contentsArray at:lastIndex put:nil.
- lastIndex := lastIndex - 1.
- firstIndex > lastIndex ifTrue:[
- "reset to avoid ever growing"
- firstIndex := 1.
- lastIndex := 0
- ].
- ^ anObject
- ].
- index := index + 1
+ anObject = (contentsArray at:index) ifTrue:[
+ contentsArray replaceFrom:index to:(contentsArray size - 1)
+ with:contentsArray startingAt:(index + 1).
+ contentsArray at:lastIndex put:nil.
+ lastIndex := lastIndex - 1.
+ firstIndex > lastIndex ifTrue:[
+ "reset to avoid ever growing"
+ firstIndex := 1.
+ lastIndex := 0
+ ].
+ ^ anObject
+ ].
+ index := index + 1
].
^ exceptionBlock value
!
@@ -275,7 +279,7 @@
Return the argument, anObject."
(lastIndex == contentsArray size) ifTrue:[
- self makeRoomAtLast
+ self makeRoomAtLast
].
lastIndex := lastIndex + 1.
contentsArray at:lastIndex put:anObject.
@@ -293,7 +297,7 @@
Return the argument, anObject."
(firstIndex == 1) ifTrue:[
- self makeRoomAtFront
+ self makeRoomAtFront
].
firstIndex := firstIndex - 1.
contentsArray at:firstIndex put:anObject.
@@ -337,7 +341,7 @@
idx := self indexOf:oldObject.
idx ~~ 0 ifTrue:[
- ^ self add:newObject beforeIndex:(idx + 1).
+ ^ self add:newObject beforeIndex:(idx + 1).
].
self errorNotFound
@@ -359,7 +363,7 @@
idx := self indexOf:oldObject.
idx ~~ 0 ifTrue:[
- ^ self add:newObject beforeIndex:idx.
+ ^ self add:newObject beforeIndex:idx.
].
self errorNotFound
@@ -379,15 +383,15 @@
|newContents oldLast|
newSize <= (lastIndex - firstIndex + 1) ifTrue:[
- oldLast := lastIndex.
- lastIndex := firstIndex + newSize - 1.
- contentsArray from:lastIndex + 1 to:oldLast put:nil.
+ oldLast := lastIndex.
+ lastIndex := firstIndex + newSize - 1.
+ contentsArray from:lastIndex + 1 to:oldLast put:nil.
] ifFalse:[
- newContents := Array new:newSize.
- newContents replaceFrom:1 to:(lastIndex - firstIndex + 1) with:contentsArray.
- contentsArray := newContents.
- firstIndex := 1.
- lastIndex := newSize
+ newContents := Array new:newSize.
+ newContents replaceFrom:1 to:(lastIndex - firstIndex + 1) with:contentsArray.
+ contentsArray := newContents.
+ firstIndex := 1.
+ lastIndex := newSize
]
! !
@@ -400,9 +404,9 @@
idx := anInteger + firstIndex - 1.
((anInteger < 1) or:[idx > lastIndex]) ifTrue:[
- self subscriptBoundsError
+ ^ self subscriptBoundsError:anInteger
] ifFalse:[
- ^ contentsArray at:idx
+ ^ contentsArray at:idx
]
!
@@ -413,9 +417,9 @@
idx := anInteger + firstIndex - 1.
((anInteger < 1) or:[idx > lastIndex]) ifTrue:[
- self subscriptBoundsError
+ ^ self subscriptBoundsError:anInteger
] ifFalse:[
- ^ contentsArray at:idx put:anObject
+ ^ contentsArray at:idx put:anObject
]
!
@@ -423,10 +427,10 @@
"return the first element"
firstIndex <= lastIndex ifTrue:[
- ^ contentsArray at:firstIndex
+ ^ contentsArray at:firstIndex
].
"error if collection is empty"
- self subscriptBoundsError
+ ^ self emptyCollectionError
"(OrderedCollection withAll:#(1 2 3 4 5)) first"
"(SortedCollection withAll:#(5 4 3 2 1)) first"
@@ -436,10 +440,10 @@
"return the last element"
firstIndex <= lastIndex ifTrue:[
- ^ contentsArray at:lastIndex
+ ^ contentsArray at:lastIndex
].
"error if collection is empty"
- self subscriptBoundsError
+ ^ self emptyCollectionError
"(OrderedCollection withAll:#(1 2 3 4 5)) last"
"(SortedCollection withAll:#(5 4 3 2 1)) last"
@@ -454,12 +458,12 @@
end := stop + firstIndex - 1.
((start >= 1) and:[end <= lastIndex]) ifTrue:[
- contentsArray
- replaceFrom:(start + firstIndex - 1)
- to:end
- with:aCollection
- startingAt:repStart.
- ^ self
+ contentsArray
+ replaceFrom:(start + firstIndex - 1)
+ to:end
+ with:aCollection
+ startingAt:repStart.
+ ^ self
].
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
! !
@@ -487,8 +491,8 @@
idx := self indexOf:anObject.
idx ~~ 0 ifTrue:[
- idx == lastIndex ifTrue:[^ nil].
- ^ self at:(idx + 1).
+ idx == lastIndex ifTrue:[^ nil].
+ ^ self at:(idx + 1).
].
^ exceptionBlock value
@@ -520,8 +524,8 @@
idx := self indexOf:anObject.
idx ~~ 0 ifTrue:[
- idx == firstIndex ifTrue:[^ nil].
- ^ self at:(idx - 1).
+ idx == firstIndex ifTrue:[^ nil].
+ ^ self at:(idx - 1).
].
^ exceptionBlock value
@@ -556,16 +560,16 @@
"if there is lots of room at the beginning (> 50%), shift instead of growing"
oldSize > (sz * 2) ifTrue:[
- startIndex := firstIndex // 4.
- contentsArray
- replaceFrom:startIndex
- to:startIndex + sz - 1
- with:contentsArray
- startingAt:firstIndex.
- contentsArray from:startIndex + sz to:lastIndex put:nil.
- firstIndex := startIndex.
- lastIndex := startIndex + sz - 1.
- ^ self
+ startIndex := firstIndex // 4.
+ contentsArray
+ replaceFrom:startIndex
+ to:startIndex + sz - 1
+ with:contentsArray
+ startingAt:firstIndex.
+ contentsArray from:startIndex + sz to:lastIndex put:nil.
+ firstIndex := startIndex.
+ lastIndex := startIndex + sz - 1.
+ ^ self
].
newSize := oldSize * 2.
newSize == 0 ifTrue:[ newSize := 1].
@@ -585,34 +589,34 @@
oldSize := contentsArray size.
oldSize == 0 ifTrue:[
- contentsArray := Array new:3.
- firstIndex := 2. lastIndex := 1.
- ^ self
+ 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"
oldSize > (sz * 2) ifTrue:[
- startIndex := oldSize // 4.
- contentsArray
- replaceFrom:startIndex
- to:startIndex + sz - 1
- with:contentsArray
- startingAt:1.
- contentsArray from:1 to:(startIndex - 1) put:nil.
- firstIndex := startIndex.
- lastIndex := startIndex + sz - 1.
- ^ self
+ startIndex := oldSize // 4.
+ contentsArray
+ replaceFrom:startIndex
+ to:startIndex + sz - 1
+ with:contentsArray
+ startingAt:1.
+ contentsArray from:1 to:(startIndex - 1) put:nil.
+ firstIndex := startIndex.
+ lastIndex := startIndex + sz - 1.
+ ^ self
].
newSize := oldSize * 2.
newSize == 0 ifTrue:[ newSize := 1].
newContents := Array new:newSize.
newContents
- replaceFrom:(oldSize + 1)
- to:newSize
- with:contentsArray
- startingAt:1.
+ replaceFrom:(oldSize + 1)
+ to:newSize
+ with:contentsArray
+ startingAt:1.
contentsArray := newContents.
firstIndex := firstIndex + oldSize.
lastIndex := lastIndex + oldSize
@@ -631,46 +635,46 @@
oldSize := contentsArray size.
((firstIndex > 1) and:[firstIndex > (oldSize // 4)]) ifTrue:[
- "there is room (>25%) at the beginning"
+ "there is room (>25%) at the beginning"
- index == 1 ifFalse:[
- contentsArray
- replaceFrom:(firstIndex - 1)
- to:(index - 1)
- with:contentsArray
- startingAt:firstIndex.
- contentsArray at:index put:nil.
- ].
- firstIndex := firstIndex - 1.
- ^ self
+ index == 1 ifFalse:[
+ contentsArray
+ replaceFrom:(firstIndex - 1)
+ to:(index - 1)
+ with:contentsArray
+ startingAt:firstIndex.
+ contentsArray at:index put:nil.
+ ].
+ firstIndex := firstIndex - 1.
+ ^ self
].
lastIndex < (oldSize * 3 // 4) ifTrue:[
- "there is room (>25%) at the end"
+ "there is room (>25%) at the end"
- index == (lastIndex + 1) ifFalse:[
- contentsArray
- replaceFrom:(index + 1)
- to:(lastIndex + 1)
- with:contentsArray
- startingAt:index.
- contentsArray at:index put:nil
- ].
- lastIndex := lastIndex + 1.
- ^ self
+ index == (lastIndex + 1) ifFalse:[
+ contentsArray
+ replaceFrom:(index + 1)
+ to:(lastIndex + 1)
+ with:contentsArray
+ startingAt:index.
+ contentsArray at:index put:nil
+ ].
+ lastIndex := lastIndex + 1.
+ ^ self
].
newSize := oldSize * 2.
newContents := Array new:newSize.
index == 1 ifFalse:[
- newContents replaceFrom:1 to:index-1
- with:contentsArray startingAt:1.
+ newContents replaceFrom:1 to:index-1
+ with:contentsArray startingAt:1.
].
index == newSize ifFalse:[
- newContents
- replaceFrom:index + 1
- to:oldSize + 1
- with:contentsArray
- startingAt:index.
+ newContents
+ replaceFrom:index + 1
+ to:oldSize + 1
+ with:contentsArray
+ startingAt:index.
].
contentsArray := newContents.
lastIndex := lastIndex + 1
@@ -746,7 +750,7 @@
"could be an instance of a subclass..."
self class == OrderedCollection ifTrue:[
- ^ self
+ ^ self
].
^ super asOrderedCollection
! !
@@ -776,7 +780,7 @@
stop := lastIndex.
start := firstIndex.
start to:stop do:[:index |
- aTwoArgBlock value:index value:(contentsArray at:index)
+ aTwoArgBlock value:index value:(contentsArray at:index)
]
!
@@ -789,11 +793,11 @@
stop "{ Class:SmallInteger }" |
"/ newCollection := (self species new).
- newCollection := (self species new) finalizeCopyFrom:self.
+ newCollection := (self species new) postCopyFrom:self.
stop := lastIndex.
start := firstIndex.
start to:stop do:[:index |
- newCollection add:(aBlock value:(contentsArray at:index)).
+ newCollection add:(aBlock value:(contentsArray at:index)).
].
^ newCollection
! !
@@ -805,9 +809,9 @@
(instead of the default InspectorView)."
OrderedCollectionInspectorView isNil ifTrue:[
- super inspect
+ super inspect
] ifFalse:[
- OrderedCollectionInspectorView openOn:self
+ OrderedCollectionInspectorView openOn:self
]
"(OrderedCollection withAll:#(3 2 1)) inspect"