$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r53771 - in sandbox/bloom_filter/trunk: boost/bloom_filter libs/bloom_filter/test
From: mikhailberis_at_[hidden]
Date: 2009-06-09 04:16:18
Author: mikhailberis
Date: 2009-06-09 04:16:16 EDT (Tue, 09 Jun 2009)
New Revision: 53771
URL: http://svn.boost.org/trac/boost/changeset/53771
Log:
Adding support for (in)equality checking for bloom_filters.
Added:
   sandbox/bloom_filter/trunk/libs/bloom_filter/test/bloom_filter_equality_test.cpp   (contents, props changed)
Text files modified: 
   sandbox/bloom_filter/trunk/boost/bloom_filter/bloom_filter.hpp |    16 ++++++++++++++--                        
   sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2   |     1 +                                       
   2 files changed, 15 insertions(+), 2 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-09 04:16:16 EDT (Tue, 09 Jun 2009)
@@ -18,14 +18,16 @@
 
     template <class Input, size_t M, size_t K>
     struct bloom_filter {
+        public:
+            typedef std::bitset<M> bitset_type;
+
         private:
-            std::bitset<M> bit_set;
+            bitset_type bit_set;
             array<function<size_t(Input)>, K> hash_array;
 
             typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
 
         public:
-            typedef std::bitset<M> bitset_type;
             static size_t const size = M;
             static size_t const functions = K;
             typedef Input element_type;
@@ -79,6 +81,16 @@
             bitset_type const & state() const { 
                 return bit_set; 
             }
+
+            bool operator== (bloom_filter const & other) const {
+                // FIXME For some reason, we cannot compare boost::function instances...
+                // return (hash_array == other.hash_array) && (bit_set == other.bit_set);
+                return bit_set == other.bit_set;
+            }
+
+            bool operator!= (bloom_filter const & other) const {
+                return !(*this == other);
+            }
     };
 
     template <class Input, size_t M, size_t K>
Modified: sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2	(original)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2	2009-06-09 04:16:16 EDT (Tue, 09 Jun 2009)
@@ -7,6 +7,7 @@
     [ run bloom_filter_test.cpp ]
     [ run default_constructed_filter_test.cpp ]
     [ run bloom_filter_swap_adl_test.cpp ]
+    [ run bloom_filter_equality_test.cpp ]
     ;
 }
 
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/test/bloom_filter_equality_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/test/bloom_filter_equality_test.cpp	2009-06-09 04:16:16 EDT (Tue, 09 Jun 2009)
@@ -0,0 +1,20 @@
+// Copyright 2009 (c) Dean Michael Berris <mikhailberis_at_[hidden]>
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/bloom_filter.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+using boost::bloom_filter;
+
+int main(int argc, char * arg[]) {
+    bloom_filter<int, 32, 3> filter1, filter2;
+    assert(filter1 == filter2);
+    filter1.insert(1);
+    assert(filter1 != filter2);
+    filter2.insert(1);
+    assert(filter1 == filter2);
+    return EXIT_SUCCESS;
+}
+