ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
Revision: 1.4
Committed: Mon Sep 4 17:16:19 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.3: +35 -0 lines
Log Message:
*** empty log message ***

File Contents

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