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.4 by root, Mon Sep 4 17:16:19 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};
19struct str_hash 20struct str_hash
20{ 21{
21 std::size_t operator ()(const char *s) const 22 std::size_t operator ()(const char *s) const
22 { 23 {
23 unsigned long hash = 0; 24 unsigned long hash = 0;
24 unsigned int i = 0;
25 25
26 /* use the one-at-a-time hash function, which supposedly is 26 /* use the one-at-a-time hash function, which supposedly is
27 * better than the djb2-like one used by perl5.005, but 27 * better than the djb2-like one used by perl5.005, but
28 * certainly is better then the bug used here before. 28 * certainly is better then the bug used here before.
29 * see http://burtleburtle.net/bob/hash/doobs.html 29 * see http://burtleburtle.net/bob/hash/doobs.html
49 { 49 {
50 return !strcmp (a, b); 50 return !strcmp (a, b);
51 } 51 }
52}; 52};
53 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
54#endif 75#endif
55 76

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines