From 62ac3f4bded4443d7561fd640133a85554948dbd Mon Sep 17 00:00:00 2001 From: davi Date: Tue, 9 Nov 2010 03:51:33 -0200 Subject: [PATCH] All fine, time to optimize. --- cxxmph/cmph_hash_map_test.cc | 2 +- cxxmph/mphtable.cc | 45 ++++++++++++++++++------------------ cxxmph/mphtable.h | 6 ++--- cxxmph/trigraph.cc | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/cxxmph/cmph_hash_map_test.cc b/cxxmph/cmph_hash_map_test.cc index a75e0cd..73c3290 100644 --- a/cxxmph/cmph_hash_map_test.cc +++ b/cxxmph/cmph_hash_map_test.cc @@ -11,7 +11,7 @@ using cxxmph::cmph_hash_map; int main(int argc, char** argv) { cmph_hash_map b; - for (int i = 0; i < 2*500; ++i) { + for (int i = 0; i < 2*1000*1000; ++i) { b.insert(make_pair(i, i)); } /* diff --git a/cxxmph/mphtable.cc b/cxxmph/mphtable.cc index b46818c..ba90ae2 100644 --- a/cxxmph/mphtable.cc +++ b/cxxmph/mphtable.cc @@ -60,16 +60,18 @@ bool MPHTable::GenerateQueue( } } } + /* for (unsigned int i = 0; i < marked_edge.size(); ++i) { cerr << "vertex with degree " << static_cast(graph->vertex_degree()[i]) << " marked " << marked_edge[i] << endl; } for (unsigned int i = 0; i < queue.size(); ++i) { cerr << "vertex " << i << " queued at " << queue[i] << endl; } + */ // 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(); + // 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); @@ -85,9 +87,11 @@ bool MPHTable::GenerateQueue( } } } + /* for (unsigned int i = 0; i < queue.size(); ++i) { cerr << "vertex " << i << " queued at " << queue[i] << endl; } + */ int cycles = queue_head - nedges; if (cycles == 0) queue.swap(*queue_output); return cycles == 0; @@ -100,17 +104,15 @@ void MPHTable::Assigning( // Initialize vector of half nibbles with all bits set. cmph_uint32 sizeg = static_cast(ceil(n_/4.0)); vector(sizeg, std::numeric_limits::max()).swap(g_); - assert(get_2bit_value(g_, 291) == kUnassigned); cmph_uint32 nedges = m_; // for legibility for (int i = nedges - 1; i + 1 >= 1; --i) { current_edge = queue[i]; - if (current_edge == 157) cerr << "Edge 157" << endl; const TriGraph::Edge& e = edges[current_edge]; - cerr << "B: " << e[0] << " " << e[1] << " " << e[2] << " -> " - << get_2bit_value(g_, e[0]) << " " - << get_2bit_value(g_, e[1]) << " " - << get_2bit_value(g_, e[2]) << " edge " << current_edge << endl; + // cerr << "B: " << e[0] << " " << e[1] << " " << e[2] << " -> " + // << get_2bit_value(g_, e[0]) << " " + // << get_2bit_value(g_, e[1]) << " " + // << get_2bit_value(g_, e[2]) << " edge " << current_edge << endl; if (!marked_vertices[e[0]]) { if (!marked_vertices[e[1]]) { set_2bit_value(&g_, e[1], kUnassigned); @@ -122,7 +124,6 @@ void MPHTable::Assigning( marked_vertices[e[2]] = true; } set_2bit_value(&g_, e[0], (6 - (get_2bit_value(g_, e[1]) + get_2bit_value(g_, e[2]))) % 3); - if (e[0] == 291) cerr << "Vertex 291 " << get_2bit_value(g_, 291) << " updated at case 1" << endl; marked_vertices[e[0]] = true; } else if (!marked_vertices[e[1]]) { if (!marked_vertices[e[2]]) { @@ -130,17 +131,15 @@ void MPHTable::Assigning( marked_vertices[e[2]] = true; } set_2bit_value(&g_, e[1], (7 - (get_2bit_value(g_, e[0]) + get_2bit_value(g_, e[2]))) % 3); - if (e[1] == 291) cerr << "Vertex 291 " << get_2bit_value(g_, 291) << " updated at case 2" << endl; marked_vertices[e[1]] = true; } else { set_2bit_value(&g_, e[2], (8 - (get_2bit_value(g_, e[0]) + get_2bit_value(g_, e[1]))) % 3); - if (e[2] == 291) cerr << "Vertex 291 " << get_2bit_value(g_, 291) << " updated at case 3" << endl; marked_vertices[e[2]] = true; } - cerr << "A: " << e[0] << " " << e[1] << " " << e[2] << " -> " - << get_2bit_value(g_, e[0]) << " " - << get_2bit_value(g_, e[1]) << " " - << get_2bit_value(g_, e[2]) << " " << endl; + // cerr << "A: " << e[0] << " " << e[1] << " " << e[2] << " -> " + // << get_2bit_value(g_, e[0]) << " " + // << get_2bit_value(g_, e[1]) << " " + // << get_2bit_value(g_, e[2]) << " " << endl; } } @@ -174,19 +173,19 @@ cmph_uint32 MPHTable::Rank(cmph_uint32 vertex) const { cmph_uint32 end_idx_b = vertex >> 2; while (beg_idx_b < end_idx_b) base_rank += kBdzLookupTable[g_[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 << "beg_idx_v: " << beg_idx_v << endl; + // cerr << "base rank: " << base_rank << endl; - cerr << "G: "; - for (unsigned int i = 0; i < n_; ++i) { - cerr << get_2bit_value(g_, i) << " "; - } - cerr << endl; + //cerr << "G: "; + // for (unsigned int i = 0; i < n_; ++i) { + // cerr << get_2bit_value(g_, i) << " "; + //} + // cerr << endl; while (beg_idx_v < vertex) { if (get_2bit_value(g_, beg_idx_v) != kUnassigned) ++base_rank; ++beg_idx_v; } - cerr << "Base rank: " << base_rank << endl; + // cerr << "Base rank: " << base_rank << endl; return base_rank; } diff --git a/cxxmph/mphtable.h b/cxxmph/mphtable.h index c1394c1..02250a9 100644 --- a/cxxmph/mphtable.h +++ b/cxxmph/mphtable.h @@ -114,7 +114,7 @@ bool MPHTable::Mapping( cmph_uint32 v0 = h[0] % r_; cmph_uint32 v1 = h[1] % r_ + r_; cmph_uint32 v2 = h[2] % r_ + (r_ << 1); - cerr << "Key: " << *it << " edge " << it - begin << " (" << v0 << "," << v1 << "," << v2 << ")" << endl; + // cerr << "Key: " << *it << " edge " << it - begin << " (" << v0 << "," << v1 << "," << v2 << ")" << endl; graph.AddEdge(TriGraph::Edge(v0, v1, v2)); } if (GenerateQueue(&graph, queue)) { @@ -132,12 +132,12 @@ cmph_uint32 MPHTable::index(const Key& key) const { 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; + //cerr << "g_.size() " << g_.size() << " h0 >> 2 " << (h[0] >> 2) << endl; assert((h[0] >> 2) > 2) > 2)