unordered output of an associated array of associated arrays

forkit forkit at gmail.com
Tue Jan 25 02:04:26 UTC 2022


On Tuesday, 25 January 2022 at 00:43:07 UTC, forkit wrote:
>
> oh. thanks :-)
>
> I will get that integrated into my example code, and will post 
> again, once it's working (so others can  learn too)

ok.. so I took the easy way out ;-)

output is now ordered:

typeA:100000003:[1, 1, 1, 0, 0, 0, 0, 0]
typeA:100000004:[1, 1, 1, 1, 0, 0, 0, 0]
typeA:100000005:[1, 1, 1, 1, 1, 0, 0, 0]
typeB:100000001:[1, 0, 0, 0, 0, 0, 0, 0]
typeB:100000002:[1, 1, 0, 0, 0, 0, 0, 0]
typeC:100000006:[1, 1, 1, 1, 1, 1, 0, 0]
typeC:100000007:[1, 1, 1, 1, 1, 1, 0, 0]


// --
module test;

import std;

void main()
{
     auto aaTable =
       ([
        "typeB" : [ 100000002 : [1, 1, 0, 0, 0, 0, 0, 0],
                    100000001 : [1, 0, 0, 0, 0, 0, 0, 0]
                  ],
        "typeC" : [ 100000007 : [1, 1, 1, 1, 1, 1, 0, 0],
                    100000006 : [1, 1, 1, 1, 1, 1, 0, 0]
                  ],
        "typeA" : [ 100000005 : [1, 1, 1, 1, 1, 0, 0, 0],
                    100000003 : [1, 1, 1, 0, 0, 0, 0, 0],
                    100000004 : [1, 1, 1, 1, 0, 0, 0, 0]
                  ]
       ]);

     string[] orderedKeyPairSet;

     foreach (key, pair; aaTable.byPair)
     {
         foreach(k, p; pair.byPair)
             orderedKeyPairSet ~= key ~ ":" ~ k.to!string ~ ":" ~ 
p.to!string;
     }

     orderedKeyPairSet.sort;

     foreach(s; orderedKeyPairSet)
         writeln(s);

}

// ---


More information about the Digitalmars-d-learn mailing list