Find if keys are in two dimensional associative array

Mike Wey mike-wey at example.com
Sun Jan 17 06:08:08 PST 2010


On 01/17/2010 01:23 PM, Michal Minich wrote:
> if one has double indexed aa, how to find that it contains value under
> keys 'a' and 123
>
> float[int][char] aa;
>
> aa['a'][123] = 4.56;
>
> I had to make following helper function. Is there more elegant way /
> built in into D?
>
> float* isIn = doubleIn(123, 'a');
>
> float* doubleIn (int i, char ch) {
>
>      float[int]* first = ch in aa;
>
>      if (first is null)
>          return null;
>      else
>          return i in *first;
> }
>

This should work.

float[int][char] aa;

aa['a'][123] = 4.56;

if ( 123 in aa['a'] )
	writeln(true);
else
	writeln(false);

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list