2010-11-18 11:56:22 -05:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2010-11-18 11:56:22 -05:00
|
|
|
|
|
|
|
#ifndef HASHTABLE_H_
|
|
|
|
#define HASHTABLE_H_
|
|
|
|
|
2013-08-06 10:39:04 -04:00
|
|
|
#include <boost/ref.hpp>
|
2011-10-04 04:28:40 -04:00
|
|
|
#include <boost/unordered_map.hpp>
|
2011-09-28 10:51:54 -04:00
|
|
|
|
2010-11-18 11:56:22 -05:00
|
|
|
template<typename keyT, typename valueT>
|
2013-08-06 10:39:04 -04:00
|
|
|
class HashTable : public boost::unordered_map<keyT, valueT> {
|
|
|
|
private:
|
|
|
|
typedef boost::unordered_map<keyT, valueT> super;
|
2010-11-18 11:56:22 -05:00
|
|
|
public:
|
2013-08-06 10:39:04 -04:00
|
|
|
HashTable() : super() { }
|
|
|
|
|
|
|
|
HashTable(const unsigned size) : super(size) { }
|
|
|
|
|
2013-09-24 04:33:29 -04:00
|
|
|
HashTable &operator=(const HashTable &other) {
|
|
|
|
super::operator = (other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-11-12 11:00:36 -05:00
|
|
|
inline void Add(const keyT& key, const valueT& value){
|
2013-08-06 10:39:04 -04:00
|
|
|
super::insert(std::make_pair(key, value));
|
2011-04-18 04:12:44 -04:00
|
|
|
}
|
2013-08-06 10:39:04 -04:00
|
|
|
|
2012-11-12 11:00:36 -05:00
|
|
|
inline valueT Find(const keyT& key) const {
|
2013-08-06 10:39:04 -04:00
|
|
|
if(super::find(key) == super::end()) {
|
2011-04-18 04:12:44 -04:00
|
|
|
return valueT();
|
2013-08-06 10:39:04 -04:00
|
|
|
}
|
|
|
|
return boost::ref(super::find(key)->second);
|
2011-04-18 04:12:44 -04:00
|
|
|
}
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2012-11-12 11:00:36 -05:00
|
|
|
inline bool Holds(const keyT& key) const {
|
2013-08-06 10:39:04 -04:00
|
|
|
if(super::find(key) == super::end()) {
|
2011-04-18 04:12:44 -04:00
|
|
|
return false;
|
2013-08-06 10:39:04 -04:00
|
|
|
}
|
2011-04-18 04:12:44 -04:00
|
|
|
return true;
|
|
|
|
}
|
2010-11-18 11:56:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* HASHTABLE_H_ */
|