OrderedDictionary (was: Re: [squeak-dev] Re: The Trunk: Collections-mt.593.mcz)

Levente Uzonyi leves at elte.hu
Fri Jan 16 13:31:02 UTC 2015


On Fri, 16 Jan 2015, Marcel Taeumel wrote:

> Hi Levente,
>
> thank you for the quick code review. I did some fixes. :)
>
> For the LinkedDictionary: When do you establish the desired order
> (insertion, lexical, ... someBlock) for the associations?

I'm not sure if I understand this question right, so I'll try do my best 
to give a meaningful answer.

If the goal is to keep the insertion order, then #atNewIndex:put: is the 
right place.
If you want it to reflect the order of modifications (insert + update), 
then #add: and #at:put: has to be modified too.
If you want the order to reflect the order of accesses, then all other 
methods have to be changed which access the value (or the key?).

For the list implementation, I always prefer the circular doubly-linked 
list with a head element (Not sure if this is the right term in english.
It means a separate element with no value, just the next and the previous 
links. This allows the code to be simpler, because the list always has 
at least one element). This list provides O(1) time removal, and insertion 
next to the head (or any other known element). This is why any kind of 
ordering can be implemented with O(1) extra time, as long as the elements 
are moved to the front.

The only drawback this dictionary implementation has is that the 
associations added with #add: can't be used, unless they are from the 
right class (the one which has the two links).

In Java this collection is called LinkedHashMap: 
http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html
This supports two kind of ordering: access-order and insertion-order.

Levente

>
> Use cases are similar to OrderedCollection. But instead of accessing items
> via index (someItems at: 5), you can access it with a more descriptive key
> (e.g., someItems at: #foobar). I will look for a more concrete one.
>
> To be better comparable with OrderedCollection, there might be an additional
> protocol to support #atFirst and others... Hmmm...
>
> Here are more references to the concept itself:
> https://www.python.org/dev/peps/pep-0372/
> https://docs.python.org/3/library/collections.html#collections.OrderedDict
>
> Best,
> Marcel
>
>
>
> --
> View this message in context: http://forum.world.st/The-Trunk-Collections-mt-593-mcz-tp4799750p4799843.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>
>


More information about the Squeak-dev mailing list