[Newbies] Ordered Set?

Ron Teitelbaum Ron at USMedRec.com
Sun Nov 4 13:58:43 UTC 2007

Hi itsme,  

I see that you have been asked already but, could you please give us a name
we can use besides itsme213?   

You can use SortedCollection.  

SortedCollection new sortBlock: [:a :b | a index < b index].  This provides
ordering but does not eliminate duplicates.  That can be accomplished pretty
simply by checking for uniqueness before adding to the collection.

You could also use a Dictionary, if your data is not too large.

aDict := Dictionary new.

aDict at: anObject index ifAbsentPut: anObject.

This provides both sorting and set like operations (again by checking for
uniqueness before adding).

Otherwise just use OrderedCollection and manage order and uniqueness
manually.  The class has all the methods you need to do so.

Happy Coding!

Ron Teitelbaum

> -----Original Message-----
> From: beginners-bounces at lists.squeakfoundation.org [mailto:beginners-
> bounces at lists.squeakfoundation.org] On Behalf Of itsme213
> Sent: Saturday, November 03, 2007 11:27 PM
> To: beginners at lists.squeakfoundation.org
> Subject: [Newbies] Ordered Set?
> I have ordered collections of things without duplicates and with an index
> 1...N for each, ideally with operations like
>   move: anExistingElement to: anExistingPosition
> What should I use? I could not find an OderedSet?
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

More information about the Beginners mailing list