[BUG]Collection>>removeAll:
Brian Keefer
mgomes21 at cox.net
Sun Sep 1 21:46:54 UTC 2002
Wim Boot wrote:
>
> Richard,
>
> >By the way, if there _is_ a process for amending the Smalltalk
> >standard, I am very pleased to hear it. Who do I write to? What
> >is the process?
>
> If you propose a change here, could you make sure that the
> following code also works?
>
> | c |
> c := #(1 2 3) asOrderedCollection.
> c removeAll: c readStream.
>
> Wim Boot
It works in my little CS (with one tiny change). Is there any guide as to
when to use (recv asFoo) or (recv as: Foo)?
The one thing that's missing is the exception for when the removal set has
an element not in #removeAll:'s reciever.
-------------- next part --------------
'From Squeak3.2gamma of 15 January 2002 [latest update: #4881] on 1 September 2002 at 5:04:54 pm'!
!OrderedCollection methodsFor: 'adding' stamp: 'bmk 9/1/2002 00:57'!
truncate:aSize
aSize > self size ifTrue:[ self error: 'ENOTPOSIX']
ifFalse:[lastIndex := firstIndex+aSize-1]! !
!OrderedCollection methodsFor: 'removing' stamp: 'bmk 9/1/2002 17:04'!
removeAll: aCollection
|removalSet sentinel|
removalSet := aCollection as: Bag. "#asBag is unfriendly to streams"
sentinel := Object new.
1 to: self size do:[:index|
(removalSet includes:(self at:index)) ifTrue:[
self at:index put:sentinel
].
].
self squeegee:sentinel.
^aCollection. "don't know why. Nobody wants it"! !
!OrderedCollection methodsFor: 'removing' stamp: 'bmk 9/1/2002 01:00'!
squeegee: sentinel "remove all instances of the sentinel, and squish down the array"
|tightIndex|
tightIndex := 1.
1 to: self size do: [:fluffedIndex| "probably safer to manually iterate here than trust #do:"
(self at: fluffedIndex) == sentinel ifFalse:[
self at:tightIndex put: (self at:fluffedIndex).
tightIndex := tightIndex+1.
].
].
self truncate:tightIndex -1
! !
More information about the Squeak-dev
mailing list
|