Dictionary and sorting

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

Dictionary and sorting

HilaireFernandes
Dear all,

From a dictionary, I want the keys sorted according to the values (string).
I came with this method:

keysSortedByValue
    ^ (self associations sort: [ :assoc1 :assoc2 | assoc1 value < assoc2
value  ])
        collect: [ :assoc | assoc key ]


Is there better way to deal with it, in term of efficiency?

Thanks

Hilaire

--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: Dictionary and sorting

HilaireFernandes
Ah, I came to discover OrderedIdentityDictionary.
After all, the most efficient is what you don't need to do.

Hilaire

Le 11/04/2015 18:41, Hilaire a écrit :

> Dear all,
>
> From a dictionary, I want the keys sorted according to the values (string).
> I came with this method:
>
> keysSortedByValue
>     ^ (self associations sort: [ :assoc1 :assoc2 | assoc1 value < assoc2
> value  ])
>         collect: [ :assoc | assoc key ]
>
>
> Is there better way to deal with it, in term of efficiency?
>
> Thanks
>
> Hilaire
>


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu