2010-11-18 11:56:22 -05:00
|
|
|
/*
|
|
|
|
open source routing machine
|
|
|
|
Copyright (C) Dennis Luxen, others 2010
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU AFFERO General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
or see http://www.gnu.org/licenses/agpl.txt.
|
|
|
|
|
|
|
|
Created on: 18.11.2010
|
|
|
|
Author: dennis
|
2011-04-18 04:12:44 -04:00
|
|
|
*/
|
2010-11-18 11:56:22 -05:00
|
|
|
|
|
|
|
#ifndef HASHTABLE_H_
|
|
|
|
#define HASHTABLE_H_
|
|
|
|
|
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>
|
|
|
|
class HashTable {
|
2011-10-04 04:28:40 -04:00
|
|
|
typedef boost::unordered_map<keyT, valueT> MyHashTable;
|
2010-11-18 11:56:22 -05:00
|
|
|
public:
|
2011-10-04 04:28:40 -04:00
|
|
|
typedef typename boost::unordered_map<keyT, valueT>::const_iterator MyIterator;
|
2011-07-11 12:55:37 -04:00
|
|
|
typedef MyIterator iterator;
|
2011-04-18 04:12:44 -04:00
|
|
|
HashTable() { }
|
|
|
|
HashTable(const unsigned size) {
|
|
|
|
table.resize(size);
|
|
|
|
}
|
2012-11-12 11:00:36 -05:00
|
|
|
inline void Add(const keyT& key, const valueT& value){
|
2011-04-18 04:12:44 -04:00
|
|
|
table[key] = value;
|
|
|
|
}
|
2012-11-12 11:00:36 -05:00
|
|
|
inline void Set(const keyT& key, const valueT& value){
|
2011-04-18 04:12:44 -04:00
|
|
|
table[key] = value;
|
|
|
|
}
|
2012-11-12 11:00:36 -05:00
|
|
|
inline valueT Find(const keyT& key) const {
|
2011-04-18 04:12:44 -04:00
|
|
|
if(table.find(key) == table.end())
|
|
|
|
return valueT();
|
|
|
|
return table.find(key)->second;
|
|
|
|
}
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2012-11-12 11:00:36 -05:00
|
|
|
inline bool Holds(const keyT& key) const {
|
2011-04-18 04:12:44 -04:00
|
|
|
if(table.find(key) == table.end())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void EraseAll() {
|
|
|
|
if(table.size() > 0)
|
|
|
|
table.clear();
|
|
|
|
}
|
2011-03-14 09:35:16 -04:00
|
|
|
|
2011-12-28 08:14:09 -05:00
|
|
|
inline valueT operator[] (keyT key) const {
|
|
|
|
if(table.find(key) == table.end())
|
|
|
|
return valueT();
|
|
|
|
return table.find(key)->second;
|
2011-04-18 04:12:44 -04:00
|
|
|
}
|
2012-11-12 11:00:36 -05:00
|
|
|
inline unsigned Size() const {
|
2011-04-18 04:12:44 -04:00
|
|
|
return table.size();
|
|
|
|
}
|
|
|
|
MyIterator begin() const {
|
|
|
|
return table.begin();
|
|
|
|
}
|
|
|
|
MyIterator end() const {
|
|
|
|
return table.end();
|
|
|
|
}
|
2010-11-18 11:56:22 -05:00
|
|
|
private:
|
2011-04-18 04:12:44 -04:00
|
|
|
MyHashTable table;
|
2010-11-18 11:56:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* HASHTABLE_H_ */
|