From 4fabbd9d25a54fda09bfa6ee8b6eddc32f23a1b2 Mon Sep 17 00:00:00 2001 From: Davi de Castro Reis Date: Sat, 9 Jun 2012 02:47:37 -0300 Subject: [PATCH] Less branches. --- cxxmph/mph_index.cc | 2 +- cxxmph/mph_index.h | 3 +-- cxxmph/mph_index_test.cc | 13 +++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cxxmph/mph_index.cc b/cxxmph/mph_index.cc index 9e24fbd..afeae14 100644 --- a/cxxmph/mph_index.cc +++ b/cxxmph/mph_index.cc @@ -182,7 +182,7 @@ void MPHIndex::Ranking() { } uint32_t MPHIndex::Rank(uint32_t vertex) const { - if (!g_.size()) return 0; + if (!ranktable_size_) return 0; uint32_t index = vertex >> b_; uint32_t base_rank = ranktable_[index]; uint32_t beg_idx_v = index << b_; diff --git a/cxxmph/mph_index.h b/cxxmph/mph_index.h index 9ab645c..dd25668 100644 --- a/cxxmph/mph_index.h +++ b/cxxmph/mph_index.h @@ -45,7 +45,7 @@ namespace cxxmph { class MPHIndex { public: MPHIndex(bool square = false, double c = 1.23, uint8_t b = 7) : - c_(c), b_(b), m_(0), n_(0), k_(0), square_(square), r_(1), + c_(c), b_(b), m_(0), n_(0), k_(0), square_(square), r_(1), g_(8, true), ranktable_(NULL), ranktable_size_(0) { } ~MPHIndex(); @@ -174,7 +174,6 @@ bool MPHIndex::Mapping( template uint32_t MPHIndex::perfect_square(const Key& key) const { - if (!g_.size()) return 0; h128 h = SeededHashFcn().hash128(key, hash_seed_[0]); h[0] = (h[0] & (r_-1)) + nest_displacement_[0]; h[1] = (h[1] & (r_-1)) + nest_displacement_[1]; diff --git a/cxxmph/mph_index_test.cc b/cxxmph/mph_index_test.cc index d414bac..d0ff418 100644 --- a/cxxmph/mph_index_test.cc +++ b/cxxmph/mph_index_test.cc @@ -33,10 +33,11 @@ int main(int argc, char** argv) { cerr << endl; sort(ids.begin(), ids.end()); for (vector::size_type i = 0; i < ids.size(); ++i) assert(ids[i] == static_cast::value_type>(i)); - /* - char* serialized = new char[mph_index.serialize_bytes_needed()]; - mph_index.serialize(serialized); - SimpleMPHIndex other_mph_index; - other_mph_index.deserialize(serialized); - */ + + FlexibleMPHIndex>::hash_function> square_empty; + auto id = square_empty.index(1); + FlexibleMPHIndex>::hash_function> unordered_empty; + id ^= unordered_empty.index(1); + FlexibleMPHIndex>::hash_function> minimal_empty; + id ^= minimal_empty.index(1); }