"Chris Uppal" <
[hidden email]> schrieb im
Newsbeitrag news:9gl4mn$43n$
[hidden email]...
> Ingo,
>
> > addAll: aDictionary
> >
> > aDictionary keysAndValuesDo: [:k :v|
> > | tmpVal |
> >
> > tmpVal := self at: k ifAbsent:[nil].
> > tmpVal isNil
> > ifTrue:[self at: k put: v]
> > ifFalse:[ tmpVal = v ifFalse:[ ^self error: 'key collision would lead
to
> > nondeterministic dictionary']]
> >
> > ].
> > ^aDictionary
>
> I don't really see why you avoid overwriting existing entries. To me it
> seems just as natural to do so (it is, at worst, no more suprising to
> overwrite the old entries than it would be to loose the new versions), and
> is easier to code and will run faster.
Chris,
Sorry for answering so late. I simply didn't see that end of thread
on my server here...
Well, the reason for doing so - I thought about it quite a while - is that
an Association is by definition a 1:1 mapping.
key -> (value-1,value-2,...,value-n) mappings violate
the Dictionary property, being a Set of Associations.
key -> value-1
key -> value-2
...
key -> value-n
is no proper <Dictionary>, but could be represented as a <SetDictionary>.
A <SetDictionary> is a more general <Dictionary>, mapping a key to a <Set>
of values.
A <SetDictionary> can be transformed into a <Dictionary> IFF all
value-<Dictionaries> are of size 1.
Otherwise we call the <SetDictionary> "nondeterministic".
As an example, you can refer to the famous T-Gen tool. I believe it comes
as a goodie with VW5i. There a <SetDictionary> is implemented and described.
Finally one *could* overwrite existing k->v's, but it seems to be not
logical. Kind of mixing apples and pears ...
> > Ingo
>
> -- chris
>
Ingo