Test for element in array
Kirk McDonald
kirklin.mcdonald at gmail.com
Fri Jul 14 19:45:53 PDT 2006
Derek Parnell wrote:
> On Sat, 15 Jul 2006 02:46:24 +1000, Carlos Santander
> <csantander619 at gmail.com> wrote:
>
>
>>
>> It was possible some time ago, but it got forbidden. What I've been
>> doing (and I think others too) is:
>>
>> char [] [char []] whos;
>>
>> And set the element to both the key and the value. However, I admit I
>> liked void [T].
>
>
> Actually I use
>
> bool[ char[] ] whos;
>
> whos["Capone"] = true;
>
You can also have a sort of poor-man's multiset with:
int[ char[] ] ms;
One could easily wrap this with a more multiset-ish interface, but to
add an item you just say:
++ms["moo"];
And to remove:
if (--ms["moo"] <= 0) ms.remove("moo");
--
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki
More information about the Digitalmars-d-learn
mailing list