lilypond-1.0.19
[lilypond.git] / flower / hash.cc
blob1e2debd13b4fbef8a313cc9cfaf1026b5e067676
1 #include "string.hh"
2 #include "array.hh"
3 #include "dictionary.hh"
6 // Note: assumes long is at least 32 bits.
7 const unsigned long my_prime_list[] =
9 53, 97, 193, 389, 769,
10 1543, 3079, 6151, 12289, 24593,
11 49157, 98317, 196613, 393241, 786433,
12 1572869, 3145739, 6291469, 12582917, 25165843,
13 50331653, 100663319, 201326611, 402653189u, 805306457u,
14 1610612741u, 3221225473u, 4294967291u
17 unsigned long prime_list (int idx)
19 return my_prime_list [idx];
22 unsigned int hash (String s)
24 const char* str = s.ch_C ();
25 unsigned int result = 0;
26 while (1) {
27 char c = *str++;
28 if (c == 0) break;
29 result += (result<<3) + c;
31 return result;