1
Fork 0

Make mph_bits compile fast.

main
Davi Reis 2012-05-08 14:22:47 -03:00
parent aaa59b7edb
commit 9d59436461
4 changed files with 2 additions and 38 deletions

View File

@ -8,28 +8,4 @@ dynamic_2bitset::dynamic_2bitset(uint32_t size, bool fill)
: size_(size), fill_(fill), data_(ceil(size / 4.0), ones()*fill) {}
dynamic_2bitset::~dynamic_2bitset() {}
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 *(&current + 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]; }
void stop_unused_warning() {
rank64(4);
nextpoweroftwo(4);
}
}

View File

@ -68,13 +68,6 @@ static uint32_t nextpoweroftwo(uint32_t k) {
// rank and select:
// http://vigna.dsi.unimi.it/ftp/papers/Broadword.pdf
struct Ranktable { static uint8_t get(uint8_t); };
static uint8_t rank64(uint64_t bits) {
auto bytes = reinterpret_cast<const uint8_t*>(&bits);
return Ranktable::get(bytes[0]) + Ranktable::get(bytes[1]) +
Ranktable::get(bytes[2]) + Ranktable::get(bytes[3]);
};
} // namespace cxxmph
#endif

View File

@ -4,7 +4,6 @@
#include "mph_bits.h"
using cxxmph::dynamic_2bitset;
using cxxmph::rank64;
using cxxmph::nextpoweroftwo;
int main(int argc, char** argv) {
@ -57,11 +56,6 @@ int main(int argc, char** argv) {
empty.swap(large);
if (nextpoweroftwo(3) != 4) exit(-1);
if (rank64(0) != 0) exit(-1);
if (rank64(1) != 1) exit(-1);
if (rank64(2) != 1) exit(-1);
if (rank64(255) != 8) exit(-1);
}

View File

@ -21,9 +21,10 @@
#include <vector>
#include <utility> // for std::pair
#include "hollow_iterator.h"
#include "mph_bits.h"
#include "mph_index.h"
#include "hollow_iterator.h"
#include "seeded_hash.h"
namespace cxxmph {