*** empty log message ***
[lilypond.git] / flower / hash.cc
blob7232c368bdc0e0203b2a7117c1100dbfdf5124cc
1 /*
2 hash.cc -- implement various functions for hash tables.
4 source file of the Flower Library
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "string.hh"
10 #include "array.hh"
11 #include "dictionary.hh"
14 // Note: assumes long is at least 32 bits.
15 const unsigned long my_prime_list[] =
17 5, 11, 23, // be a bit careful for short lists: we want reasonable mem usage.
18 53, 97, 193, 389, 769,
19 1543, 3079, 6151, 12289, 24593,
20 49157, 98317, 196613, 393241, 786433,
21 1572869, 3145739, 6291469, 12582917, 25165843,
22 50331653, 100663319, 201326611, 402653189u, 805306457u,
23 1610612741u, 3221225473u, 4294967291u
26 unsigned long
27 prime_list (int idx)
29 return my_prime_list [idx];
32 unsigned int
33 string_hash (String s)
35 const char* str = s.to_str0 ();
36 unsigned int result = 0;
37 while (1) {
38 char c = *str++;
39 if (c == 0) break;
40 result += (result<<3) + c;
42 return result;
46 unsigned int
47 hash (unsigned int i)
49 return i;
52 unsigned int
53 int_hash (int i)
55 return (unsigned) i;