minor refactoring
This commit is contained in:
parent
241d6b482e
commit
265af1f790
@ -28,41 +28,46 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#ifndef HASH_TABLE_H
|
#ifndef HASH_TABLE_H
|
||||||
#define HASH_TABLE_H
|
#define HASH_TABLE_H
|
||||||
|
|
||||||
|
#include <boost/functional/hash.hpp>
|
||||||
#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 Key, typename Value, typename Hash = boost::hash<Key> >
|
||||||
class HashTable : public boost::unordered_map<KeyT, ValueT> {
|
class HashTable : public boost::unordered_map<Key, Value> {
|
||||||
private:
|
private:
|
||||||
typedef boost::unordered_map<KeyT, ValueT> super;
|
typedef boost::unordered_map<Key, Value, Hash> super;
|
||||||
public:
|
public:
|
||||||
static ValueT default_value;
|
static Value default_value;
|
||||||
|
|
||||||
HashTable() : super() { }
|
HashTable() : super() { }
|
||||||
|
|
||||||
explicit HashTable(const unsigned size) : super(size) { }
|
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));
|
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);
|
typename super::const_iterator iter = super::find(key);
|
||||||
if( iter == super::end() ) {
|
if (iter == super::end())
|
||||||
|
{
|
||||||
return boost::cref(default_value);
|
return boost::cref(default_value);
|
||||||
}
|
}
|
||||||
return boost::cref(iter->second);
|
return boost::cref(iter->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const bool Holds( KeyT const & key) const {
|
inline const bool Holds( Key const & key) const
|
||||||
if( super::find(key) == super::end() ) {
|
{
|
||||||
|
if(super::find(key) == super::end())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename KeyT, typename ValueT>
|
template<typename Key, typename Value, typename Hash>
|
||||||
ValueT HashTable<KeyT, ValueT>::default_value;
|
Value HashTable<Key, Value, Hash>::default_value;
|
||||||
|
|
||||||
#endif /* HASH_TABLE_H */
|
#endif /* HASH_TABLE_H */
|
||||||
|
@ -26,7 +26,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ExtractorCallbacks.h"
|
#include "ExtractorCallbacks.h"
|
||||||
|
|
||||||
#include "ExtractionContainers.h"
|
#include "ExtractionContainers.h"
|
||||||
#include "ExtractionWay.h"
|
#include "ExtractionWay.h"
|
||||||
|
|
||||||
|
@ -215,25 +215,26 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) {
|
|||||||
denseTagIndex += 2;
|
denseTagIndex += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
const int thread_num = omp_get_thread_num();
|
||||||
#pragma omp parallel for schedule ( guided )
|
#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];
|
ImportNode & import_node = extracted_nodes_vector[i];
|
||||||
ParseNodeInLua(
|
ParseNodeInLua(import_node, scripting_environment.getLuaStateForThreadID(thread_num));
|
||||||
import_node,
|
|
||||||
scripting_environment.getLuaStateForThreadID(omp_get_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);
|
extractor_callbacks->nodeFunction(import_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PBFParser::parseNode(_ThreadData * ) {
|
inline void PBFParser::parseNode(_ThreadData * )
|
||||||
throw OSRMException(
|
{
|
||||||
"Parsing of simple nodes not supported. PBF should use dense nodes"
|
throw OSRMException("Parsing of simple nodes not supported. PBF should use dense nodes");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PBFParser::parseRelation(_ThreadData * threadData) {
|
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 )
|
#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];
|
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) {
|
BOOST_FOREACH(ExtractionWay & extraction_way, parsed_way_vector)
|
||||||
if (2 > extraction_way.path.size())
|
{
|
||||||
|
if (2 <= extraction_way.path.size())
|
||||||
{
|
{
|
||||||
continue;
|
extractor_callbacks->wayFunction(extraction_way);
|
||||||
}
|
}
|
||||||
extractor_callbacks->wayFunction(extraction_way);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
|
|||||||
// Add our function to the state's global scope
|
// Add our function to the state's global scope
|
||||||
luabind::module(myLuaState) [
|
luabind::module(myLuaState) [
|
||||||
luabind::def("print", LUA_print<std::string>),
|
luabind::def("print", LUA_print<std::string>),
|
||||||
// luabind::def("parseMaxspeed", parseMaxspeed),
|
|
||||||
luabind::def("durationIsValid", durationIsValid),
|
luabind::def("durationIsValid", durationIsValid),
|
||||||
luabind::def("parseDuration", parseDuration)
|
luabind::def("parseDuration", parseDuration)
|
||||||
];
|
];
|
||||||
@ -106,9 +105,8 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
|
|||||||
|
|
||||||
// fails on c++11/OS X 10.9
|
// fails on c++11/OS X 10.9
|
||||||
luabind::module(myLuaState) [
|
luabind::module(myLuaState) [
|
||||||
luabind::class_<std::vector<std::string> >("vector")
|
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)
|
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string&)>(&std::vector<std::string>::push_back))
|
||||||
)
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if(0 != luaL_dofile(myLuaState, fileName) ) {
|
if(0 != luaL_dofile(myLuaState, fileName) ) {
|
||||||
|
@ -273,7 +273,7 @@ ImportNode XMLParser::_ReadXMLNode() {
|
|||||||
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
|
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
|
||||||
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
|
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
|
||||||
if ( k != NULL && value != NULL ) {
|
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 ) {
|
if ( k != NULL ) {
|
||||||
xmlFree( k );
|
xmlFree( k );
|
||||||
|
Loading…
Reference in New Issue
Block a user