[Pharo-project] Dictionary as a Set
I reported some important distinction between Dictionaries and Sets at http://bugs.squeak.org/view.php?id=7258. The problem has been introduced by the change of Association>>#=. Logically, Dictionary should have been detached from Set at this time, since it was no more a Set of associations as it used to. Stéphane Ducasse <stephane.ducasse@...> writes:
This is interesting that you present that as a Bag. I'm too sick now (my brain is wandering across my room) to really reply something clever.
I thought that a bag was more an counting elements container
For me the sole specification is that a Bag unlike a Set can hold several equal elements. The fact that it can count them fast rather than enumerating the whole collection is an implementation detail (an important detail of course).
a) multiple values can be in the dictionary: (Dictionary new) at: 'one' put: 1; at: 'first' put: 1; yourself.
For me to be bag would mean more
dc := (DictionaryBag new) at: 'one' put: 1; at: 'one' put: 2; yourself. dc at: one -> #(1 2)
Stef
a DictionaryOfBags ? One thing Dictionary is not : a Bag of associations. Think of it as a Bag of values. As long as you don't override a key, a Dictionary behaves like a Bag: digits := 0 to: 9. b := Bag new. d := Dictionary new. digits do: [:i | b add: i//2]. digits do: [:i | d at: i printString put: i//2]. digits do: [:i | self assert: (b occurrencesOf: i) = (d occurrencesOf: i)]. Personnally, I would expect d values. to answer a Bag (unordered) rather than an Array (arbitrary order)... The only advantage of an Array is that it is faster than a Bag...
For me the sole specification is that a Bag unlike a Set can hold several equal elements. The fact that it can count them fast rather than enumerating the whole collection is an implementation detail (an important detail of course).
exact this is why for me a dictionary is more like a set than a bag because I can only have one key for #a for example. This is why I did not totally understand your bag relationships.
a) multiple values can be in the dictionary: (Dictionary new) at: 'one' put: 1; at: 'first' put: 1; yourself.
For me to be bag would mean more
dc := (DictionaryBag new) at: 'one' put: 1; at: 'one' put: 2; yourself. dc at: one -> #(1 2)
Stef
a DictionaryOfBags ?
No I mean if you want to see Dictionary as a bag then it means that you could have multiple similar keys 'one' in the above example. For a Dictionary (as for now and which I see as a set) you get only one value for the key 'one'
One thing Dictionary is not : a Bag of associations. Think of it as a Bag of values. As long as you don't override a key, a Dictionary behaves like a Bag:
digits := 0 to: 9. b := Bag new. d := Dictionary new. digits do: [:i | b add: i//2]. digits do: [:i | d at: i printString put: i//2]. digits do: [:i | self assert: (b occurrencesOf: i) = (d occurrencesOf: i)].
Personnally, I would expect d values. to answer a Bag (unordered) rather than an Array (arbitrary order)... The only advantage of an Array is that it is faster than a Bag...
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (2)
-
nicolas cellier -
Stéphane Ducasse