Why D is annoying =P
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Oct 24 13:39:13 PDT 2012
On Wed, Oct 24, 2012 at 10:16:27PM +0200, Mehrdad wrote:
[...]
> struct Set(T)
> {
> int[T] dict;
> hash_t toHash() const
> {
> typeof(return) r = 0;
> foreach (item; this.dict.keys)
> {
> ??? // what should be here?
> }
> return r;
> }
> }
Try this:
hash_t toHash() const
{
hash_t h = 0;
foreach (item; this.dict.keys)
{
// We use a commutative operation here (+) so
// that the order of keys don't matter.
h += hashOf(&item, item.sizeof);
}
return h;
}
T
--
What do you get if you drop a piano down a mineshaft? A flat minor.
More information about the Digitalmars-d
mailing list