Use .get() in MultiD Assoc Array?

Philippe Sigaud philippe.sigaud at gmail.com
Fri Aug 31 11:46:11 PDT 2012


On Fri, Aug 31, 2012 at 5:56 PM, Paul <phshaffer at gmail.com> wrote:

> The data is in an ascii text file.
> I need to be able to search it by group/block/parameter.
> I need to be able to maintain group/block order.
> There are ~hundred diff block types where the params and order of params are
> known...though I would rather not create all of these structures or lists
> ahead of time.
>
> My greatest need at this point is to compare two files block by block.  The
> blocks may be in diff orders between the files but the params of each block
> type would always be the same in the same order.
>
> So compare groups, blocks within groups, and the values of each param for
> matching group/block names.

I see. In that case, your original idea of having a three-tier
associative array (AA in AA in AA) is better than my tuple-key
suggestion, since you want to look into all three levels. Does the
provider ensure that no two groups have the same name and no two
blocks in a group have the same name?

If the blocks are in a different order, you don't care about order,
right? Then use an AA. As params of each block always have the same
order, you can use a dynamic array.

So:

struct Param
{
    string name, value;
}

struct Block
{
    string name;
    Param[] params;
}

struct Group
{
    string name;
    Block[string] blocks;
}

alias Group[string] InputFile;

InputFile file1, file2;


Maybe someone here will have a better idea?


More information about the Digitalmars-d-learn mailing list