Dynamic associative array, to hold many values per key

bearophile bearophileHUGS at lycos.com
Sun Oct 20 07:05:52 PDT 2013


Andrej Mitrovic:

>> struct kie { short a; short b; }
>> short[kie] possibles;
> ...
> Try:
>
> short[][kie];

In D structs/classes usually start with an upper case letter:

struct Kie { short a, b; }

But if you want to use Kie as key in an associative array you 
have to add it the full hashing protocol of three functions: 
equality, hash function and comparison.

A simpler solution is to use a Tuple, that already defines those 
three methods:

alias Kie = Tuple!(short,"a", short,"b");

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list