]> git.donarmstrong.com Git - lilypond.git/blob - flower/hash.cc
release: 1.0.17
[lilypond.git] / flower / hash.cc
1 #include "string.hh"
2 #include "array.hh"
3 #include "dictionary.hh"
4
5
6 // Note: assumes long is at least 32 bits.
7 const unsigned long my_prime_list[] = 
8 {
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
15 };
16
17 unsigned long prime_list (int idx)
18 {
19   return my_prime_list [idx];
20 }
21
22 unsigned int hash (String s)
23 {
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;
30   }
31   return result;
32 }
33