Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53783 - in sandbox/bloom_filter/trunk/boost/bloom_filter: . detail
From: mikhailberis_at_[hidden]
Date: 2009-06-10 02:39:27


Author: mikhailberis
Date: 2009-06-10 02:39:27 EDT (Wed, 10 Jun 2009)
New Revision: 53783
URL: http://svn.boost.org/trac/boost/changeset/53783

Log:
Using Boost.Hash instead of adhoc Boost.CRC based default hash implementation.
Text files modified:
   sandbox/bloom_filter/trunk/boost/bloom_filter/detail/default_hash.hpp | 23 ++++++++---------------
   sandbox/bloom_filter/trunk/boost/bloom_filter/static_bloom_filter.hpp | 6 +++---
   2 files changed, 11 insertions(+), 18 deletions(-)

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-10 02:39:27 EDT (Wed, 10 Jun 2009)
@@ -2,7 +2,7 @@
 #define BOOST_BLOOM_FILTER_DETAIL_DEFAULT_HASH_20090609_0
 
 #include <string>
-#include <boost/crc.hpp>
+#include <boost/functional/hash.hpp>
 #include <boost/type_traits/add_const.hpp>
 #include <boost/type_traits/add_reference.hpp>
 
@@ -10,24 +10,17 @@
 
     namespace detail {
 
- template <class Input, size_t M>
+ template <class Input>
             struct default_hash {
                 typedef typename add_reference<typename add_const<Input>::type>::type const_ref;
-
- size_t offset_;
- explicit default_hash(size_t offset)
- : offset_(offset) {}
-
- size_t operator()(std::string const & input) const {
- crc_32_type crc32_computer;
- crc32_computer.process_bytes(input.c_str(), input.size());
- return (crc32_computer.checksum() + offset_) % M;
- }
+ size_t seed_;
+ default_hash(size_t seed)
+ : seed_(seed) {}
 
                 size_t operator()(const_ref input) const {
- crc_32_type crc32_computer;
- crc32_computer.process_bytes(&input, sizeof(input));
- return (crc32_computer.checksum() + offset_) % M;
+ size_t seed = seed_;
+ hash_combine(seed, input);
+ return seed;
                 }
             };
 

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-10 02:39:27 EDT (Wed, 10 Jun 2009)
@@ -41,7 +41,7 @@
                 : bit_set(initial_state)
             {
                 for(size_t k = 0; k < K; ++k)
- hash_array[k] = detail::default_hash<Input,M>(k);
+ hash_array[k] = detail::default_hash<Input>(k);
             }
 
             static_bloom_filter(static_bloom_filter const & other) :
@@ -61,13 +61,13 @@
 
             void insert(const_ref input) {
                 for(size_t k = 0; k < K; ++k)
- bit_set[hash_array[k](input)] = 1;
+ bit_set[hash_array[k](input) % M] = 1;
             }
 
             bool contains(const_ref input) const {
                 bool result = true;
                 for(size_t k = 0; k < K && result; ++k)
- result = result && bit_set[hash_array[k](input)];
+ result = result && bit_set[hash_array[k](input) % M];
                 return result;
             }
 


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