… | |
… | |
18 | |
18 | |
19 | #include <shstr.h> |
19 | #include <shstr.h> |
20 | #include <traits.h> |
20 | #include <traits.h> |
21 | |
21 | |
22 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
22 | // use a gcc extension for auto declarations until ISO C++ sanctifies them |
23 | #define AUTODECL(var,expr) typeof(expr) var = (expr) |
23 | #define auto(var,expr) typeof(expr) var = (expr) |
24 | |
24 | |
25 | // very ugly macro that basicaly declares and initialises a variable |
25 | // very ugly macro that basicaly declares and initialises a variable |
26 | // that is in scope for the next statement only |
26 | // that is in scope for the next statement only |
27 | // works only for stuff that can be assigned 0 and converts to false |
27 | // works only for stuff that can be assigned 0 and converts to false |
28 | // (note: works great for pointers) |
28 | // (note: works great for pointers) |
… | |
… | |
48 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
48 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
49 | |
49 | |
50 | // lots of stuff taken from FXT |
50 | // lots of stuff taken from FXT |
51 | |
51 | |
52 | /* Rotate right. This is used in various places for checksumming */ |
52 | /* Rotate right. This is used in various places for checksumming */ |
53 | //TODO: this sucks, use a better checksum algo |
53 | //TODO: that sucks, use a better checksum algo |
54 | static inline uint32_t |
54 | static inline uint32_t |
55 | rotate_right (uint32_t c) |
55 | rotate_right (uint32_t c, uint32_t count = 1) |
56 | { |
56 | { |
57 | return (c << 31) | (c >> 1); |
57 | return (c << (32 - count)) | (c >> count); |
|
|
58 | } |
|
|
59 | |
|
|
60 | static inline uint32_t |
|
|
61 | rotate_left (uint32_t c, uint32_t count = 1) |
|
|
62 | { |
|
|
63 | return (c >> (32 - count)) | (c << count); |
58 | } |
64 | } |
59 | |
65 | |
60 | // Return abs(a-b) |
66 | // Return abs(a-b) |
61 | // Both a and b must not have the most significant bit set |
67 | // Both a and b must not have the most significant bit set |
62 | static inline uint32_t |
68 | static inline uint32_t |
… | |
… | |
393 | } |
399 | } |
394 | |
400 | |
395 | void erase (T *obj) |
401 | void erase (T *obj) |
396 | { |
402 | { |
397 | assert (obj->*index); |
403 | assert (obj->*index); |
398 | int pos = obj->*index; |
404 | unsigned int pos = obj->*index; |
399 | obj->*index = 0; |
405 | obj->*index = 0; |
400 | |
406 | |
401 | if (pos < this->size ()) |
407 | if (pos < this->size ()) |
402 | { |
408 | { |
403 | (*this)[pos - 1] = (*this)[this->size () - 1]; |
409 | (*this)[pos - 1] = (*this)[this->size () - 1]; |