From b8610f52e18fbbf4538b4d1ab9c1955dd92525a9 Mon Sep 17 00:00:00 2001 From: Davi Reis Date: Tue, 20 Mar 2012 12:06:30 -0300 Subject: [PATCH] Some debugging, found that minimal version of mph_map is broken. Need to investigate. --- cxxmph/mph_index.cc | 22 ++++++++++++++-------- cxxmph/mph_index.h | 1 + cxxmph/mph_map.h | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cxxmph/mph_index.cc b/cxxmph/mph_index.cc index 8b6baec..5a6426e 100644 --- a/cxxmph/mph_index.cc +++ b/cxxmph/mph_index.cc @@ -180,20 +180,26 @@ void MPHIndex::Ranking() { } uint32_t MPHIndex::Rank(uint32_t vertex) const { + if (!g_.size()) return 0; uint32_t index = vertex >> b_; uint32_t base_rank = ranktable_[index]; uint32_t beg_idx_v = index << b_; uint32_t beg_idx_b = beg_idx_v >> 2; uint32_t end_idx_b = vertex >> 2; - while (beg_idx_b < end_idx_b) base_rank += kBdzLookupIndex[g_.data()[beg_idx_b++]]; + while (beg_idx_b < end_idx_b) { + assert(g_.data().size() > beg_idx_b); + base_rank += kBdzLookupIndex[g_.data()[beg_idx_b++]]; + } beg_idx_v = beg_idx_b << 2; - // cerr << "beg_idx_v: " << beg_idx_v << endl; - // cerr << "base rank: " << base_rank << endl; - // cerr << "G: "; - // for (unsigned int i = 0; i < n_; ++i) { - // cerr << static_cast(g_[i]) << " "; - // } - // cerr << endl; + /* + cerr << "beg_idx_v: " << beg_idx_v << endl; + cerr << "base rank: " << base_rank << endl; + cerr << "G: "; + for (unsigned int i = 0; i < n_; ++i) { + cerr << static_cast(g_[i]) << " "; + } + cerr << endl; + */ while (beg_idx_v < vertex) { if (g_[beg_idx_v] != kUnassigned) ++base_rank; ++beg_idx_v; diff --git a/cxxmph/mph_index.h b/cxxmph/mph_index.h index 6982534..11d9bea 100644 --- a/cxxmph/mph_index.h +++ b/cxxmph/mph_index.h @@ -65,6 +65,7 @@ class MPHIndex { uint32_t perfect_hash_size() const { return n_; } template // must agree with Reset uint32_t perfect_hash(const Key& x) const; + uint32_t minimal_perfect_hash_size() const { return size(); } template // must agree with Reset uint32_t minimal_perfect_hash(const Key& x) const; diff --git a/cxxmph/mph_map.h b/cxxmph/mph_map.h index 60a52a6..ceb3109 100644 --- a/cxxmph/mph_map.h +++ b/cxxmph/mph_map.h @@ -172,6 +172,7 @@ MPH_MAP_METHOD_DECL(void_type, pack)() { new_present.reserve(new_present.size() * 2); for (iterator it = begin(), it_end = end(); it != it_end; ++it) { size_type id = index_.perfect_hash(it->first); + assert(id < index_.perfect_hash_size()); assert(id < new_values.size()); new_values[id] = *it; new_present[id] = true;