Support of algebraic operations on sets
nicolas cellier
ncellier at ifrance.com
Sat Jun 16 07:10:24 UTC 2007
nicolas cellier a écrit :
> So, making Association comparing on values seems to be a remedy to this
> surprise. But in this case, Dictionary don't behave like Set anymore...
> So the logic would be to detach them from Set hierarchy. Only the list
> of keys is a set...
>
> Maybe we kept it there for saving a few methods duplication? But when it
> is necessary to define more methods to contradict super behaviour than
> methods we inherit, maybe it's time for a move in hierarchy. Leave your
> super and be adopted by a new family.
>
> Nicolas
>
>
Well inquiring a bit more on Set-Dictionary inheritance:
"methods in set not overriden in Dictionary"
(Set selectors difference: Dictionary selectors) size. "21"
"methods in set overriden in Dictionary"
(Set selectors intersection: Dictionary selectors) size. "15"
At first glance, Dictionary inherit more than it overrides.
To be fair, i should also include the count of overrides calling
super... that's only one, #do:
But let's look more in detail inherited stuff:
an IdentitySet(#doWithIndex: #like: #size #fullCheck #someElement
#comeFullyUpOnReload: #array #findElementOrNil: #swap:with: #atRandom:
#capacity #union: #growSize #add:withOccurrences: #copyWithout:
#withArray: #grow #initialize: #atNewIndex:put: #asSet #fixCollisionsFrom:)
Dictionary new asSet answers a Dictionary... arguable sig said it's not
a set of values, nor a set of associations (because Association values
are compared!). Only a set of keys, but that's a very poor view of
Dictionary... Bert suggested ^self values asSet
Dictionary union: is surprising as debatted in this thread because non
commutative... But well, maybe it is usefull as it is...
Dictionary doWithIndex: do not use keys as index... implementing this
message taylored for SequenceableCollection is arguable anyway (used by
atRandom:, anywhere else?).
Dictionary like: works only on keys... arguable (Bert would prefer
values i guess)
Dictionary copyWithout: will call a shouldNotImplement remove:ifAbsent:
and fail. not a valuable inheritance...
What is common and not arguable is the behavior of HashedCollection
( #size #fullCheck #someElement #comeFullyUpOnReload:
#findElementOrNil: #swap:with: #atRandom: #capacity #growSize
#withArray: #grow #initialize: #atNewIndex:put: #fixCollisionsFrom:)
Also, the class side messages are mostly HashedCollection:
"methods in set not overriden in Dictionary"
(Set class selectors difference: Dictionary class selectors) size. "5"
"methods in set overriden in Dictionary"
(Set class selectors intersection: Dictionary class selectors) size. "1"
So creating a HashedCollection above both Set and Dictionary would be an
interesting alternative.
Add the #union: message to it.
And another inherited from uniqueness of keys: #add:withOccurrences:
Well, maybe that does not add a lot of value, what difference between a
HashedCollection of unique elements and a Set? But semantically, it
disjoint Dictionary from Set, and that is consistent with Association
behavior. Since Dictionary are no more Set, no use to
have union: commutative.
Nicolas
More information about the Squeak-dev
mailing list
|