Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53928 - in sandbox/bloom_filter/trunk/boost/bloom_filter: . detail
From: mikhailberis_at_[hidden]
Date: 2009-06-15 04:31:16


Author: mikhailberis
Date: 2009-06-15 04:31:15 EDT (Mon, 15 Jun 2009)
New Revision: 53928
URL: http://svn.boost.org/trac/boost/changeset/53928

Log:
Introducing nested bloom_filters namespace.
Text files modified:
   sandbox/bloom_filter/trunk/boost/bloom_filter/bloom_filter.hpp | 164 ++++++++++++++++---------------
   sandbox/bloom_filter/trunk/boost/bloom_filter/detail/default_hash.hpp | 26 ++--
   sandbox/bloom_filter/trunk/boost/bloom_filter/detail/internals.hpp | 73 +++++++------
   sandbox/bloom_filter/trunk/boost/bloom_filter/static_bloom_filter.hpp | 205 ++++++++++++++++++++-------------------
   4 files changed, 246 insertions(+), 222 deletions(-)

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/bloom_filter.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/bloom_filter.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/bloom_filter.hpp 2009-06-15 04:31:15 EDT (Mon, 15 Jun 2009)
@@ -18,85 +18,91 @@
 
 namespace boost {
 
- template <
- class Input,
- class HashFunctions = fusion::vector<
- detail::default_hash<0>,
- detail::default_hash<1>,
- detail::default_hash<2>
- >,
- class Block = unsigned char,
- class Allocator = std::allocator<unsigned char>
- >
- struct bloom_filter : protected detail::bloom_filter_internals<Input, dynamic_bitset<Block,Allocator> > {
- public:
- typedef dynamic_bitset<Block, Allocator> bitset_type;
-
- private:
- bitset_type bit_set;
- HashFunctions hash_functions;
-
- typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
- typedef detail::bloom_filter_internals<Input, dynamic_bitset<Block,Allocator> > base;
-
- public:
- bloom_filter(
- size_t size,
- HashFunctions const & functions = HashFunctions())
- : bit_set(size, 0), hash_functions(functions)
- {}
-
- bloom_filter(bloom_filter const & other)
- : bit_set(other.bit_set), hash_functions(other.hash_functions)
- {}
-
- bloom_filter & operator= (bloom_filter rhs) {
- return rhs.swap(*this);
- }
-
- bloom_filter & swap(bloom_filter & other) {
- using std::swap;
- swap(bit_set, other.bit_set);
- swap(hash_functions, other.hash_functions);
- return *this;
- }
-
- void insert(const_ref input) {
- using fusion::for_each;
- typedef typename base::insert_impl inserter;
- for_each(
- hash_functions,
- inserter(bit_set, input)
- );
- }
-
- bool contains(const_ref input) const {
- using fusion::for_each;
- typedef typename base::contains_impl contains_checker;
- bool found = true;
- for_each(
- hash_functions,
- contains_checker(bit_set, input, found)
- );
- return found;
- }
-
- bool operator==(bloom_filter const & other) const {
- return bit_set == other.bit_set;
- }
-
- bool operator!=(bloom_filter const & other) const {
- return !(*this == other);
- }
- };
-
- template <class Input, class HashFunctions, class Block, class Allocator>
- inline void swap(
- bloom_filter<Input, HashFunctions, Block, Allocator> & left,
- bloom_filter<Input, HashFunctions, Block, Allocator> & right
- ) {
- left.swap(right);
- }
+ namespace bloom_filters {
+
+ template <
+ class Input,
+ class HashFunctions = fusion::vector<
+ detail::default_hash<0>,
+ detail::default_hash<1>,
+ detail::default_hash<2>
+ >,
+ class Block = unsigned char,
+ class Allocator = std::allocator<unsigned char>
+ >
+ struct bloom_filter : protected detail::internals<Input, dynamic_bitset<Block,Allocator> > {
+ public:
+ typedef dynamic_bitset<Block, Allocator> bitset_type;
+
+ private:
+ bitset_type bit_set;
+ HashFunctions hash_functions;
+
+ typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
+ typedef detail::internals<Input, dynamic_bitset<Block,Allocator> > base;
+
+ public:
+ bloom_filter(
+ size_t size,
+ HashFunctions const & functions = HashFunctions())
+ : bit_set(size, 0), hash_functions(functions)
+ {}
+
+ bloom_filter(bloom_filter const & other)
+ : bit_set(other.bit_set), hash_functions(other.hash_functions)
+ {}
+
+ bloom_filter & operator= (bloom_filter rhs) {
+ return rhs.swap(*this);
+ }
+
+ bloom_filter & swap(bloom_filter & other) {
+ using std::swap;
+ swap(bit_set, other.bit_set);
+ swap(hash_functions, other.hash_functions);
+ return *this;
+ }
+
+ void insert(const_ref input) {
+ using fusion::for_each;
+ typedef typename base::insert_impl inserter;
+ for_each(
+ hash_functions,
+ inserter(bit_set, input)
+ );
+ }
+
+ bool contains(const_ref input) const {
+ using fusion::for_each;
+ typedef typename base::contains_impl contains_checker;
+ bool found = true;
+ for_each(
+ hash_functions,
+ contains_checker(bit_set, input, found)
+ );
+ return found;
+ }
+
+ bool operator==(bloom_filter const & other) const {
+ return bit_set == other.bit_set;
+ }
+
+ bool operator!=(bloom_filter const & other) const {
+ return !(*this == other);
+ }
+ };
+
+ template <class Input, class HashFunctions, class Block, class Allocator>
+ inline void swap(
+ bloom_filter<Input, HashFunctions, Block, Allocator> & left,
+ bloom_filter<Input, HashFunctions, Block, Allocator> & right
+ ) {
+ left.swap(right);
+ }
+
+ } // namespace bloom_filters
+
+ using bloom_filters::bloom_filter;
 
 } // namespace boost
 

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/detail/default_hash.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/detail/default_hash.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/detail/default_hash.hpp 2009-06-15 04:31:15 EDT (Mon, 15 Jun 2009)
@@ -8,19 +8,23 @@
 
 namespace boost {
 
- namespace detail {
+ namespace bloom_filters {
 
- template <size_t Seed = 0>
- struct default_hash {
- template <class T>
- size_t operator() (T const & input) const {
- size_t seed = Seed;
- hash_combine(seed, input);
- return seed;
- }
- };
+ namespace detail {
 
- } // namespace detail
+ template <size_t Seed = 0>
+ struct default_hash {
+ template <class T>
+ size_t operator() (T const & input) const {
+ size_t seed = Seed;
+ hash_combine(seed, input);
+ return seed;
+ }
+ };
+
+ } // namespace detail
+
+ } // namespace bloom_filters
 
 } // namespace boost
 

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/detail/internals.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/detail/internals.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/detail/internals.hpp 2009-06-15 04:31:15 EDT (Mon, 15 Jun 2009)
@@ -6,44 +6,51 @@
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#include <boost/type_traits/add_reference.hpp>
+#include <boost/type_traits/add_const.hpp>
+
 namespace boost {
 
- namespace detail {
+ namespace bloom_filters {
+
+ namespace detail {
+
+ template <class Input, class BitSet>
+ class internals {
+ protected:
+ typedef BitSet bitset_type;
+ typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
+
+ struct insert_impl {
+ bitset_type & bit_set_;
+ const_ref input_;
+ insert_impl(bitset_type & bit_set, const_ref input)
+ : bit_set_(bit_set), input_(input)
+ {}
+ template <class F>
+ void operator()(F const & f) const {
+ bit_set_[f(input_) % bit_set_.size()] = true;
+ }
+ };
+
+ struct contains_impl {
+ bitset_type const & bit_set_;
+ const_ref input_;
+ bool & result_;
+ contains_impl(bitset_type const & bit_set, const_ref input, bool & result)
+ : bit_set_(bit_set), input_(input), result_(result)
+ {}
+ template <class F>
+ void operator()(F const & f) const {
+ result_ = result_ && bit_set_[f(input_) % bit_set_.size()];
+ }
+ };
 
- template <class Input, class BitSet>
- class bloom_filter_internals {
- protected:
- typedef BitSet bitset_type;
- typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
-
- struct insert_impl {
- bitset_type & bit_set_;
- const_ref input_;
- insert_impl(bitset_type & bit_set, const_ref input)
- : bit_set_(bit_set), input_(input)
- {}
- template <class F>
- void operator()(F const & f) const {
- bit_set_[f(input_) % bit_set_.size()] = true;
- }
- };
-
- struct contains_impl {
- bitset_type const & bit_set_;
- const_ref input_;
- bool & result_;
- contains_impl(bitset_type const & bit_set, const_ref input, bool & result)
- : bit_set_(bit_set), input_(input), result_(result)
- {}
- template <class F>
- void operator()(F const & f) const {
- result_ = result_ && bit_set_[f(input_) % bit_set_.size()];
- }
- };
+ };
 
- };
+ } // namespace detail
 
- } // namespace detail
+ } // namespace bloom_filters
 
 } // namespace boost
 

