[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squeak-beginners
Subject:    Re: [Newbies] Dictionary and order
From:       Matthew Fulmer <tapplek () gmail ! com>
Date:       2007-09-07 15:18:12
Message-ID: 20070907151812.GE8394 () tacobell ! ph ! cox ! net
[Download RAW message or body]

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
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic