Iterate/sort associative array by value?

Robert M. Münch robert.muench at saphirion.com
Sun Apr 7 16:44:01 UTC 2019


On 2019-04-07 16:24:52 +0000, Cym13 said:

> You could use sort to gather the indexes in order then traverse from there:
> 
>      aa.byKey.array.sort!((a, b) => aa[a]<aa[b])

That doesn't work: Error: no property array for type Result
> 
> With a wrapper caching that order and making it transparent as well as 
> update on insertion (which should be in log(n) since you know have an 
> ordered list of indexes, you can use dichotomy to update the indexes 
> without walking all your AA again) I think you could have a nice little 
> container. However if double entry is necessary maybe a simpler 2D 
> array would be easier to work with?

At the point where I need this sorted array, nothing will change it. 
It's a log output. So, not necessary to make things more complex.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list