ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.3 by root, Mon Sep 4 11:07:59 2006 UTC vs.
Revision 1.6 by root, Mon Sep 11 01:16:20 2006 UTC

8#endif 8#endif
9 9
10// makes dynamically allocated objects zero-initialised 10// makes dynamically allocated objects zero-initialised
11struct zero_initialised 11struct zero_initialised
12{ 12{
13 void *operator new (size_t s, void *);
13 void *operator new (size_t s); 14 void *operator new (size_t s);
14 void *operator new [] (size_t s); 15 void *operator new [] (size_t s);
15 void operator delete (void *p, size_t s); 16 void operator delete (void *p, size_t s);
16 void operator delete [] (void *p, size_t s); 17 void operator delete [] (void *p, size_t s);
17}; 18};
18 19
20struct str_hash
21{
22 std::size_t operator ()(const char *s) const
23 {
24 unsigned long hash = 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
46struct str_equal
47{
48 bool operator ()(const char *a, const char *b) const
49 {
50 return !strcmp (a, b);
51 }
52};
53
54#include <vector>
55
56template<class obj>
57struct unordered_vector : std::vector<obj>
58{
59 typedef typename std::vector<obj>::iterator iterator;
60
61 void erase (unsigned int pos)
62 {
63 if (pos < this->size () - 1)
64 (*this)[pos] = (*this)[this->size () - 1];
65
66 this->pop_back ();
67 }
68
69 void erase (iterator i)
70 {
71 erase ((unsigned int )(i - this->begin ()));
72 }
73};
74
19#endif 75#endif
20 76

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines