diff --git a/cxxmph/Makefile.am b/cxxmph/Makefile.am index 7566f00..4c8989a 100644 --- a/cxxmph/Makefile.am +++ b/cxxmph/Makefile.am @@ -1,8 +1,8 @@ bin_PROGRAMS = cmph_hash_map_test mphtable_test trigraph_test lib_LTLIBRARIES = libcxxmph.la -include_HEADERS = cmph_hash_map.h mphtable.h MurmurHash2.h trigraph.h cmph_hash_function.h +include_HEADERS = cmph_hash_map.h mphtable.h MurmurHash2.h trigraph.h cmph_hash_function.h stringpiece.h -libcxxmph_la_SOURCES = MurmurHash2.h trigragh.h trigraph.cc mphtable.h mphtable.cc cmph_hash_function.h +libcxxmph_la_SOURCES = MurmurHash2.h trigragh.h trigraph.cc mphtable.h mphtable.cc cmph_hash_function.h stringpiece.h libcxxmph_la_LDFLAGS = -version-info 0:0:0 cmph_hash_map_test_LDADD = libcxxmph.la diff --git a/cxxmph/cmph_hash_function.h b/cxxmph/cmph_hash_function.h index 900491d..e607e48 100644 --- a/cxxmph/cmph_hash_function.h +++ b/cxxmph/cmph_hash_function.h @@ -25,7 +25,7 @@ struct Murmur2StringPiece { template cmph_uint32 operator()(const Key& k) const { StringPiece s(k); - return MurmurHash2(k.data(), k.length(), 1 /* seed */); + return MurmurHash2(s.data(), s.length(), 1 /* seed */); } }; @@ -42,7 +42,7 @@ struct seeded_hash_function { template cmph_uint32 operator()(const Key& k, cmph_uint32 seed) const { StringPiece s(k); - return MurmurHash2(k.data(), k.length(), seed); + return MurmurHash2(s.data(), s.length(), seed); } }; diff --git a/cxxmph/cmph_hash_map.h b/cxxmph/cmph_hash_map.h index a606c32..51ddcef 100644 --- a/cxxmph/cmph_hash_map.h +++ b/cxxmph/cmph_hash_map.h @@ -4,7 +4,6 @@ #include "MurmurHash2.h" #include "mphtable.h" -#include "iterator_first.h" namespace __gnu_cxx { template <> struct hash { diff --git a/cxxmph/iterator_first.h b/cxxmph/iterator_first.h deleted file mode 100644 index 1babb77..0000000 --- a/cxxmph/iterator_first.h +++ /dev/null @@ -1,43 +0,0 @@ -#include "stringpiece.h" - -namespace cxxmph { - -template -struct iterator_first : public iterator { - iterator_first(iterator it) : iterator(it) { } - const typename iterator::value_type::first_type& operator*() const { - return this->iterator::operator*().first; - } -}; - -template -iterator_first make_iterator_first(iterator it) { - return iterator_first(it); -} - -template class MakeStringPiece { - public: - StringPiece operator()(const value& v) { return StringPiece(reinterpret_cast(&v), sizeof(value)); } -}; -template <> class MakeStringPiece { - public: - StringPiece operator()(const std::string& v) { return StringPiece(v); } -}; -template <> class MakeStringPiece { - public: - StringPiece operator()(const char* v) { return StringPiece(v); } -}; - -template -struct iterator_stringpiece : public iterator { - iterator_stringpiece(iterator it) : iterator(it) { } - StringPiece operator*() const { - return MakeStringPiece()(this->iterator::operator*()); - } -}; -template -iterator_stringpiece make_iterator_stringpiece(iterator it) { - return iterator_stringpiece(it); -} - -} // namespace cxxmph diff --git a/cxxmph/randomly_seeded_hash.h b/cxxmph/randomly_seeded_hash.h deleted file mode 100644 index 747bbf3..0000000 --- a/cxxmph/randomly_seeded_hash.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __CXXMPH_RANDOMLY_SEEDED_HASH__ -#define __CXXMPH_RANDOMLY_SEEDED_HASH__ - -// Helper to create randomly seeded hash functions out of existing hash -// functions that take a seed as a parameter. - -#include - -#include "cmph_types.h" -#include "MurmurHash2.h" -#include "stringpiece.h" - -namespace cxxmph { - -template -struct RandomlySeededHashFunction { }; - -class Murmur2StringPiece { }; -class Murmur2Pod { }; - -template <> -struct RandomlySeededHashFunction { - RandomlySeededHashFunction() : seed(random()) { } - cmph_uint32 operator()(const StringPiece& key) const { - return MurmurHash2(key.data(), key.length(), seed); - } - cmph_uint32 seed; -}; - -template<> -struct RandomlySeededHashFunction { - RandomlySeededHashFunction() : seed(random()) { } - template - cmph_uint32 operator()(const Key& key) const { - return MurmurHash2(&key, sizeof(key), seed); - } - cmph_uint32 seed; -}; - -} // namespace cxxmph - -#endif // __CXXMPH_RANDOMLY_SEEDED_HASH__ diff --git a/cxxmph/stringpiece.h b/cxxmph/stringpiece.h index 4595dc7..fdd8f75 100644 --- a/cxxmph/stringpiece.h +++ b/cxxmph/stringpiece.h @@ -172,8 +172,6 @@ inline bool operator>=(const cxxmph::StringPiece& x, const cxxmph::StringPiece& } // allow StringPiece to be logged -inline std::ostream& operator<<(std::ostream& o, const cxxmph::StringPiece& piece) { - return operator<<(o, std::string(piece.data(), piece.size())); -} +extern std::ostream& operator<<(std::ostream& o, const cxxmph::StringPiece& piece); #endif // CXXMPH_STRINGPIECE_H__