1
Fork 0

All looks fine, commenting debug.

This commit is contained in:
davi 2010-11-09 03:38:46 -02:00
parent b0255a8269
commit bb2e9e28a8
5 changed files with 16 additions and 10 deletions

View File

@ -95,8 +95,6 @@ CMPH_METHOD_DECL(insert_return_type, insert)(const value_type& x) {
slack_.insert(std::make_pair(x.first, values_.size() - 1)); slack_.insert(std::make_pair(x.first, values_.size() - 1));
if (slack_.size() == table_.size() || if (slack_.size() == table_.size() ||
(slack_.size() >= 256 && table_.size() == 0)) { (slack_.size() >= 256 && table_.size() == 0)) {
// TODO(davi) debug only, remove afterwards
std::sort(values_.begin(), values_.end());
rehash(); rehash();
} }
it = find(x.first); it = find(x.first);

View File

@ -11,7 +11,7 @@ using cxxmph::cmph_hash_map;
int main(int argc, char** argv) { int main(int argc, char** argv) {
cmph_hash_map<int64_t, int64_t> b; cmph_hash_map<int64_t, int64_t> b;
for (int i = 0; i < 257; ++i) { for (int i = 0; i < 2*500; ++i) {
b.insert(make_pair(i, i)); b.insert(make_pair(i, i));
} }
/* /*

View File

@ -100,16 +100,17 @@ void MPHTable::Assigning(
// Initialize vector of half nibbles with all bits set. // Initialize vector of half nibbles with all bits set.
cmph_uint32 sizeg = static_cast<cmph_uint32>(ceil(n_/4.0)); cmph_uint32 sizeg = static_cast<cmph_uint32>(ceil(n_/4.0));
vector<cmph_uint8>(sizeg, std::numeric_limits<cmph_uint8>::max()).swap(g_); vector<cmph_uint8>(sizeg, std::numeric_limits<cmph_uint8>::max()).swap(g_);
assert(get_2bit_value(g_, 291) == kUnassigned);
cmph_uint32 nedges = m_; // for legibility cmph_uint32 nedges = m_; // for legibility
for (int i = nedges - 1; i + 1 >= 1; --i) { for (int i = nedges - 1; i + 1 >= 1; --i) {
current_edge = queue[i]; current_edge = queue[i];
cerr << "Current edge " << current_edge << " at queue pos " << i << endl; if (current_edge == 157) cerr << "Edge 157" << endl;
const TriGraph::Edge& e = edges[current_edge]; const TriGraph::Edge& e = edges[current_edge];
cerr << "B: " << e[0] << " " << e[1] << " " << e[2] << " -> " cerr << "B: " << e[0] << " " << e[1] << " " << e[2] << " -> "
<< get_2bit_value(g_, e[0]) << " " << get_2bit_value(g_, e[0]) << " "
<< get_2bit_value(g_, e[1]) << " " << get_2bit_value(g_, e[1]) << " "
<< get_2bit_value(g_, e[2]) << " " << endl; << get_2bit_value(g_, e[2]) << " edge " << current_edge << endl;
if (!marked_vertices[e[0]]) { if (!marked_vertices[e[0]]) {
if (!marked_vertices[e[1]]) { if (!marked_vertices[e[1]]) {
set_2bit_value(&g_, e[1], kUnassigned); set_2bit_value(&g_, e[1], kUnassigned);
@ -121,6 +122,7 @@ void MPHTable::Assigning(
marked_vertices[e[2]] = true; 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); 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; marked_vertices[e[0]] = true;
} else if (!marked_vertices[e[1]]) { } else if (!marked_vertices[e[1]]) {
if (!marked_vertices[e[2]]) { if (!marked_vertices[e[2]]) {
@ -128,9 +130,11 @@ void MPHTable::Assigning(
marked_vertices[e[2]] = true; 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); 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; marked_vertices[e[1]] = true;
} else { } else {
set_2bit_value(&g_, e[2], (8 - (get_2bit_value(g_, e[0]) + get_2bit_value(g_, e[1]))) % 3); 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; marked_vertices[e[2]] = true;
} }
cerr << "A: " << e[0] << " " << e[1] << " " << e[2] << " -> " cerr << "A: " << e[0] << " " << e[1] << " " << e[2] << " -> "
@ -177,8 +181,8 @@ cmph_uint32 MPHTable::Rank(cmph_uint32 vertex) const {
for (unsigned int i = 0; i < n_; ++i) { for (unsigned int i = 0; i < n_; ++i) {
cerr << get_2bit_value(g_, i) << " "; cerr << get_2bit_value(g_, i) << " ";
} }
cerr << endl;
while (beg_idx_v < vertex) { while (beg_idx_v < vertex) {
cerr << get_2bit_value(g_, beg_idx_v) << " ";
if (get_2bit_value(g_, beg_idx_v) != kUnassigned) ++base_rank; if (get_2bit_value(g_, beg_idx_v) != kUnassigned) ++base_rank;
++beg_idx_v; ++beg_idx_v;
} }

View File

@ -64,10 +64,10 @@ class MPHTable {
cmph_uint32 hash_seed_[3]; cmph_uint32 hash_seed_[3];
static const cmph_uint8 valuemask[]; static const cmph_uint8 valuemask[];
static void set_2bit_value(std::vector<cmph_uint8> *d, cmph_uint8 i, cmph_uint8 v) { static void set_2bit_value(std::vector<cmph_uint8> *d, cmph_uint32 i, cmph_uint8 v) {
(*d)[(i >> 2)] &= (v << ((i & 3) << 1)) | valuemask[i & 3]; (*d)[(i >> 2)] &= (v << ((i & 3) << 1)) | valuemask[i & 3];
} }
static cmph_uint32 get_2bit_value(const std::vector<cmph_uint8>& d, cmph_uint8 i) { static cmph_uint32 get_2bit_value(const std::vector<cmph_uint8>& d, cmph_uint32 i) {
return (d[(i >> 2)] >> ((i & 3) << 1)) & 3; return (d[(i >> 2)] >> ((i & 3) << 1)) & 3;
} }
@ -85,12 +85,13 @@ bool MPHTable::Reset(ForwardIterator begin, ForwardIterator end) {
cerr << "m " << m_ << " n " << n_ << " r " << r_ << endl; cerr << "m " << m_ << " n " << n_ << " r " << r_ << endl;
int iterations = 1000; int iterations = 10;
std::vector<TriGraph::Edge> edges; std::vector<TriGraph::Edge> edges;
std::vector<cmph_uint32> queue; std::vector<cmph_uint32> queue;
while (1) { while (1) {
cerr << "Iterations missing: " << iterations << endl; cerr << "Iterations missing: " << iterations << endl;
for (int i = 0; i < 3; ++i) hash_seed_[i] = random(); for (int i = 0; i < 3; ++i) hash_seed_[i] = random() % m_;
// for (int i = 0; i < 3; ++i) hash_seed_[i] = random() + i;
if (Mapping<SeededHashFcn>(begin, end, &edges, &queue)) break; if (Mapping<SeededHashFcn>(begin, end, &edges, &queue)) break;
else --iterations; else --iterations;
if (iterations == 0) break; if (iterations == 0) break;

View File

@ -444,6 +444,7 @@ static void assigning(bdz_config_data_t *bdz, bdz_graph3_t* graph3, bdz_queue_t
SETBIT(marked_vertices, v2); SETBIT(marked_vertices, v2);
} }
SETVALUE1(bdz->g, v0, (6-(GETVALUE(bdz->g, v1) + GETVALUE(bdz->g,v2)))%3); SETVALUE1(bdz->g, v0, (6-(GETVALUE(bdz->g, v1) + GETVALUE(bdz->g,v2)))%3);
if (v0 == 291) fprintf(stderr, "Vertex 291 updated at case 1\n");
SETBIT(marked_vertices, v0); SETBIT(marked_vertices, v0);
} else if(!GETBIT(marked_vertices, v1)) { } else if(!GETBIT(marked_vertices, v1)) {
if(!GETBIT(marked_vertices, v2)) if(!GETBIT(marked_vertices, v2))
@ -452,9 +453,11 @@ static void assigning(bdz_config_data_t *bdz, bdz_graph3_t* graph3, bdz_queue_t
SETBIT(marked_vertices, v2); SETBIT(marked_vertices, v2);
} }
SETVALUE1(bdz->g, v1, (7-(GETVALUE(bdz->g, v0)+GETVALUE(bdz->g, v2)))%3); SETVALUE1(bdz->g, v1, (7-(GETVALUE(bdz->g, v0)+GETVALUE(bdz->g, v2)))%3);
if (v1 == 291) fprintf(stderr, "Vertex 291 updated at case 1\n");
SETBIT(marked_vertices, v1); SETBIT(marked_vertices, v1);
}else { }else {
SETVALUE1(bdz->g, v2, (8-(GETVALUE(bdz->g,v0)+GETVALUE(bdz->g, v1)))%3); SETVALUE1(bdz->g, v2, (8-(GETVALUE(bdz->g,v0)+GETVALUE(bdz->g, v1)))%3);
if (v2 == 291) fprintf(stderr, "Vertex 291 updated at case 1\n");
SETBIT(marked_vertices, v2); SETBIT(marked_vertices, v2);
} }
DEBUGP("A:%u %u %u -- %u %u %u\n", v0, v1, v2, GETVALUE(bdz->g, v0), GETVALUE(bdz->g, v1), GETVALUE(bdz->g, v2)); DEBUGP("A:%u %u %u -- %u %u %u\n", v0, v1, v2, GETVALUE(bdz->g, v0), GETVALUE(bdz->g, v1), GETVALUE(bdz->g, v2));