associativeArray.toHash()
Jarrett Billingsley
kb3ctd2 at yahoo.com
Wed Feb 21 18:42:21 PST 2007
"Michiel" <nomail at please.com> wrote in message
news:eritp3$d3j$1 at digitalmars.com...
> Michiel wrote:
>
> I think I found a way in Phobos, but it might not be the most elegant
> one. I used std.boxer to pack each element of the array into a box. Then
> I call the Box.toHash() function on each and use the sum to calculate
> the sets hash.
>
> Is there a better way?
You can use the .getHash method of the typeinfo any type, and it'll use the
built in hashing function.
class Set(T)
{
...
T[] values; // or however you store them
void someFunc(T data)
{
hash_t hash = typeid(T).getHash(&data);
}
}
More information about the Digitalmars-d
mailing list