From 4c48cda4cd75398e49bada9f7e899c9745df322e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 14 Feb 2014 18:18:26 +0100 Subject: [PATCH] refactor HashTable facade class --- DataStructures/HashTable.h | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/DataStructures/HashTable.h b/DataStructures/HashTable.h index 7acfb22ae..1e9c3333c 100644 --- a/DataStructures/HashTable.h +++ b/DataStructures/HashTable.h @@ -25,43 +25,44 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HASHTABLE_H_ -#define HASHTABLE_H_ +#ifndef HASH_TABLE_H +#define HASH_TABLE_H #include #include -template -class HashTable : public boost::unordered_map { +template +class HashTable : public boost::unordered_map { private: - typedef boost::unordered_map super; + typedef boost::unordered_map super; public: + static ValueT default_value; + HashTable() : super() { } HashTable(const unsigned size) : super(size) { } - // HashTable &operator=(const HashTable &other) { - // super::operator = (other); - // return *this; - // } - - inline void Add(const keyT& key, const valueT& value){ - super::insert(std::make_pair(key, value)); + inline void Add( KeyT const & key, ValueT const & value) { + super::emplace(std::make_pair(key, value)); } - inline valueT Find(const keyT& key) const { - if(super::find(key) == super::end()) { - return valueT(); + inline const ValueT Find(KeyT const & key) const { + typename super::const_iterator iter = super::find(key); + if( iter == super::end() ) { + return boost::cref(default_value); } - return boost::ref(super::find(key)->second); + return boost::cref(iter->second); } - inline bool Holds(const keyT& key) const { - if(super::find(key) == super::end()) { + inline bool Holds( KeyT const & key) const { + if( super::find(key) == super::end() ) { return false; } return true; } }; -#endif /* HASHTABLE_H_ */ +template +ValueT HashTable::default_value; + +#endif /* HASH_TABLE_H */