Nice and fast.
This commit is contained in:
parent
b3842c69e8
commit
b47f367db0
@ -20,10 +20,6 @@ class dynamic_2bitset {
|
|||||||
dynamic_2bitset() : size_(0), fill_(false) {}
|
dynamic_2bitset() : size_(0), fill_(false) {}
|
||||||
dynamic_2bitset(uint32_t size, bool fill = false)
|
dynamic_2bitset(uint32_t size, bool fill = false)
|
||||||
: size_(size), fill_(fill), data_(ceil(size / 4.0), ones()*fill) {
|
: size_(size), fill_(fill), data_(ceil(size / 4.0), ones()*fill) {
|
||||||
if (data_.size()) fprintf(stderr, "creating %p size %d\n", &data_[0], data_.size());
|
|
||||||
}
|
|
||||||
~dynamic_2bitset() {
|
|
||||||
if (data_.size()) fprintf(stderr, "Deleting %p size %d\n", &data_[0], data_.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t operator[](uint32_t i) const { return get(i); }
|
const uint8_t operator[](uint32_t i) const { return get(i); }
|
||||||
@ -53,19 +49,13 @@ class dynamic_2bitset {
|
|||||||
uint32_t size() const { return size_; }
|
uint32_t size() const { return size_; }
|
||||||
static const uint8_t vmask[];
|
static const uint8_t vmask[];
|
||||||
const std::vector<uint8_t>& data() const { return data_; }
|
const std::vector<uint8_t>& data() const { return data_; }
|
||||||
// private:
|
private:
|
||||||
uint32_t size_;
|
uint32_t size_;
|
||||||
bool fill_;
|
bool fill_;
|
||||||
std::vector<uint8_t> data_;
|
std::vector<uint8_t> data_;
|
||||||
const uint8_t ones() { return std::numeric_limits<uint8_t>::max(); }
|
const uint8_t ones() { return std::numeric_limits<uint8_t>::max(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void set_2bit_value(uint8_t *d, uint32_t i, uint8_t v) {
|
|
||||||
d[(i >> 2)] &= ((v << ((i & 3) << 1)) | dynamic_2bitset::vmask[i & 3]);
|
|
||||||
}
|
|
||||||
static uint32_t get_2bit_value(const uint8_t* d, uint32_t i) {
|
|
||||||
return (d[(i >> 2)] >> (((i & 3) << 1)) & 3);
|
|
||||||
}
|
|
||||||
static uint32_t nextpoweroftwo(uint32_t k) {
|
static uint32_t nextpoweroftwo(uint32_t k) {
|
||||||
if (k == 0) return 1;
|
if (k == 0) return 1;
|
||||||
k--;
|
k--;
|
||||||
|
@ -37,14 +37,12 @@ static uint8_t kBdzLookupIndex[] =
|
|||||||
|
|
||||||
namespace cxxmph {
|
namespace cxxmph {
|
||||||
|
|
||||||
const uint8_t MPHIndex::valuemask[] = { 0xfc, 0xf3, 0xcf, 0x3f};
|
|
||||||
|
|
||||||
MPHIndex::~MPHIndex() {
|
MPHIndex::~MPHIndex() {
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPHIndex::clear() {
|
void MPHIndex::clear() {
|
||||||
if (!deserialized_) delete [] ranktable_;
|
delete [] ranktable_;
|
||||||
ranktable_ = NULL;
|
ranktable_ = NULL;
|
||||||
ranktable_size_ = 0;
|
ranktable_size_ = 0;
|
||||||
// TODO(davi) implement me
|
// TODO(davi) implement me
|
||||||
@ -162,7 +160,7 @@ void MPHIndex::Ranking() {
|
|||||||
uint32_t size = k_ >> 2U;
|
uint32_t size = k_ >> 2U;
|
||||||
ranktable_size_ = static_cast<uint32_t>(
|
ranktable_size_ = static_cast<uint32_t>(
|
||||||
ceil(n_ / static_cast<double>(k_)));
|
ceil(n_ / static_cast<double>(k_)));
|
||||||
if (!deserialized_) delete [] ranktable_;
|
delete [] ranktable_;
|
||||||
ranktable_ = NULL;
|
ranktable_ = NULL;
|
||||||
uint32_t* ranktable = new uint32_t[ranktable_size_];
|
uint32_t* ranktable = new uint32_t[ranktable_size_];
|
||||||
memset(ranktable, 0, ranktable_size_*sizeof(uint32_t));
|
memset(ranktable, 0, ranktable_size_*sizeof(uint32_t));
|
||||||
@ -191,11 +189,11 @@ uint32_t MPHIndex::Rank(uint32_t vertex) const {
|
|||||||
beg_idx_v = beg_idx_b << 2;
|
beg_idx_v = beg_idx_b << 2;
|
||||||
// cerr << "beg_idx_v: " << beg_idx_v << endl;
|
// cerr << "beg_idx_v: " << beg_idx_v << endl;
|
||||||
// cerr << "base rank: " << base_rank << endl;
|
// cerr << "base rank: " << base_rank << endl;
|
||||||
cerr << "G: ";
|
// cerr << "G: ";
|
||||||
for (unsigned int i = 0; i < n_; ++i) {
|
// for (unsigned int i = 0; i < n_; ++i) {
|
||||||
cerr << static_cast<uint32_t>(g_[i]) << " ";
|
// cerr << static_cast<uint32_t>(g_[i]) << " ";
|
||||||
}
|
// }
|
||||||
cerr << endl;
|
// cerr << endl;
|
||||||
while (beg_idx_v < vertex) {
|
while (beg_idx_v < vertex) {
|
||||||
if (g_[beg_idx_v] != kUnassigned) ++base_rank;
|
if (g_[beg_idx_v] != kUnassigned) ++base_rank;
|
||||||
++beg_idx_v;
|
++beg_idx_v;
|
||||||
@ -204,14 +202,4 @@ uint32_t MPHIndex::Rank(uint32_t vertex) const {
|
|||||||
return base_rank;
|
return base_rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t MPHIndex::serialize_bytes_needed() const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
void MPHIndex::serialize(char* memory) const {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MPHIndex::deserialize(const char* serialized_memory) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cxxmph
|
} // namespace cxxmph
|
||||||
|
@ -45,8 +45,7 @@ class MPHIndex {
|
|||||||
public:
|
public:
|
||||||
MPHIndex(double c = 1.23, uint8_t b = 7) :
|
MPHIndex(double c = 1.23, uint8_t b = 7) :
|
||||||
c_(c), b_(b), m_(0), n_(0), k_(0), r_(1),
|
c_(c), b_(b), m_(0), n_(0), k_(0), r_(1),
|
||||||
ranktable_(NULL), ranktable_size_(0),
|
ranktable_(NULL), ranktable_size_(0) { }
|
||||||
deserialized_(false) { }
|
|
||||||
~MPHIndex();
|
~MPHIndex();
|
||||||
|
|
||||||
template <class SeededHashFcn, class ForwardIterator>
|
template <class SeededHashFcn, class ForwardIterator>
|
||||||
@ -69,13 +68,6 @@ class MPHIndex {
|
|||||||
template <class SeededHashFcn, class Key> // must agree with Reset
|
template <class SeededHashFcn, class Key> // must agree with Reset
|
||||||
void hash_vector(const Key& x, uint32_t* h) const;
|
void hash_vector(const Key& x, uint32_t* h) const;
|
||||||
|
|
||||||
// Serialization for mmap usage - not tested well, ping me if you care.
|
|
||||||
// Serialized tables are not guaranteed to work across versions or different
|
|
||||||
// endianness (although they could easily be made to be).
|
|
||||||
uint32_t serialize_bytes_needed() const;
|
|
||||||
void serialize(char *memory) const;
|
|
||||||
bool deserialize(const char* serialized_memory);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <class SeededHashFcn, class ForwardIterator>
|
template <class SeededHashFcn, class ForwardIterator>
|
||||||
bool Mapping(ForwardIterator begin, ForwardIterator end,
|
bool Mapping(ForwardIterator begin, ForwardIterator end,
|
||||||
@ -111,10 +103,6 @@ class MPHIndex {
|
|||||||
// The selected hash seed triplet for finding the edges in the minimal
|
// The selected hash seed triplet for finding the edges in the minimal
|
||||||
// perfect hash function graph.
|
// perfect hash function graph.
|
||||||
uint32_t hash_seed_[3];
|
uint32_t hash_seed_[3];
|
||||||
|
|
||||||
bool deserialized_;
|
|
||||||
|
|
||||||
static const uint8_t valuemask[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Template method needs to go in the header file.
|
// Template method needs to go in the header file.
|
||||||
@ -153,10 +141,8 @@ bool MPHIndex::Reset(
|
|||||||
}
|
}
|
||||||
if (iterations == 0) return false;
|
if (iterations == 0) return false;
|
||||||
Assigning(edges, queue);
|
Assigning(edges, queue);
|
||||||
fprintf(stderr, "Assignment finished\n");
|
|
||||||
std::vector<TriGraph::Edge>().swap(edges);
|
std::vector<TriGraph::Edge>().swap(edges);
|
||||||
Ranking();
|
Ranking();
|
||||||
deserialized_ = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ int main(int argc, char** argv) {
|
|||||||
b.insert(make_pair(i, i));
|
b.insert(make_pair(i, i));
|
||||||
}
|
}
|
||||||
b.rehash(b.size());
|
b.rehash(b.size());
|
||||||
fprintf(stderr, "Insertion finished\n");
|
|
||||||
for (int i = 0; i < 1000000; ++i) {
|
for (int i = 0; i < 1000000; ++i) {
|
||||||
auto it = b.find(i % num_keys);
|
auto it = b.find(i % num_keys);
|
||||||
if (it == b.end()) {
|
if (it == b.end()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user