Comment #0 by andrej.mitrovich — 2010-08-26T14:27:13Z
Example under "Using Classes as the KeyType" has some typos (f instead of foo), fix to:
class Foo
{
int a, b;
hash_t toHash() { return a + b; }
bool opEquals(Object o)
{
Foo foo = cast(Foo) o;
return foo && a == foo.a && b == foo.b;
}
int opCmp(Object o)
{
Foo foo = cast(Foo) o;
if (!foo)
return -1;
if (a == foo.a)
return b - foo.b;
return a - foo.a;
}
}
Example under "Using Structs or Unions as the KeyType" has a typo (s instead of str) fix to:
import std.string;
struct MyString
{
string str;
const hash_t toHash()
{
hash_t hash;
foreach (char c; str)
hash = (hash * 9) + c;
return hash;
}
const bool opEquals(ref const MyString s)
{
return std.string.cmp(this.str, s.str) == 0;
}
const int opCmp(ref const MyString s)
{
return std.string.cmp(this.str, s.str);
}
}
Comment #1 by andrej.mitrovich — 2012-01-04T07:41:52Z