[BUG]Collection>>removeAll:
Torge Husfeldt
Torge.Husfeldt at gmx.de
Fri Sep 6 12:11:10 UTC 2002
Brian,
If i still can read this last version reintroduces the slack problem?!
One more point: do you really think dowithindex would be so problematic?
Just my two cents,
Torge
Brian Keefer wrote:
>
> For the love of traffic, here is another exciting release. Now removeAll:
> provides even more exciting features, like not breaking image saving. I
> swear, this is just 2 versions away from MilSpec.
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> 'From Squeak3.2gamma of 15 January 2002 [latest update: #4881] on 5 September 2002 at 8:06:36 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 20:03'!
> 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
|