… | |
… | |
9 | |
9 | |
10 | // makes dynamically allocated objects zero-initialised |
10 | // makes dynamically allocated objects zero-initialised |
11 | struct zero_initialised |
11 | struct zero_initialised |
12 | { |
12 | { |
13 | void *operator new (size_t s); |
13 | void *operator new (size_t s); |
|
|
14 | void *operator new [] (size_t s); |
14 | void operator delete (void *p, size_t s); |
15 | void operator delete (void *p, size_t s); |
|
|
16 | void operator delete [] (void *p, size_t s); |
|
|
17 | }; |
|
|
18 | |
|
|
19 | struct str_hash |
|
|
20 | { |
|
|
21 | std::size_t operator ()(const char *s) const |
|
|
22 | { |
|
|
23 | unsigned long hash = 0; |
|
|
24 | |
|
|
25 | /* use the one-at-a-time hash function, which supposedly is |
|
|
26 | * better than the djb2-like one used by perl5.005, but |
|
|
27 | * certainly is better then the bug used here before. |
|
|
28 | * see http://burtleburtle.net/bob/hash/doobs.html |
|
|
29 | */ |
|
|
30 | while (*s) |
|
|
31 | { |
|
|
32 | hash += *s++; |
|
|
33 | hash += hash << 10; |
|
|
34 | hash ^= hash >> 6; |
|
|
35 | } |
|
|
36 | |
|
|
37 | hash += hash << 3; |
|
|
38 | hash ^= hash >> 11; |
|
|
39 | hash += hash << 15; |
|
|
40 | |
|
|
41 | return hash; |
|
|
42 | } |
|
|
43 | }; |
|
|
44 | |
|
|
45 | struct str_equal |
|
|
46 | { |
|
|
47 | bool operator ()(const char *a, const char *b) const |
|
|
48 | { |
|
|
49 | return !strcmp (a, b); |
|
|
50 | } |
15 | }; |
51 | }; |
16 | |
52 | |
17 | #endif |
53 | #endif |
18 | |
54 | |