From 3b9681232873029fdd983874126ba093fb611093 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 4 Sep 2015 11:28:33 +0100 Subject: [PATCH] [thin_show_dups] switch to boost::circular_buffer in the rolling_hash --- base/rolling_hash.cc | 7 ++++--- base/rolling_hash.h | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/base/rolling_hash.cc b/base/rolling_hash.cc index 8de7ac3..c780a27 100644 --- a/base/rolling_hash.cc +++ b/base/rolling_hash.cc @@ -10,7 +10,8 @@ using namespace std; rolling_hash::rolling_hash(unsigned window_size) : a_(MULTIPLIER), a_to_k_minus_1_(a_), - window_size_(window_size) { + window_size_(window_size), + buffer_(window_size) { for (unsigned i = 1; i < window_size_ - 1; i++) a_to_k_minus_1_ *= a_; @@ -22,12 +23,12 @@ void rolling_hash::reset() { // prime with zeroes - chars_.clear(); + buffer_.clear(); hash_ = 0; for (unsigned i = 0; i < window_size_; i++) { hash_ = (hash_ * a_) + SEED; - chars_.push_back(0); + buffer_.push_back(0); } } diff --git a/base/rolling_hash.h b/base/rolling_hash.h index c5fa44c..dff3145 100644 --- a/base/rolling_hash.h +++ b/base/rolling_hash.h @@ -1,7 +1,7 @@ #ifndef BASE_ROLLING_HASH_H #define BASE_ROLLING_HASH_H -#include +#include #include #include @@ -31,20 +31,18 @@ namespace base { private: void update_hash(uint8_t byte) { - hash_ -= a_to_k_minus_1_ * (chars_.front() + hash_detail::SEED); - chars_.pop_front(); - chars_.push_back(byte); + hash_ -= a_to_k_minus_1_ * (buffer_.front() + hash_detail::SEED); + buffer_.push_back(byte); hash_ = (hash_ * a_) + byte + hash_detail::SEED; } uint32_t a_; uint32_t a_to_k_minus_1_; - // FIXME: use a ring buffer - std::list chars_; - uint32_t hash_; uint32_t window_size_; + + boost::circular_buffer buffer_; }; class content_based_hash {