From 265af1f7904bb76c4bf7aa726ca656cb35dcdadb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 28 Apr 2014 17:27:15 +0200 Subject: [PATCH] minor refactoring --- DataStructures/HashTable.h | 27 +++++++++------- Extractor/ExtractorCallbacks.cpp | 1 - Extractor/PBFParser.cpp | 49 ++++++++++++++++-------------- Extractor/ScriptingEnvironment.cpp | 6 ++-- Extractor/XMLParser.cpp | 2 +- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/DataStructures/HashTable.h b/DataStructures/HashTable.h index 871ba4933..111296ea7 100644 --- a/DataStructures/HashTable.h +++ b/DataStructures/HashTable.h @@ -28,41 +28,46 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef HASH_TABLE_H #define HASH_TABLE_H +#include #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; + 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 -ValueT HashTable::default_value; +template +Value HashTable::default_value; #endif /* HASH_TABLE_H */ diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index 9ac9cb1cb..17ef0e9ca 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -26,7 +26,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "ExtractorCallbacks.h" - #include "ExtractionContainers.h" #include "ExtractionWay.h" diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index 003552885..9126be8a1 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -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); } } diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index 998e2f198..5f15b392a 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -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), - // 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_ >("vector") - .def("Add", static_cast::*)(const std::string&)>(&std::vector::push_back) - ) + luabind::class_ >("vector") + .def("Add", static_cast::*)(const std::string&)>(&std::vector::push_back)) ]; if(0 != luaL_dofile(myLuaState, fileName) ) { diff --git a/Extractor/XMLParser.cpp b/Extractor/XMLParser.cpp index 2fdcb6a6e..06ace2f2d 100644 --- a/Extractor/XMLParser.cpp +++ b/Extractor/XMLParser.cpp @@ -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(k) ), std::string( reinterpret_cast(value))); + node.keyVals.emplace(std::string(reinterpret_cast(k)), std::string(reinterpret_cast(value))); } if ( k != NULL ) { xmlFree( k );