Dictionary and order

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

Dictionary and order

NorbertHartl
Hi,

is the order of elements in a dictionary preserved?
I mean if I can assume that the first element added
stays the first element in associations, keys and
values?

thanks,

Norbert

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

Re: Dictionary and order

NorbertHartl

On Fri, 2007-09-07 at 15:26 +0200, Norbert Hartl wrote:
> Hi,
>
> is the order of elements in a dictionary preserved?
> I mean if I can assume that the first element added
> stays the first element in associations, keys and
> values?
>
Oh, I tested it the wrong way. I can easily that the
answer to my question is no :) So I need to use two
orderedcollections or is there something appropriate?

thanks again,

Norbert

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

Re: Dictionary and order

Tapple Gao
On Fri, Sep 07, 2007 at 03:30:17PM +0200, Norbert Hartl wrote:

>
> On Fri, 2007-09-07 at 15:26 +0200, Norbert Hartl wrote:
> > Hi,
> >
> > is the order of elements in a dictionary preserved?
> > I mean if I can assume that the first element added
> > stays the first element in associations, keys and
> > values?
> >
> Oh, I tested it the wrong way. I can easily that the
> answer to my question is no :) So I need to use two
> orderedcollections or is there something appropriate?

It really depends on what you are actually trying to do. You can
use an OrderedCollection of associations to have ordered key,
value pairs:
OrderedCollection new
    with: #key1 -> #value1;
    with: #key2 -> #value2.

(note that a Dictionary is just a Set of associations). Or there
may be a more appropriate data structure for your problem, like
Categorizer, which provides a grouping for all elements in an
OrderedCollection, and is how Class categories and method
protocols are stored.

Or, if all else fails, it is really easy to make a new data
structure. Subclass Association to provide a 'next' field, and
subclass Dictionary to use these new LinkedAssociations, and now
you have a linked list overlaid on top of a dictionary

--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners