I would like to know proper way to calculate
hash for given member fields.

class Foo {
        int value;
        string str;
        override nothrow @safe size_t toHash() {
                // calculate hash based on field value.
                // value and str in this example.
        }
}

boost::hash provides easy and systematic way
to calculate hash.
I found std.digest.crc is useful.

override nothrow @safe size_t toHash() {
        if (str is null) return value;
        ubyte[4] hash = crc32Of(str);
        return value^((hash[0]<<24)|(hash[1]<<16)|(hash[2]<<8)|hash[3]);
}

Please suggest me if anyone have an idea.

Regards, aki.

Reply via email to