2012-03-14 09:51:55 +02:00
|
|
|
#include "mph_bits.h"
|
|
|
|
|
|
|
|
namespace cxxmph {
|
2012-03-14 21:43:38 +02:00
|
|
|
|
|
|
|
const uint8_t dynamic_2bitset::vmask[] = { 0xfc, 0xf3, 0xcf, 0x3f};
|
2012-04-15 06:03:00 +03:00
|
|
|
dynamic_2bitset::dynamic_2bitset() : size_(0), fill_(false) {}
|
|
|
|
dynamic_2bitset::dynamic_2bitset(uint32_t size, bool fill)
|
|
|
|
: size_(size), fill_(fill), data_(ceil(size / 4.0), ones()*fill) {}
|
|
|
|
dynamic_2bitset::~dynamic_2bitset() {}
|
2012-03-14 21:43:38 +02:00
|
|
|
|
2012-03-22 01:19:16 +02:00
|
|
|
template <int n, int mask = (1 << 7)> struct bitcount {
|
|
|
|
enum { value = (n & mask ? 1:0) + bitcount<n, (mask >> 1)>::value };
|
|
|
|
};
|
|
|
|
template <int n> struct bitcount<n, 0> { enum { value = 0 }; };
|
|
|
|
|
|
|
|
template <int size, int index = size>
|
|
|
|
class CompileTimeRankTable {
|
|
|
|
public:
|
|
|
|
CompileTimeRankTable() : current(bitcount<index - 1>::value) { }
|
|
|
|
uint8_t operator[] (uint8_t i) { return *(¤t + size - i - 1); }
|
|
|
|
private:
|
|
|
|
unsigned char current;
|
|
|
|
CompileTimeRankTable<index -1> next;
|
|
|
|
};
|
|
|
|
template <int size> class CompileTimeRankTable<size, 0> { };
|
|
|
|
static CompileTimeRankTable<256> kRanktable;
|
|
|
|
|
|
|
|
uint8_t Ranktable::get(uint8_t i) { return kRanktable[i]; }
|
|
|
|
|
2012-04-15 06:03:00 +03:00
|
|
|
void stop_unused_warning() {
|
|
|
|
rank64(4);
|
|
|
|
nextpoweroftwo(4);
|
|
|
|
}
|
2012-03-22 01:19:16 +02:00
|
|
|
|
2012-03-14 09:51:55 +02:00
|
|
|
}
|