… | |
… | |
8 | #endif |
8 | #endif |
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, 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 | }; |
… | |
… | |
19 | struct str_hash |
20 | struct 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 | |
|
|
56 | template<class obj> |
|
|
57 | struct 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 | |