Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72326 - in sandbox/bloom_filter/trunk: boost/bloom_filter boost/bloom_filter/detail libs/bloom_filter/test
From: cpp.cabrera_at_[hidden]
Date: 2011-06-01 10:26:59


Author: alejandro
Date: 2011-06-01 10:26:59 EDT (Wed, 01 Jun 2011)
New Revision: 72326
URL: http://svn.boost.org/trac/boost/changeset/72326

Log:
Changed prototype of all hash functions - they are now callables.
Text files modified:
   sandbox/bloom_filter/trunk/boost/bloom_filter/bloom.hpp | 12 ++++++------
   sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp | 12 ++++++++----
   sandbox/bloom_filter/trunk/boost/bloom_filter/hash.hpp | 20 ++++++++++++++++++--
   sandbox/bloom_filter/trunk/libs/bloom_filter/test/boost_test.cpp | 21 ++++++++++++++++-----
   4 files changed, 48 insertions(+), 17 deletions(-)

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/bloom.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/bloom.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/bloom.hpp 2011-06-01 10:26:59 EDT (Wed, 01 Jun 2011)
@@ -28,9 +28,9 @@
 namespace boost {
   template <typename T,
             size_t Size,
- class HashFunctions = mpl::vector<MurmurHash3<T, 3>,
- MurmurHash3<T, 5>,
- MurmurHash3<T, 7> > >
+ class HashFunctions = mpl::vector<boost::BoostHash<T, 3>,
+ boost::BoostHash<T, 5>,
+ boost::BoostHash<T, 7> > >
   class bloom_filter {
   public:
     bloom_filter() {}
@@ -62,7 +62,7 @@
       this->bits &= rhs.bits;
       return *this;
     }
-
+
   private:
     std::bitset<Size> bits;
   };
@@ -72,7 +72,7 @@
   operator|(const bloom_filter<_T, _Size, _HashFunctions>& lhs,
             const bloom_filter<_T, _Size, _HashFunctions>& rhs)
   {
- bloom_filter<_T, _Size, _HashFunctions> ret = lhs;
+ bloom_filter<_T, _Size, _HashFunctions> ret(lhs);
     ret |= rhs;
     return ret;
   }
@@ -82,7 +82,7 @@
   operator&(const bloom_filter<_T, _Size, _HashFunctions>& lhs,
             const bloom_filter<_T, _Size, _HashFunctions>& rhs)
   {
- bloom_filter<_T, _Size, _HashFunctions> ret = lhs;
+ bloom_filter<_T, _Size, _HashFunctions> ret(lhs);
     ret &= rhs;
     return ret;
   }

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp 2011-06-01 10:26:59 EDT (Wed, 01 Jun 2011)
@@ -24,13 +24,15 @@
     {
       static void insert(const T& t, std::bitset<Size>& _bits) {
         typedef typename boost::mpl::at_c<HashFunctions, N>::type Hash;
- _bits[Hash::hash(t) % Size] = true;
+ static Hash hasher;
+ _bits[hasher(t) % Size] = true;
         apply_hash<N-1, T, Size, HashFunctions>::insert(t, _bits);
       }
     
       static bool contains(const T& t, const std::bitset<Size>& _bits) {
         typedef typename boost::mpl::at_c<HashFunctions, N>::type Hash;
- return (_bits[Hash::hash(t) % Size] &&
+ static Hash hasher;
+ return (_bits[hasher(t) % Size] &&
                 apply_hash<N-1, T, Size, HashFunctions>::contains(t, _bits));
       }
     };
@@ -42,12 +44,14 @@
     {
       static void insert(const T& t, std::bitset<Size>& _bits) {
         typedef typename boost::mpl::at_c<HashFunctions, 0>::type Hash;
- _bits[Hash::hash(t) % Size] = true;
+ static Hash hasher;
+ _bits[hasher(t) % Size] = true;
       }
     
       static bool contains(const T& t, const std::bitset<Size>& _bits) {
         typedef typename boost::mpl::at_c<HashFunctions, 0>::type Hash;
- return (_bits[Hash::hash(t) % Size]);
+ static Hash hasher;
+ return (_bits[hasher(t) % Size]);
       }
     };
   }

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/hash.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/hash.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/hash.hpp 2011-06-01 10:26:59 EDT (Wed, 01 Jun 2011)
@@ -19,8 +19,13 @@
  * \todo Provide 64-bit implementation of murmurhash3.
  */
 #include <cstdint>
