[Click] hashcode() system

Eddie Kohler kohler at cs.ucla.edu
Sun Jul 20 13:42:51 EDT 2008


Hi Julian,

The problematic type is being used as the key in a HashMap or HashTable.  The 
type's hashcode() member function should return an unsigned integer that acts 
as a good hash value for the type.  T::hashcode() must satisfy two invariants. 
  For any two objects "T a" and "T b":

        if (a.hashcode() != b.hashcode())
            assert(a != b);
        if (a == b)
            assert(a.hashcode() == b.hashcode());

These invariants are required for correctness.  For good performance, there is 
another requirement: the hashcode() function should return widely distributed 
values.  Otherwise, the HashMap will become unbalanced (most buckets are empty 
and a couple buckets contain tons of values).

For examples of hashcode() functions, see IPFlowID::hashcode() and 
String::hashcode().

Hope this helps.
Eddie


JULIAN DAVID MORILLA POZO wrote:
> Dear all,
> 
> Up to now I have been using Version 1.5.0. Now I have downloaded Version 1.6.0 and I have found that one of my elements doesn't compile. The error is related to the Hash implementation. I have found on the web that one of the changes from previous version is:
> 
> "A better hashcode() system uses templates and overloading, reducing the chance that an operator bool() will mistakenly be used as a hashcode()."
> 
> I have also seen a new file hashcode.hh in the include/click directory which appears on the error shown by the compiler. More precisely, the error says that my hash key class does not have any member "hashcode()" as it is requested in hashcode.hh.
> 
> I suppose that I should implement this function but... what is this function supposed to do/return? Or What changes should I do to my current implementation?
> 
> Thanks a lot!
> julian
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click



More information about the click mailing list