Fixed small bugs.

This commit is contained in:
davi
2010-11-05 00:17:08 -02:00
parent 84f7da426c
commit 6c69aa0a8f
5 changed files with 8 additions and 257 deletions

View File

@@ -12,20 +12,20 @@ int main(int argc, char** argv) {
h.insert(std::make_pair("-1",-1));
cmph_hash_map<string, int>::const_iterator it;
for (it = h.begin(); it != h.end(); ++it) {
std::cout << it->first << " -> " << it->second << std::endl;
std::cerr << it->first << " -> " << it->second << std::endl;
}
std::cout << "Search -1 gives " << h.find("-1")->second << std::endl;
for (int i = 0; i < 1000; ++i) {
std::cerr << "Search -1 gives " << h.find("-1")->second << std::endl;
for (int i = 0; i < 100; ++i) {
char buf[10];
snprintf(buf, 10, "%d", i);
h.insert(std::make_pair(buf, i));
}
for (int j = 0; j < 1000; ++j) {
for (int j = 0; j < 100; ++j) {
for (int i = 1000; i > 0; --i) {
char buf[10];
snprintf(buf, 10, "%d", i - 1);
h.find(buf);
// std::cout << "Search " << i - 1 << " gives " << h.find(i - 1)->second << std::endl;
std::cerr << "Search " << i - 1 << " gives " << h.find(buf)->second << std::endl;
}
}
}

View File

@@ -24,7 +24,8 @@ class MPHTable {
typedef StringPiece key_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), m_(0), n_(0), k_(0), r_(0) { }
~MPHTable() {}
template <class ForwardIterator>

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>

View File

@@ -8,7 +8,6 @@
#include "../src/cmph_types.h"
#include "MurmurHash2.h"
#include "jenkins_hash.h"
#include "stringpiece.h"
namespace cxxmph {
@@ -16,25 +15,9 @@ namespace cxxmph {
template <class HashFun>
struct RandomlySeededHashFunction { };
class JenkinsStringPiece { };
class Murmur2StringPiece { };
class Murmur2Pod { };
template <>
struct RandomlySeededHashFunction<JenkinsStringPiece> {
RandomlySeededHashFunction() {
srand(1);
seed = 4;
}
cmph_uint32 operator()(const StringPiece& key) const {
return jenkins_hash(key.data(), key.length(), seed);
}
void operator()(const StringPiece& key, cmph_uint32* hashes) const {
__jenkins_hash_vector(seed, key.data(), key.length(), hashes);
}
cmph_uint32 seed;
};
template <>
struct RandomlySeededHashFunction<Murmur2StringPiece> {
RandomlySeededHashFunction() : seed(random()) { }