+
+#include <boost/functional/hash.hpp>
+
 #include <boost/bloom_filter/murmurhash3/murmurhash3.h>
 
+#include <iostream>
+
 template <typename UnsignedIntT>
 inline UnsignedIntT rotl(const UnsignedIntT x, uint8_t r)
 {
@@ -104,7 +109,7 @@
 
 template <typename T, size_t Seed>
 struct MurmurHash3 {
- static size_t hash(const T& t) {
+ size_t operator()(const T& t) {
     size_t out = 0;
     murmurhash3(static_cast<const void *const>(&t),
                 sizeof(t),
@@ -117,7 +122,7 @@
 // uses public domain implementation of murmurhash3
 template <typename T, size_t Seed>
 struct OHash {
- static size_t hash(const T& t) {
+ size_t operator()(const T& t) {
     size_t out = 0;
     MurmurHash3_x86_32(static_cast<const void *const>(&t),
                        sizeof(t),
@@ -126,4 +131,15 @@
     return out;
   }
 };
+
+namespace boost {
+ template <typename T, size_t Seed>
+ struct BoostHash {
+ size_t operator()(const T& t) {
+ size_t seed = Seed;
+ boost::hash_combine(seed, t);
+ return seed;
+ }
+ };
+}
 #endif

Modified: sandbox/bloom_filter/trunk/libs/bloom_filter/test/boost_test.cpp
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/boost_test.cpp (original)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/test/boost_test.cpp 2011-06-01 10:26:59 EDT (Wed, 01 Jun 2011)
@@ -17,6 +17,7 @@
 #include <boost/test/unit_test.hpp>
 
 using boost::bloom_filter;
+using boost::BoostHash;
 
 BOOST_AUTO_TEST_CASE(defaultConstructor) {
   typedef boost::mpl::vector<
@@ -33,6 +34,16 @@
   bloom_filter<int, 8, EightHashFunctions_O> bloom2;
 }
 
+BOOST_AUTO_TEST_CASE(defaultConstructor_boost) {
+ typedef boost::mpl::vector<
+ BoostHash<int, 13>,
+ BoostHash<int, 17>,
+ BoostHash<int, 19>> BoostHashFunctions;
+
+ bloom_filter<int, 8> bloom1;
+ bloom_filter<int, 8, BoostHashFunctions> bloom2;
+}
+
 BOOST_AUTO_TEST_CASE(assignment)
 {
   bloom_filter<int, 8> bloom1;
@@ -130,9 +141,9 @@
 }
 
 BOOST_AUTO_TEST_CASE(testIntersect) {
- bloom_filter<size_t, 8> bloom_1;
- bloom_filter<size_t, 8> bloom_2;
- bloom_filter<size_t, 8> bloom_intersect;
+ bloom_filter<size_t, 20000> bloom_1;
+ bloom_filter<size_t, 20000> bloom_2;
+ bloom_filter<size_t, 20000> bloom_intersect;
 
   for (size_t i = 0; i < 100; ++i)
     bloom_1.insert(i);
@@ -147,8 +158,8 @@
 }
 
 BOOST_AUTO_TEST_CASE(testIntersectAssign) {
- bloom_filter<size_t, 8> bloom_1;
- bloom_filter<size_t, 8> bloom_2;
+ bloom_filter<size_t, 32> bloom_1;
+ bloom_filter<size_t, 32> bloom_2;
 
   for (size_t i = 0; i < 100; ++i)
     bloom_1.insert(i);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk