Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72222 - in sandbox/bloom_filter/trunk: boost/bloom_filter boost/bloom_filter/detail libs/bloom_filter/test
From: cpp.cabrera_at_[hidden]
Date: 2011-05-27 13:30:23


Author: alejandro
Date: 2011-05-27 13:30:20 EDT (Fri, 27 May 2011)
New Revision: 72222
URL: http://svn.boost.org/trac/boost/changeset/72222

Log:
Moved implementation details to detail/. Added namespace boost and detail.
Added:
   sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp (contents, props changed)
Removed:
   sandbox/bloom_filter/trunk/boost/bloom_filter/detail/PLACE_HOLDER
Text files modified:
   sandbox/bloom_filter/trunk/boost/bloom_filter/bloom.hpp | 161 +++++++++++++++------------------------
   sandbox/bloom_filter/trunk/libs/bloom_filter/test/boost_test.cpp | 4
   2 files changed, 65 insertions(+), 100 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-05-27 13:30:20 EDT (Fri, 27 May 2011)
@@ -5,114 +5,77 @@
  * \brief A generic Bloom filter providing compile-time unrolling
  * of hash function application.
  */
-#include <boost/config.hpp>
 #include <bitset>
 
+#include <boost/config.hpp>
 #include <boost/mpl/vector.hpp>
 #include <boost/mpl/size.hpp>
-#include <boost/mpl/at.hpp>
 
+#include <detail/apply_hash.hpp>
 #include <hash.hpp>
 
-template <size_t N,
- typename T,
- size_t Size,
- class HashFunctions>
-struct apply_hash
-{
- 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;
- 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] &&
- apply_hash<N-1, T, Size, HashFunctions>::contains(t, _bits));
- }
-};
-
-template <typename T,
- size_t Size,
- class HashFunctions>
-struct apply_hash<0, T, Size, HashFunctions>
-{
- 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 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]);
- }
-};
-
-template <typename T,
- size_t Size,
- class HashFunctions = boost::mpl::vector<MurmurHash3<T, 3>,
- MurmurHash3<T, 5>,
- MurmurHash3<T, 7> > >
-class bloom_filter {
- typedef std::bitset<Size> Bitset;
-
-public:
- bloom_filter() {}
-
- BOOST_CONSTEXPR size_t size() const {
- return Size;
- }
-
- void insert(const T& t) {
- static const unsigned N = boost::mpl::size<HashFunctions>::value - 1;
- apply_hash<N, T, Size, HashFunctions>::insert(t, bits);
- }
-
- bool contains(const T& t) const {
- static const unsigned N = boost::mpl::size<HashFunctions>::value - 1;
- return apply_hash<N, T, Size, HashFunctions>::contains(t, bits);
- }
-
- bool operator[](const T& t) const {
- return this->contains(t);
- }
-
- void clear() {
- this->bits.reset();
- }
-
- bloom_filter& operator|=(const bloom_filter& rhs) {
- this->bits |= rhs.bits;
- return *this;
- }
+namespace boost {
+ template <typename T,
+ size_t Size,
+ class HashFunctions = mpl::vector<MurmurHash3<T, 3>,
+ MurmurHash3<T, 5>,
+ MurmurHash3<T, 7> > >
+ class bloom_filter {
+ typedef std::bitset<Size> Bitset;
+
+ public:
+ bloom_filter() {}
+
+ BOOST_CONSTEXPR size_t size() const {
+ return Size;
+ }
+
+ void insert(const T& t) {
+ static const unsigned N = mpl::size<HashFunctions>::value - 1;
+ detail::apply_hash<N, T, Size, HashFunctions>::insert(t, bits);
+ }
+
+ bool contains(const T& t) const {
+ static const unsigned N = mpl::size<HashFunctions>::value - 1;
+ return detail::apply_hash<N, T, Size, HashFunctions>::contains(t, bits);
+ }
+
+ void clear() {
+ this->bits.reset();
+ }
+
+ bloom_filter& operator|=(const bloom_filter& rhs) {
+ this->bits |= rhs.bits;
+ return *this;
+ }
+
+ bloom_filter& operator&=(const bloom_filter& rhs) {
+ this->bits &= rhs.bits;
+ return *this;
+ }
+
+ private:
+ std::bitset<Size> bits;
+ };
   
- bloom_filter& operator&=(const bloom_filter& rhs) {
- this->bits &= rhs.bits;
- return *this;
+ template<class _T, size_t _Size, class _HashFunctions>
+ bloom_filter<_T, _Size, _HashFunctions>
+ operator|(const bloom_filter<_T, _Size, _HashFunctions>& lhs,
+ const bloom_filter<_T, _Size, _HashFunctions>& rhs)
+ {
+ bloom_filter<_T, _Size, _HashFunctions> ret = lhs;
+ ret |= rhs;
+ return ret;
   }
   
-private:
- std::bitset<Size> bits;
-};
-
-template<class _T, size_t _Size, class _HashFunctions>
-bloom_filter<_T, _Size, _HashFunctions>
-operator|(const bloom_filter<_T, _Size, _HashFunctions>& lhs,
- const bloom_filter<_T, _Size, _HashFunctions>& rhs)
-{
- bloom_filter<_T, _Size, _HashFunctions> ret = lhs;
- ret |= rhs;
- return ret;
-}
-
-template<class _T, size_t _Size, class _HashFunctions>
-bloom_filter<_T, _Size, _HashFunctions>
-operator&(const bloom_filter<_T, _Size, _HashFunctions>& lhs,
- const bloom_filter<_T, _Size, _HashFunctions>& rhs)
-{
- bloom_filter<_T, _Size, _HashFunctions> ret = lhs;
- ret &= rhs;
- return ret;
+ template<class _T, size_t _Size, class _HashFunctions>
+ bloom_filter<_T, _Size, _HashFunctions>
+ operator&(const bloom_filter<_T, _Size, _HashFunctions>& lhs,
+ const bloom_filter<_T, _Size, _HashFunctions>& rhs)
+ {
+ bloom_filter<_T, _Size, _HashFunctions> ret = lhs;
+ ret &= rhs;
+ return ret;
+ }
 }
 #endif

Deleted: sandbox/bloom_filter/trunk/boost/bloom_filter/detail/PLACE_HOLDER
==============================================================================

Added: sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/detail/apply_hash.hpp 2011-05-27 13:30:20 EDT (Fri, 27 May 2011)
@@ -0,0 +1,44 @@
+#ifndef __APPLY_HASH_HPP
+#define __APPLY_HASH_HPP
+
+#include <boost/mpl/at.hpp>
+
+namespace boost {
+ namespace detail {
+ template <size_t N,
+ typename T,
+ size_t Size,
+ class HashFunctions>
+ struct apply_hash
+ {
+ 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;
+ 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] &&
+ apply_hash<N-1, T, Size, HashFunctions>::contains(t, _bits));
+ }
+ };
+
+ template <typename T,
+ size_t Size,
+ class HashFunctions>
+ struct apply_hash<0, T, Size, HashFunctions>
+ {
+ 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 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]);
+ }
+ };
+ }
+}
+#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-05-27 13:30:20 EDT (Fri, 27 May 2011)
@@ -5,6 +5,8 @@
 #include <bloom.hpp>
 #include <boost/test/unit_test.hpp>
 
+using boost::bloom_filter;
+
 BOOST_AUTO_TEST_CASE(defaultConstructor) {
   typedef boost::mpl::vector<
     OHash <int, 2>,
@@ -166,7 +168,7 @@
   std::cout << "bloom size " << bloom.size() << std::endl;
   bloom.insert(INSERT_VAL);
   for (size_t i = 0; i < SEARCH_SPACE; ++i) {
- if (bloom[i] && i != INSERT_VAL) ++collisions;
+ if (bloom.contains(i) && i != INSERT_VAL) ++collisions;
   }
 
   std::cout << collisions << " collisions" << std::endl;


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