minor refactoring

This commit is contained in:
Dennis Luxen 2014-04-28 17:27:15 +02:00
parent 241d6b482e
commit 265af1f790
5 changed files with 46 additions and 39 deletions

View File

@ -28,41 +28,46 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#include <boost/functional/hash.hpp>
#include <boost/ref.hpp>
#include <boost/unordered_map.hpp>
template<typename KeyT, typename ValueT>
class HashTable : public boost::unordered_map<KeyT, ValueT> {
template<typename Key, typename Value, typename Hash = boost::hash<Key> >
class HashTable : public boost::unordered_map<Key, Value> {
private:
typedef boost::unordered_map<KeyT, ValueT> super;
typedef boost::unordered_map<Key, Value, Hash> super;
public:
static ValueT default_value;
static Value default_value;
HashTable() : super() { }
explicit HashTable(const unsigned size) : super(size) { }
inline void Add( KeyT const & key, ValueT const & value) {
inline void Add( Key const & key, Value const & value) {
super::emplace(std::make_pair(key, value));
}
inline const ValueT Find(KeyT const & key) const {
inline const Value Find(Key const & key) const
{
typename super::const_iterator iter = super::find(key);
if( iter == super::end() ) {
if (iter == super::end())
{
return boost::cref(default_value);
}
return boost::cref(iter->second);
}
inline const bool Holds( KeyT const & key) const {
if( super::find(key) == super::end() ) {
inline const bool Holds( Key const & key) const
{
if(super::find(key) == super::end())
{
return false;
}
return true;
}
};
template<typename KeyT, typename ValueT>
ValueT HashTable<KeyT, ValueT>::default_value;
template<typename Key, typename Value, typename Hash>
Value HashTable<Key, Value, Hash>::default_value;
#endif /* HASH_TABLE_H */

View File

@ -26,7 +26,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ExtractorCallbacks.h"
#include "ExtractionContainers.h"
#include "ExtractionWay.h"

View File

@ -215,25 +215,26 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) {
denseTagIndex += 2;
}
}
#pragma omp parallel
{
const int thread_num = omp_get_thread_num();
#pragma omp parallel for schedule ( guided )
for(int i = 0; i < number_of_nodes; ++i) {
for(int i = 0; i < number_of_nodes; ++i)
{
ImportNode & import_node = extracted_nodes_vector[i];
ParseNodeInLua(
import_node,
scripting_environment.getLuaStateForThreadID(omp_get_thread_num())
);
ParseNodeInLua(import_node, scripting_environment.getLuaStateForThreadID(thread_num));
}
}
BOOST_FOREACH(const ImportNode &import_node, extracted_nodes_vector) {
BOOST_FOREACH(const ImportNode &import_node, extracted_nodes_vector)
{
extractor_callbacks->nodeFunction(import_node);
}
}
inline void PBFParser::parseNode(_ThreadData * ) {
throw OSRMException(
"Parsing of simple nodes not supported. PBF should use dense nodes"
);
inline void PBFParser::parseNode(_ThreadData * )
{
throw OSRMException("Parsing of simple nodes not supported. PBF should use dense nodes");
}
inline void PBFParser::parseRelation(_ThreadData * threadData) {
@ -351,25 +352,29 @@ inline void PBFParser::parseWay(_ThreadData * threadData) {
}
}
#pragma omp parallel
{
const int thread_num = omp_get_thread_num();
#pragma omp parallel for schedule ( guided )
for(int i = 0; i < number_of_ways; ++i) {
for(int i = 0; i < number_of_ways; ++i)
{
ExtractionWay & extraction_way = parsed_way_vector[i];
if (2 > extraction_way.path.size())
if (2 <= extraction_way.path.size())
{
continue;
ParseWayInLua(
extraction_way,
scripting_environment.getLuaStateForThreadID(thread_num)
);
}
ParseWayInLua(
extraction_way,
scripting_environment.getLuaStateForThreadID( omp_get_thread_num())
);
}
}
BOOST_FOREACH(ExtractionWay & extraction_way, parsed_way_vector) {
if (2 > extraction_way.path.size())
BOOST_FOREACH(ExtractionWay & extraction_way, parsed_way_vector)
{
if (2 <= extraction_way.path.size())
{
continue;
extractor_callbacks->wayFunction(extraction_way);
}
extractor_callbacks->wayFunction(extraction_way);
}
}

View File

@ -58,7 +58,6 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
// Add our function to the state's global scope
luabind::module(myLuaState) [
luabind::def("print", LUA_print<std::string>),
// luabind::def("parseMaxspeed", parseMaxspeed),
luabind::def("durationIsValid", durationIsValid),
luabind::def("parseDuration", parseDuration)
];
@ -106,9 +105,8 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
// fails on c++11/OS X 10.9
luabind::module(myLuaState) [
luabind::class_<std::vector<std::string> >("vector")
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string&)>(&std::vector<std::string>::push_back)
)
luabind::class_<std::vector<std::string> >("vector")
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string&)>(&std::vector<std::string>::push_back))
];
if(0 != luaL_dofile(myLuaState, fileName) ) {

View File

@ -273,7 +273,7 @@ ImportNode XMLParser::_ReadXMLNode() {
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
if ( k != NULL && value != NULL ) {
node.keyVals.Add(std::string( reinterpret_cast<char*>(k) ), std::string( reinterpret_cast<char*>(value)));
node.keyVals.emplace(std::string(reinterpret_cast<char*>(k)), std::string(reinterpret_cast<char*>(value)));
}
if ( k != NULL ) {
xmlFree( k );