built-in string hash ?

bearophile bearophileHUGS at lycos.com
Sat Aug 28 13:25:37 PDT 2010


torhu:
> string a = "abc";
> auto hash = typeid(a).getHash(&a);

If higher performance is necessary, you may pre-compute part of that:

void main() {
    string a = "abc";
    auto hash1 = typeid(a).getHash(&a);
    auto stringHash = &(typeid(a).getHash);
    auto hash2 = stringHash(&a);
    assert(hash1 == hash2);
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list