hashed array?

monarch_dodra monarchdodra at gmail.com
Mon Nov 12 07:36:28 PST 2012


On Monday, 12 November 2012 at 15:32:24 UTC, Joseph Rushton 
Wakeling wrote:
> On 11/12/2012 03:53 PM, Andrej Mitrovic wrote:
>> You probably mean a Set? I think we could really use some 
>> syntax
>> support for sets. Otherwise people use workarounds like "alias
>> void[0][string] StringSet"
>
> Can you give a bit more explanation of how that workaround 
> would work?  I can't see how you would insert entries in that 
> case ...
>
>     StringSet s;
>
>     s["one"] = .... ?

The set interface would mean you use "add" or "insert", so you 
would write it like this:

Set!string s;
s.add("one");

As for the implementation, this seems to work:


StringSet(T)
{
     private void[0][T] _data;
     void add(T value)
     {
         _data.get(value, cast(void[0]) null);
     }
}


More information about the Digitalmars-d mailing list