[BUG]Collection>>removeAll:
Brian Keefer
squeak-dev at lists.squeakfoundation.org
Sun Sep 1 05:39:14 UTC 2002
This is a multi-part message in MIME format.
--------------A58D867545941E75C5C9B40D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
> The specific instance of removeAll: and it's close relatives is not
> terrifically interesting. I'm sure we could solve it by some means
> involving sticking appropriate nulls in the removed places and cleaning
> up at the end of the operation, in a manner analogous to the tricks used
> to save redisplayingthe Display on every little draw. Or something
> equally trivial.
Trivial is good. Attached is my little sliver of understanding about the
problem. One other little quandry I came by in trying this is
foo:= #(1 2 3) asOrderedCollection.
foo add: foo.
foo asBag. "Boom. Stack all over the place, children crying, etc."
--------------A58D867545941E75C5C9B40D
Content-Type: text/plain; charset=us-ascii;
name="removeAll: fix.1.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="removeAll: fix.1.cs"
'From Squeak3.2gamma of 15 January 2002 [latest update: #4881] on 1 September 2002 at 1:15:12 am'!
!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 01:12'!
removeAll: aCollection
|removalSet sentinel|
removalSet:= aCollection asBag.
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
! !
--------------A58D867545941E75C5C9B40D--
More information about the Squeak-dev
mailing list
|