Modified: sandbox/bloom_filter/trunk/boost/bloom_filter/static_bloom_filter.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/boost/bloom_filter/static_bloom_filter.hpp (original)
+++ sandbox/bloom_filter/trunk/boost/bloom_filter/static_bloom_filter.hpp 2009-06-15 04:31:15 EDT (Mon, 15 Jun 2009)
@@ -21,110 +21,117 @@
 
 namespace boost {
 
- template <
- class Input,
- size_t M,
- class HashFunctions = fusion::vector<
- detail::default_hash<0>,
- detail::default_hash<1>,
- detail::default_hash<2>
- >
- >
- struct static_bloom_filter : protected detail::bloom_filter_internals<Input, std::bitset<M> > {
- public:
- typedef std::bitset<M> bitset_type;
-
- private:
- bitset_type bit_set;
- HashFunctions hash_functions;
-
- typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
- typedef detail::bloom_filter_internals<Input, std::bitset<M> > base;
-
- struct insert_impl {
- bitset_type & bit_set_;
- };
-
- public:
- static size_t const size = M;
- typedef Input element_type;
-
- static_bloom_filter(
- bitset_type const & initial_state = bitset_type(),
- HashFunctions const & hash_functions = HashFunctions())
- : bit_set(initial_state), hash_functions(hash_functions)
- {}
-
- explicit static_bloom_filter(
- HashFunctions const & hash_functions
- )
- : bit_set(), hash_functions(hash_functions)
- {}
-
- static_bloom_filter(static_bloom_filter const & other) :
- bit_set(other.bit_set), hash_functions(other.hash_functions) {}
-
- static_bloom_filter & operator=(static_bloom_filter rhs) {
- rhs.swap(*this);
- return *this;
- }
-
- static_bloom_filter & swap(static_bloom_filter & other) {
- using std::swap;
- swap(bit_set, other.bit_set);
- swap(hash_functions, other.hash_functions);
- return *this;
- }
-
- void insert(const_ref input) {
- using fusion::for_each;
- typedef typename base::insert_impl inserter;
- for_each(
- hash_functions,
- inserter(bit_set, input)
- );
- }
-
- bool contains(const_ref input) const {
- using fusion::for_each;
- typedef typename base::contains_impl contains_checker;
- bool found = true;
- for_each(
- hash_functions,
- contains_checker(bit_set, input, found)
- );
- return found;
- }
+ namespace bloom_filters {
 
- bool operator[](const_ref input) const {
- return contains(input);
- }
-
- static_bloom_filter & clear() {
- bit_set.reset();
- return *this;
- }
-
- bitset_type const & state() const {
- return bit_set;
+ template <
+ class Input,
+ size_t M,
+ class HashFunctions = fusion::vector<
+ detail::default_hash<0>,
+ detail::default_hash<1>,
+ detail::default_hash<2>
+ >
+ >
+ struct static_bloom_filter : protected detail::internals<Input, std::bitset<M> > {
+ public:
+ typedef std::bitset<M> bitset_type;
+
+ private:
+ bitset_type bit_set;
+ HashFunctions hash_functions;
+
+ typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
+ typedef detail::internals<Input, std::bitset<M> > base;
+
+ struct insert_impl {
+ bitset_type & bit_set_;
+ };
+
+ public:
+ static size_t const size = M;
+ typedef Input element_type;
+
+ static_bloom_filter(
+ bitset_type const & initial_state = bitset_type(),
+ HashFunctions const & hash_functions = HashFunctions())
+ : bit_set(initial_state), hash_functions(hash_functions)
+ {}
+
+ explicit static_bloom_filter(
+ HashFunctions const & hash_functions
+ )
+ : bit_set(), hash_functions(hash_functions)
+ {}
+
+ static_bloom_filter(static_bloom_filter const & other) :
+ bit_set(other.bit_set), hash_functions(other.hash_functions) {}
+
+ static_bloom_filter & operator=(static_bloom_filter rhs) {
+ rhs.swap(*this);
+ return *this;
+ }
+
+ static_bloom_filter & swap(static_bloom_filter & other) {
+ using std::swap;
+ swap(bit_set, other.bit_set);
+ swap(hash_functions, other.hash_functions);
+ return *this;
+ }
+
+ void insert(const_ref input) {
+ using fusion::for_each;
+ typedef typename base::insert_impl inserter;
+ for_each(
+ hash_functions,
+ inserter(bit_set, input)
+ );
+ }
+
+ bool contains(const_ref input) const {
+ using fusion::for_each;
+ typedef typename base::contains_impl contains_checker;
+ bool found = true;
+ for_each(
+ hash_functions,
+ contains_checker(bit_set, input, found)
+ );
+ return found;
+ }
+
+ bool operator[](const_ref input) const {
+ return contains(input);
+ }
+
+ static_bloom_filter & clear() {
+ bit_set.reset();
+ return *this;
+ }
+
+ bitset_type const & state() const {
+ return bit_set;
+ }
+
+ bool operator== (static_bloom_filter const & other) const {
+ return bit_set == other.bit_set;
+ }
+
+ bool operator!= (static_bloom_filter const & other) const {
+ return !(*this == other);
+ }
+ };
+
+ template <class Input, size_t M, class HashFunctions>
+ inline void swap(
+ static_bloom_filter<Input, M, HashFunctions> & left,
+ static_bloom_filter<Input, M, HashFunctions> & right) {
+ left.swap(right);
             }
 
- bool operator== (static_bloom_filter const & other) const {
- return bit_set == other.bit_set;
- }
+ } // namespce bloom_filters
 
- bool operator!= (static_bloom_filter const & other) const {
- return !(*this == other);
- }
- };
+ using bloom_filters::static_bloom_filter;
 
- template <class Input, size_t M, class HashFunctions>
- inline void swap(
- static_bloom_filter<Input, M, HashFunctions> & left,
- static_bloom_filter<Input, M, HashFunctions> & right) {
- left.swap(right);
- }
-}
+} // namespace boost
 
 #endif
 


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