1 // cln/string.hashcode().
4 #include "base/cl_sysdep.h"
7 #include "cln/string.h"
14 unsigned long hashcode (const cl_string& str)
16 var unsigned long code = 0x61284AF3;
17 // We walk through all characters. It may take some time for very
18 // long strings, but it's better than completely ignoring some characters.
19 var long len = str.size();
20 var const char * ptr = str.asciz();
21 for (; len > 0; len--) {
22 var unsigned char c = *ptr++;
23 code = (code << 5) | (code >> 27); // rotate left 5 bits
24 code += (long)c << 16;