[BUG]Collection>>removeAll:
Brian Keefer
mgomes21 at cox.net
Thu Sep 5 21:38:49 UTC 2002
Just one last nit to fix with my little exercise of "what would a
programming Pooh Bear do?"
-------------- next part --------------
'From Squeak3.2gamma of 15 January 2002 [latest update: #4881] on 5 September 2002 at 5:15:33 pm'!
!OrderedCollection methodsFor: 'adding' 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]! !
!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/5/2002 15:47'!
squeegee: sentinel "remove all instances of the sentinel, and squish down the array"
|tightIndex|
tightIndex := firstIndex.
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
|