http://d.puremagic.com/issues/show_bug.cgi?id=4736

           Summary: http://www.digitalmars.com/d/2.0/hash-map.html
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: andrej.mitrov...@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2010-08-26 
14:27:13 PDT ---
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);
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to