Fixed first_edge initialization bug.

This commit is contained in:
davi
2010-11-08 22:02:18 -02:00
parent cde9f72c9e
commit 676d34073c
8 changed files with 84 additions and 57 deletions

View File

@@ -110,8 +110,10 @@ CMPH_METHOD_DECL(void_type, rehash)() {
<< slack_.size() << " keys in slack "
<< values_.size() << " key in total" << std::endl;
slack_type().swap(slack_);
table_.Reset(make_iterator_first(values_.begin()),
make_iterator_first(values_.end()));
bool success = table_.Reset(
make_iterator_first(values_.begin()),
make_iterator_first(values_.end()));
assert(success);
std::vector<value_type> new_values(values_.size());
for (const_iterator it = values_.begin(), end = values_.end();
it != end; ++it) {

View File

@@ -69,6 +69,7 @@ bool MPHTable::GenerateQueue(
// At this point queue head is the number of edges touching at least one
// vertex of degree 1.
cerr << "Queue head " << queue_head << " Queue tail " << queue_tail << endl;
graph->DebugGraph();
while (queue_tail != queue_head) {
cmph_uint32 current_edge = queue[queue_tail++];
graph->RemoveEdge(current_edge);

View File

@@ -3,6 +3,7 @@
// Minimal perfect hash abstraction implementing the BDZ algorithm
#include <cassert>
#include <cmath>
#include <unordered_map> // for std::hash
#include <vector>
@@ -129,6 +130,11 @@ cmph_uint32 MPHTable::index(const Key& key) const {
h[0] = h[0] % r_;
h[1] = h[1] % r_ + r_;
h[2] = h[2] % r_ + (r_ << 1);
assert(g_.size());
cerr << "g_.size() " << g_.size() << " h0 >> 2 " << (h[0] >> 2) << endl;
assert((h[0] >> 2) <g_.size());
assert((h[1] >> 2) <g_.size());
assert((h[2] >> 2) <g_.size());
cmph_uint32 vertex = h[(get_2bit_value(g_, h[0]) + get_2bit_value(g_, h[1]) + get_2bit_value(g_, h[2])) % 3];
cerr << "Search found vertex " << vertex << endl;
return Rank(vertex);

View File

@@ -9,7 +9,7 @@ using std::endl;
using std::vector;
namespace {
static const cmph_uint8 kInvalidEdge = std::numeric_limits<cmph_uint8>::max();
static const cmph_uint32 kInvalidEdge = std::numeric_limits<cmph_uint32>::max();
}
namespace cxxmph {
@@ -65,5 +65,17 @@ void TriGraph::RemoveEdge(cmph_uint32 current_edge) {
--vertex_degree_[vertex];
}
}
void TriGraph::DebugGraph() const {
int i;
for(i = 0; i < edges_.size(); i++){
cerr << i << " " << edges_[i][0] << " " << edges_[i][1] << " " << edges_[i][2]
<< " nexts " << next_edge_[i][0] << " " << next_edge_[i][1] << " " << next_edge_[i][2] << endl;
}
for(i = 0; i < first_edge_.size();i++){
cerr << "first for vertice " <<i << " " << first_edge_[i] << endl;
}
}
} // namespace cxxmph

View File

@@ -30,6 +30,7 @@ class TriGraph {
void AddEdge(const Edge& edge);
void RemoveEdge(cmph_uint32 edge_id);
void ExtractEdgesAndClear(std::vector<Edge>* edges);
void DebugGraph() const;
const std::vector<Edge>& edges() const { return edges_; }
const std::vector<cmph_uint8>& vertex_degree() const { return vertex_degree_; }