D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4736 - http://www.digitalmars.com/d/2.0/hash-map.html
Summary: http://www.digitalmars.com/d/2.0/hash-map.html
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-26 14:27 UTC by Andrej Mitrovic
Modified: 2012-01-18 14:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2010-08-26 14:27:13 UTC
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);
    }
}