[squeak-dev] The Inbox: Collections-dtl.931.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Fri Mar 12 09:06:46 UTC 2021


+1 !! :-) Thanks!
Am 11.03.2021 23:49:54 schrieb David T. Lewis <lewis at mail.msen.com>:
Every once in a while I find myself hunting around to locate the
basic set operations. These should be simple and obvious so I think
they deserve their own method category.

I also added the trivial implementation of #symmetricDifference: because
it seemed to be inexplicably missing. Most likely this would benefit from
optimization, but the simple implementation is readable and actually
looks symmetric, so it seems like a good start.

OK to move to trunk?

Dave


On Thu, Mar 11, 2021 at 10:44:44PM +0000, commits at source.squeak.org wrote:
> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-dtl.931.mcz
>
> ==================== Summary ====================
>
> Name: Collections-dtl.931
> Author: dtl
> Time: 11 March 2021, 5:44:43.577146 pm
> UUID: 1ed239e3-d108-43c3-8b6e-de8c43d842d1
> Ancestors: Collections-nice.930
>
> Set logic methods should be discoverable, so give them a method category. Add an implementation of Collection>>symmetricDifference: so that the basic set operations of union, intersection, difference, and symmetric difference are available.
>
> =============== Diff against Collections-nice.930 ===============
>
> Item was changed:
> + ----- Method: Collection>>difference: (in category 'set logic') -----
> - ----- Method: Collection>>difference: (in category 'enumerating') -----
> difference: aCollection
> "Answer the set theoretic difference of two collections."
>
> ^ self reject: [:each | aCollection includes: each]!
>
> Item was changed:
> + ----- Method: Collection>>intersection: (in category 'set logic') -----
> - ----- Method: Collection>>intersection: (in category 'enumerating') -----
> intersection: aCollection
> "Answer the set theoretic intersection of two collections."
>
> ^ self select: [:each | aCollection includes: each]!
>
> Item was added:
> + ----- Method: Collection>>symmetricDifference: (in category 'set logic') -----
> + symmetricDifference: aCollection
> + "Answer the set theoretic symmetric difference of two collections."
> +
> + ^ (self difference: aCollection) union: (aCollection difference: self)
> + !
>
> Item was changed:
> + ----- Method: Collection>>union: (in category 'set logic') -----
> - ----- Method: Collection>>union: (in category 'enumerating') -----
> union: aCollection
> "Answer the set theoretic union of two collections."
>
> ^ self asSet addAll: aCollection; yourself!
>
> Item was changed:
> + ----- Method: HashedCollection>>union: (in category 'set logic') -----
> - ----- Method: HashedCollection>>union: (in category 'enumerating') -----
> union: aCollection
> "Answer the set theoretic union of the receiver and aCollection, using the receiver's notion of equality and not side effecting the receiver at all."
>
> ^ self copy addAll: aCollection; yourself
>
> !
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210312/b0379436/attachment.html>


More information about the Squeak-dev mailing list