Ordered Set?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Ordered Set?

Sophie424
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
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: Ordered Set?

Ron Teitelbaum
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: [hidden email] [mailto:beginners-
> [hidden email]] On Behalf Of itsme213
> Sent: Saturday, November 03, 2007 11:27 PM
> To: [hidden email]
> 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
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Ordered Set?

Sophie424

"Ron Teitelbaum" <[hidden email]> wrote

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

But of course ... I had not realized my signature was broken.

Thanks ... Sophie.



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

RE: Re: Ordered Set?

Ron Teitelbaum
Thanks Sophie,

        It's nice to meet you!

Ron

> -----Original Message-----
> From: [hidden email] [mailto:beginners-
> [hidden email]] On Behalf Of itsme213
> Sent: Sunday, November 04, 2007 10:55 AM
> To: [hidden email]
> Subject: [Newbies] Re: Ordered Set?
>
>
> "Ron Teitelbaum" <[hidden email]> wrote
>
> > I see that you have been asked already but, could you please give us a
> > name
> > we can use besides itsme213?
>
> But of course ... I had not realized my signature was broken.
>
> Thanks ... Sophie.
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners