1
Fork 0

Now going to adapt hash_map.

This commit is contained in:
Davi de Castro Reis 2010-10-28 17:53:40 -07:00
parent 22d149d3a8
commit 5fab722781
3 changed files with 11 additions and 7 deletions

View File

@ -165,8 +165,8 @@ void MPHTable::Ranking() {
cmph_uint32 MPHTable::Search(const key_type& key) const { cmph_uint32 MPHTable::Search(const key_type& key) const {
cmph_uint32 h[3]; cmph_uint32 h[3];
// for (int i = 0; i < 3; ++i) h[i] = hash_function_[i](key); for (int i = 0; i < 3; ++i) h[i] = hash_function_[i](key);
hash_function_[0](key, h); // hash_function_[0](key, h);
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);

View File

@ -22,7 +22,7 @@ class MPHTable {
// This class could be a template for both key type and hash function, but we // This class could be a template for both key type and hash function, but we
// chose to go with simplicity. // chose to go with simplicity.
typedef StringPiece key_type; typedef StringPiece key_type;
typedef RandomlySeededHashFunction<JenkinsStringPiece> hasher_type; typedef RandomlySeededHashFunction<Murmur2StringPiece> hasher_type;
MPHTable(double c = 1.23, cmph_uint8 b = 7) : c_(c), b_(b) { } MPHTable(double c = 1.23, cmph_uint8 b = 7) : c_(c), b_(b) { }
~MPHTable() {} ~MPHTable() {}
@ -82,8 +82,8 @@ bool MPHTable::Reset(ForwardIterator begin, ForwardIterator end) {
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_function_[i] = hasher_type(); for (int i = 0; i < 3; ++i) hash_function_[i] = hasher_type();
hash_function_[0] = hasher_type(); // hash_function_[0] = hasher_type();
cerr << "Seed: " << hash_function_[0].seed << endl; cerr << "Seed: " << hash_function_[0].seed << endl;
if (Mapping(begin, end, &edges, &queue)) break; if (Mapping(begin, end, &edges, &queue)) break;
else --iterations; else --iterations;
@ -103,8 +103,8 @@ bool MPHTable::Mapping(
TriGraph graph(n_, m_); TriGraph graph(n_, m_);
for (ForwardIterator it = begin; it != end; ++it) { for (ForwardIterator it = begin; it != end; ++it) {
cmph_uint32 h[3]; cmph_uint32 h[3];
// for (int i = 0; i < 3; ++i) h[i] = hash_function_[i](*it); for (int i = 0; i < 3; ++i) h[i] = hash_function_[i](*it);
hash_function_[0](*it, h); // hash_function_[0](*it, h);
cmph_uint32 v0 = h[0] % r_; cmph_uint32 v0 = h[0] % r_;
cmph_uint32 v1 = h[1] % r_ + r_; cmph_uint32 v1 = h[1] % r_ + r_;
cmph_uint32 v2 = h[2] % r_ + (r_ << 1); cmph_uint32 v2 = h[2] % r_ + (r_ << 1);

View File

@ -17,6 +17,10 @@ int main(int argc, char** argv) {
keys.push_back("joao"); keys.push_back("joao");
keys.push_back("maria"); keys.push_back("maria");
keys.push_back("bruno"); keys.push_back("bruno");
keys.push_back("paula");
keys.push_back("diego");
keys.push_back("diogo");
keys.push_back("algume");
MPHTable mphtable; MPHTable mphtable;
assert(mphtable.Reset(keys.begin(), keys.end())); assert(mphtable.Reset(keys.begin(), keys.end()));