2009/12/23 Adrian Kuhn <akuhn@iam.unibe.ch>:
Stéphane Ducasse <stephane.ducasse@...> writes:
I was more looking at the user perspective. You often want an orderedCollection (add:) vs Array at: but which deals with duplicate as a Set.
A simple method should do that job
  Collection >> #addIfAbsent: element     (self includes: element) ifFalse: [ self add: element ]
usage
  coll := OrderedCollection new.   coll addIfAbsent: #foo.   coll addIfAbsent: #bar.   coll addIfAbsent: #qux.   coll addIfAbsent: #bar.   self assert: coll asArray = #(foo bar qux).
--AA
Yes in O(n)... The challenge was to provide a fast implementation.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project