Ranges/algorithms for aggregation

"Luís "Luís
Fri Mar 21 08:22:13 PDT 2014


Is there a neat way to do this transformation with ranges and 
std.algorithms?

     Input:
     -------
     B foo
     B bar
     C ble
     B big
     A begga

     Output: (aggregated and sorted on length)
     -------
     B -> [foo, bar, big]
     C -> [ble]
     A -> [begga]

The most obvious way (to me) to do this without standard 
algorithms is with an AA to the aggregation. The most obvious way 
(to me) to do this with std.algorithms is:

     B foo
     B bar
     C ble
     B big
     A begga

     =>

     [B, foo]
     [B, bar]
     [C, ble]
     [B, big]
     [A, begga]

     =>

     [B, foo]
     [B, bar]
     [B, big]
     [C, ble]
     [A, begga]

     =>

     B -> [foo, bar, big]
     C -> [ble]
     A -> [begga]

But this seems wasteful on memory. Is there a better way to do 
this in a more algorithmic way?


More information about the Digitalmars-d-learn mailing list