Fixed first_edge initialization bug.
This commit is contained in:
parent
cde9f72c9e
commit
676d34073c
@ -110,8 +110,10 @@ CMPH_METHOD_DECL(void_type, rehash)() {
|
|||||||
<< slack_.size() << " keys in slack "
|
<< slack_.size() << " keys in slack "
|
||||||
<< values_.size() << " key in total" << std::endl;
|
<< values_.size() << " key in total" << std::endl;
|
||||||
slack_type().swap(slack_);
|
slack_type().swap(slack_);
|
||||||
table_.Reset(make_iterator_first(values_.begin()),
|
bool success = table_.Reset(
|
||||||
make_iterator_first(values_.end()));
|
make_iterator_first(values_.begin()),
|
||||||
|
make_iterator_first(values_.end()));
|
||||||
|
assert(success);
|
||||||
std::vector<value_type> new_values(values_.size());
|
std::vector<value_type> new_values(values_.size());
|
||||||
for (const_iterator it = values_.begin(), end = values_.end();
|
for (const_iterator it = values_.begin(), end = values_.end();
|
||||||
it != end; ++it) {
|
it != end; ++it) {
|
||||||
|
@ -69,6 +69,7 @@ bool MPHTable::GenerateQueue(
|
|||||||
// At this point queue head is the number of edges touching at least one
|
// At this point queue head is the number of edges touching at least one
|
||||||
// vertex of degree 1.
|
// vertex of degree 1.
|
||||||
cerr << "Queue head " << queue_head << " Queue tail " << queue_tail << endl;
|
cerr << "Queue head " << queue_head << " Queue tail " << queue_tail << endl;
|
||||||
|
graph->DebugGraph();
|
||||||
while (queue_tail != queue_head) {
|
while (queue_tail != queue_head) {
|
||||||
cmph_uint32 current_edge = queue[queue_tail++];
|
cmph_uint32 current_edge = queue[queue_tail++];
|
||||||
graph->RemoveEdge(current_edge);
|
graph->RemoveEdge(current_edge);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
// Minimal perfect hash abstraction implementing the BDZ algorithm
|
// Minimal perfect hash abstraction implementing the BDZ algorithm
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <unordered_map> // for std::hash
|
#include <unordered_map> // for std::hash
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -129,6 +130,11 @@ cmph_uint32 MPHTable::index(const Key& key) const {
|
|||||||
h[0] = h[0] % r_;
|
h[0] = h[0] % r_;
|
||||||
h[1] = h[1] % r_ + r_;
|
h[1] = h[1] % r_ + r_;
|
||||||
h[2] = h[2] % r_ + (r_ << 1);
|
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];
|
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;
|
cerr << "Search found vertex " << vertex << endl;
|
||||||
return Rank(vertex);
|
return Rank(vertex);
|
||||||
|
@ -9,7 +9,7 @@ using std::endl;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
namespace {
|
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 {
|
namespace cxxmph {
|
||||||
@ -65,5 +65,17 @@ void TriGraph::RemoveEdge(cmph_uint32 current_edge) {
|
|||||||
--vertex_degree_[vertex];
|
--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
|
} // namespace cxxmph
|
||||||
|
@ -30,6 +30,7 @@ class TriGraph {
|
|||||||
void AddEdge(const Edge& edge);
|
void AddEdge(const Edge& edge);
|
||||||
void RemoveEdge(cmph_uint32 edge_id);
|
void RemoveEdge(cmph_uint32 edge_id);
|
||||||
void ExtractEdgesAndClear(std::vector<Edge>* edges);
|
void ExtractEdgesAndClear(std::vector<Edge>* edges);
|
||||||
|
void DebugGraph() const;
|
||||||
|
|
||||||
const std::vector<Edge>& edges() const { return edges_; }
|
const std::vector<Edge>& edges() const { return edges_; }
|
||||||
const std::vector<cmph_uint8>& vertex_degree() const { return vertex_degree_; }
|
const std::vector<cmph_uint8>& vertex_degree() const { return vertex_degree_; }
|
||||||
|
@ -2,7 +2,7 @@ bin_PROGRAMS = cmph
|
|||||||
lib_LTLIBRARIES = libcmph.la
|
lib_LTLIBRARIES = libcmph.la
|
||||||
include_HEADERS = cmph.h cmph_types.h cmph_time.h chd_ph.h
|
include_HEADERS = cmph.h cmph_types.h cmph_time.h chd_ph.h
|
||||||
libcmph_la_SOURCES = hash.h hash.c \
|
libcmph_la_SOURCES = hash.h hash.c \
|
||||||
jenkins_hash.h jenkins_hash.c\
|
jenkins_hash.h jenkins_hash.c MurmurHash2.h\
|
||||||
hash_state.h debug.h \
|
hash_state.h debug.h \
|
||||||
vstack.h vstack.c vqueue.h vqueue.c\
|
vstack.h vstack.c vqueue.h vqueue.c\
|
||||||
graph.h graph.c bitbool.h \
|
graph.h graph.c bitbool.h \
|
||||||
|
@ -178,6 +178,7 @@ static int bdz_generate_queue(cmph_uint32 nedges, cmph_uint32 nvertices, bdz_que
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
DEBUGP("Queue head %d Queue tail %d\n", queue_head, queue_tail);
|
DEBUGP("Queue head %d Queue tail %d\n", queue_head, queue_tail);
|
||||||
|
bdz_dump_graph(graph3,graph3->nedges,graph3->nedges+graph3->nedges/4);
|
||||||
while(queue_tail!=queue_head){
|
while(queue_tail!=queue_head){
|
||||||
curr_edge=queue[queue_tail++];
|
curr_edge=queue[queue_tail++];
|
||||||
bdz_remove_edge(graph3,curr_edge);
|
bdz_remove_edge(graph3,curr_edge);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "MurmurHash2.h"
|
||||||
|
|
||||||
#define hashsize(n) ((cmph_uint32)1<<(n))
|
#define hashsize(n) ((cmph_uint32)1<<(n))
|
||||||
#define hashmask(n) (hashsize(n)-1)
|
#define hashmask(n) (hashsize(n)-1)
|
||||||
@ -99,63 +100,67 @@ void jenkins_state_destroy(jenkins_state_t *state)
|
|||||||
|
|
||||||
inline void __jenkins_hash_vector(cmph_uint32 seed, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes)
|
inline void __jenkins_hash_vector(cmph_uint32 seed, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes)
|
||||||
{
|
{
|
||||||
register cmph_uint32 len, length;
|
int i;
|
||||||
|
for (i = 0; i < 3; ++i) {
|
||||||
/* Set up the internal state */
|
hashes[i] = MurmurHash2(k, keylen, seed + i);
|
||||||
length = keylen;
|
|
||||||
len = length;
|
|
||||||
hashes[0] = hashes[1] = 0x9e3779b9; /* the golden ratio; an arbitrary value */
|
|
||||||
hashes[2] = seed; /* the previous hash value - seed in our case */
|
|
||||||
|
|
||||||
/*---------------------------------------- handle most of the key */
|
|
||||||
while (len >= 12)
|
|
||||||
{
|
|
||||||
hashes[0] += ((cmph_uint32)k[0] +((cmph_uint32)k[1]<<8) +((cmph_uint32)k[2]<<16) +((cmph_uint32)k[3]<<24));
|
|
||||||
hashes[1] += ((cmph_uint32)k[4] +((cmph_uint32)k[5]<<8) +((cmph_uint32)k[6]<<16) +((cmph_uint32)k[7]<<24));
|
|
||||||
hashes[2] += ((cmph_uint32)k[8] +((cmph_uint32)k[9]<<8) +((cmph_uint32)k[10]<<16)+((cmph_uint32)k[11]<<24));
|
|
||||||
mix(hashes[0],hashes[1],hashes[2]);
|
|
||||||
k += 12; len -= 12;
|
|
||||||
}
|
}
|
||||||
|
// register cmph_uint32 len, length;
|
||||||
/*------------------------------------- handle the last 11 bytes */
|
//
|
||||||
hashes[2] += length;
|
// /* Set up the internal state */
|
||||||
switch(len) /* all the case statements fall through */
|
// length = keylen;
|
||||||
{
|
// len = length;
|
||||||
case 11:
|
// hashes[0] = hashes[1] = 0x9e3779b9; /* the golden ratio; an arbitrary value */
|
||||||
hashes[2] +=((cmph_uint32)k[10]<<24);
|
// hashes[2] = seed; /* the previous hash value - seed in our case */
|
||||||
case 10:
|
//
|
||||||
hashes[2] +=((cmph_uint32)k[9]<<16);
|
// /*---------------------------------------- handle most of the key */
|
||||||
case 9 :
|
// while (len >= 12)
|
||||||
hashes[2] +=((cmph_uint32)k[8]<<8);
|
// {
|
||||||
/* the first byte of hashes[2] is reserved for the length */
|
// hashes[0] += ((cmph_uint32)k[0] +((cmph_uint32)k[1]<<8) +((cmph_uint32)k[2]<<16) +((cmph_uint32)k[3]<<24));
|
||||||
case 8 :
|
// hashes[1] += ((cmph_uint32)k[4] +((cmph_uint32)k[5]<<8) +((cmph_uint32)k[6]<<16) +((cmph_uint32)k[7]<<24));
|
||||||
hashes[1] +=((cmph_uint32)k[7]<<24);
|
// hashes[2] += ((cmph_uint32)k[8] +((cmph_uint32)k[9]<<8) +((cmph_uint32)k[10]<<16)+((cmph_uint32)k[11]<<24));
|
||||||
case 7 :
|
// mix(hashes[0],hashes[1],hashes[2]);
|
||||||
hashes[1] +=((cmph_uint32)k[6]<<16);
|
// k += 12; len -= 12;
|
||||||
case 6 :
|
// }
|
||||||
hashes[1] +=((cmph_uint32)k[5]<<8);
|
//
|
||||||
case 5 :
|
// /*------------------------------------- handle the last 11 bytes */
|
||||||
hashes[1] +=(cmph_uint8) k[4];
|
// hashes[2] += length;
|
||||||
case 4 :
|
// switch(len) /* all the case statements fall through */
|
||||||
hashes[0] +=((cmph_uint32)k[3]<<24);
|
// {
|
||||||
case 3 :
|
// case 11:
|
||||||
hashes[0] +=((cmph_uint32)k[2]<<16);
|
// hashes[2] +=((cmph_uint32)k[10]<<24);
|
||||||
case 2 :
|
// case 10:
|
||||||
hashes[0] +=((cmph_uint32)k[1]<<8);
|
// hashes[2] +=((cmph_uint32)k[9]<<16);
|
||||||
case 1 :
|
// case 9 :
|
||||||
hashes[0] +=(cmph_uint8)k[0];
|
// hashes[2] +=((cmph_uint32)k[8]<<8);
|
||||||
/* case 0: nothing left to add */
|
// /* the first byte of hashes[2] is reserved for the length */
|
||||||
}
|
// case 8 :
|
||||||
|
// hashes[1] +=((cmph_uint32)k[7]<<24);
|
||||||
mix(hashes[0],hashes[1],hashes[2]);
|
// case 7 :
|
||||||
|
// hashes[1] +=((cmph_uint32)k[6]<<16);
|
||||||
|
// case 6 :
|
||||||
|
// hashes[1] +=((cmph_uint32)k[5]<<8);
|
||||||
|
// case 5 :
|
||||||
|
// hashes[1] +=(cmph_uint8) k[4];
|
||||||
|
// case 4 :
|
||||||
|
// hashes[0] +=((cmph_uint32)k[3]<<24);
|
||||||
|
// case 3 :
|
||||||
|
// hashes[0] +=((cmph_uint32)k[2]<<16);
|
||||||
|
// case 2 :
|
||||||
|
// hashes[0] +=((cmph_uint32)k[1]<<8);
|
||||||
|
// case 1 :
|
||||||
|
// hashes[0] +=(cmph_uint8)k[0];
|
||||||
|
// /* case 0: nothing left to add */
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// mix(hashes[0],hashes[1],hashes[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmph_uint32 jenkins_hash(jenkins_state_t *state, const char *k, cmph_uint32 keylen)
|
cmph_uint32 jenkins_hash(jenkins_state_t *state, const char *k, cmph_uint32 keylen)
|
||||||
{
|
{
|
||||||
cmph_uint32 hashes[3];
|
// cmph_uint32 hashes[3];
|
||||||
__jenkins_hash_vector(state->seed, k, keylen, hashes);
|
// __jenkins_hash_vector(state->seed, k, keylen, hashes);
|
||||||
return hashes[2];
|
// return hashes[2];
|
||||||
/* cmph_uint32 a, b, c;
|
cmph_uint32 a, b, c;
|
||||||
cmph_uint32 len, length;
|
cmph_uint32 len, length;
|
||||||
|
|
||||||
// Set up the internal state
|
// Set up the internal state
|
||||||
@ -209,7 +214,6 @@ cmph_uint32 jenkins_hash(jenkins_state_t *state, const char *k, cmph_uint32 keyl
|
|||||||
/// report the result
|
/// report the result
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jenkins_hash_vector_(jenkins_state_t *state, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes)
|
void jenkins_hash_vector_(jenkins_state_t *state, const char *k, cmph_uint32 keylen, cmph_uint32 * hashes)
|
||||||
|
Loading…
Reference in New Issue
Block a user