refactor HashTable facade class
This commit is contained in:
parent
9e64ccdbf2
commit
4c48cda4cd
@ -25,43 +25,44 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HASHTABLE_H_
|
#ifndef HASH_TABLE_H
|
||||||
#define HASHTABLE_H_
|
#define HASH_TABLE_H
|
||||||
|
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
|
|
||||||
template<typename keyT, typename valueT>
|
template<typename KeyT, typename ValueT>
|
||||||
class HashTable : public boost::unordered_map<keyT, valueT> {
|
class HashTable : public boost::unordered_map<KeyT, ValueT> {
|
||||||
private:
|
private:
|
||||||
typedef boost::unordered_map<keyT, valueT> super;
|
typedef boost::unordered_map<KeyT, ValueT> super;
|
||||||
public:
|
public:
|
||||||
|
static ValueT default_value;
|
||||||
|
|
||||||
HashTable() : super() { }
|
HashTable() : super() { }
|
||||||
|
|
||||||
HashTable(const unsigned size) : super(size) { }
|
HashTable(const unsigned size) : super(size) { }
|
||||||
|
|
||||||
// HashTable &operator=(const HashTable &other) {
|
inline void Add( KeyT const & key, ValueT const & value) {
|
||||||
// super::operator = (other);
|
super::emplace(std::make_pair(key, value));
|
||||||
// return *this;
|
|
||||||
// }
|
|
||||||
|
|
||||||
inline void Add(const keyT& key, const valueT& value){
|
|
||||||
super::insert(std::make_pair(key, value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline valueT Find(const keyT& key) const {
|
inline const ValueT Find(KeyT const & key) const {
|
||||||
if(super::find(key) == super::end()) {
|
typename super::const_iterator iter = super::find(key);
|
||||||
return valueT();
|
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 {
|
inline bool Holds( KeyT const & key) const {
|
||||||
if(super::find(key) == super::end()) {
|
if( super::find(key) == super::end() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HASHTABLE_H_ */
|
template<typename KeyT, typename ValueT>
|
||||||
|
ValueT HashTable<KeyT, ValueT>::default_value;
|
||||||
|
|
||||||
|
#endif /* HASH_TABLE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user