Dynamic associative array, to hold many values per key
Logesh Pillay
lp at webafrica.org.za
Sun Oct 20 08:13:45 PDT 2013
On Sunday, 20 October 2013 at 14:05:53 UTC, bearophile wrote:
> 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
Thanks. Coming to D from python, I have to say D's tuples look
difficult. I'm going to see how far I can get with structs
writing my sudoku solver.
More information about the Digitalmars-d-learn
mailing list