hashed array?

monarch_dodra monarchdodra at gmail.com
Mon Nov 12 07:04:29 PST 2012


On Monday, 12 November 2012 at 14:50:48 UTC, bearophile wrote:
> monarch_dodra:
>
>> I've noticed though it has no built-in "hashed container" for 
>> when you just need to store unique elements, but without any 
>> specific data associated (lists of names, for example).
>
> They are often named "hash sets". In Python this is a built-in 
> type. But in D I think it's better to define such sets as a 
> library template in a module to import. This is meant to be in 
> Phobos.
>
>
>> he interface would be mostly the already existing functions of 
>> AA (".remove", "in", "rehash()"), plus ".insert" to insert a 
>> key.
>
> It also needs some other methods, see:
> http://docs.python.org/2/library/sets.html
>
> Bye,
> bearophile

Well, I don't see why AA would be built-in, but not set.

In particular, more often than not, AAs are implemented in terms 
of set (and not the other way around) anyways, so if we take the 
time to implement AA, why not hashed sets?

The advantage of having it built-in would mean more convenient 
declaration syntax:
int[string] vs AA!(string, int) // string => int
[string] vs Set!(string) //set of string

But of course, a library solution would be good too.

Might even make it my next project and get started on it now :)


More information about the Digitalmars-d mailing list