From 674f6136783fb82e4dbdaa50a9a784ffafdabf10 Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Tue, 13 Nov 2012 16:35:21 -0800 Subject: [PATCH] Add Hash::clear() to restore initial internal state of hasher --- src/core/model/hash-fnv.cc | 5 +++++ src/core/model/hash-fnv.h | 4 ++++ src/core/model/hash-implementation.h | 4 ++++ src/core/model/hash-murmur3.cc | 5 +++++ src/core/model/hash-murmur3.h | 4 ++++ src/core/model/hash.cc | 9 ++++++++- src/core/model/hash.h | 6 ++++++ 7 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/core/model/hash-fnv.cc b/src/core/model/hash-fnv.cc index a6bd98456..5b2d89b5e 100644 --- a/src/core/model/hash-fnv.cc +++ b/src/core/model/hash-fnv.cc @@ -742,6 +742,11 @@ Fnv1a::GetHash64 (const char * buffer, const size_t size) return result; } +void +Fnv1a::clear (void) +{ +} + } // namespace HashFunction } // namespace ns3 diff --git a/src/core/model/hash-fnv.h b/src/core/model/hash-fnv.h index eee495059..7ceb53e24 100644 --- a/src/core/model/hash-fnv.h +++ b/src/core/model/hash-fnv.h @@ -52,6 +52,10 @@ public: * \return 64-bit hash of the buffer */ Hash64_t GetHash64 (const char * buffer, const size_t size); + /** + * Restore initial state + */ + virtual void clear (void); private: /** diff --git a/src/core/model/hash-implementation.h b/src/core/model/hash-implementation.h index 774530e67..b26d7337d 100644 --- a/src/core/model/hash-implementation.h +++ b/src/core/model/hash-implementation.h @@ -60,6 +60,10 @@ public: * \return 64-bit hash of the buffer */ virtual Hash64_t GetHash64 (const char * buffer, const size_t size); + /** + * Restore initial state + */ + virtual void clear (void) = 0; /* * Destructor */ diff --git a/src/core/model/hash-murmur3.cc b/src/core/model/hash-murmur3.cc index 0fd786f78..f21375757 100644 --- a/src/core/model/hash-murmur3.cc +++ b/src/core/model/hash-murmur3.cc @@ -374,6 +374,11 @@ Murmur3::GetHash64 (const char * buffer, const size_t size) return result[0]; } +void +Murmur3::clear (void) +{ +} + } // namespace HashFunction } // namespace ns3 diff --git a/src/core/model/hash-murmur3.h b/src/core/model/hash-murmur3.h index 591e85662..522d6db9b 100644 --- a/src/core/model/hash-murmur3.h +++ b/src/core/model/hash-murmur3.h @@ -61,6 +61,10 @@ public: * \return 64-bit hash of the buffer */ Hash64_t GetHash64 (const char * buffer, const size_t size); + /** + * Restore initial state + */ + virtual void clear (void); private: /** diff --git a/src/core/model/hash.cc b/src/core/model/hash.cc index b0f864e45..bb387a661 100644 --- a/src/core/model/hash.cc +++ b/src/core/model/hash.cc @@ -41,5 +41,12 @@ Hash::Hash (Ptr hp) { NS_ASSERT (m_impl != 0); } - + +Hash * +Hash::clear (void) +{ + m_impl->clear(); + return this; +} + } // namespace ns3 diff --git a/src/core/model/hash.h b/src/core/model/hash.h index 784882687..6fa2ff031 100644 --- a/src/core/model/hash.h +++ b/src/core/model/hash.h @@ -104,6 +104,12 @@ public: * \return 64-bit hash of the string */ Hash64_t GetHash64 (const std::string s); + /** + * Restore initial state + * + * \return this + */ + Hash * clear (void); private: Ptr m_impl; /** Hash implementation */