[BUG]Collection>>removeAll:
Brian Keefer
squeak-dev at lists.squeakfoundation.org
Mon Sep 9 19:10:40 UTC 2002
This is a multi-part message in MIME format.
--------------A16C321C6C18B0408FF3D2A1
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
"Richard A. O'Keefe" wrote:
>
> In reply to Brian Keefer <mgomes21 at cox.net>:
> This version (too many versions for such a simple thing!) follows the
> fixes reccommended by Mr. O'Keefe. I'm even going along with the #=
> sentinel comparison in removeOccurancesOf:.
>
> There is no "a" in "occurrences".
Oops. I'll also throw an extra $r in there, just to be safe. May this
thread R.I.P.
--------------A16C321C6C18B0408FF3D2A1
Content-Type: text/plain; charset=us-ascii;
name="YA removeAll: fix .6.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="YA removeAll: fix .6.cs"
'From Squeak3.2gamma of 15 January 2002 [latest update: #4881] on 9 September 2002 at 3:03:33 pm'!
!OrderedCollection methodsFor: 'removing' stamp: 'bmk 9/9/2002 15:03'!
removeAll: aCollection
|removalSet sentinel|
removalSet:= aCollection as: Bag. "#asBag is unfriendly to streams"
sentinel:= Object new.
self withIndexDo: [:value :index|
(removalSet includes:value) ifTrue:[
self at:index put:sentinel.
].
].
self removeOccurrencesOf:sentinel.
^aCollection. "don't know why. Nobody wants it"! !
!OrderedCollection methodsFor: 'removing' stamp: 'bmk 9/9/2002 09:51'!
removeOccurrencesOf: sentinel "Though this was made with consideration towards sentinels, any regular container member could be sent. It just reads better using the name sentinel than anItem. What would ``valueOrAnItem'' mean?"
|valuesOnlyIndex|
valuesOnlyIndex:= 1.
self withIndexDo: [:valueOrSentinel :valuesOrSentinelsIndex| "VOSIndex unnecessary"
sentinel = valueOrSentinel ifFalse:[ "As long as sentinel class -> Object, #= means #==."
self at:valuesOnlyIndex put: valueOrSentinel.
valuesOnlyIndex := valuesOnlyIndex + 1.
].
].
self truncate:valuesOnlyIndex - 1
! !
!OrderedCollection methodsFor: 'removing' stamp: 'bmk 9/5/2002 15:45'!
truncate:aSize
|newLastIndex|
aSize > self size ifTrue:[ self error: 'cannot truncate larger']
ifFalse:[
newLastIndex := firstIndex+aSize-1.
newLastIndex+1 to: lastIndex do: [:position| array at: position put: nil].
lastIndex := newLastIndex]! !
--------------A16C321C6C18B0408FF3D2A1--
More information about the Squeak-dev
mailing list
|