replace hashmap with a dummy vector based implementation as the number of tags per object is tiny
This commit is contained in:
parent
f99f194927
commit
b06a73e893
@ -28,37 +28,50 @@ 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 <unordered_map>
|
#include <vector>
|
||||||
|
|
||||||
template <typename Key, typename Value> class HashTable : public std::unordered_map<Key, Value>
|
template <typename Key, typename Value>
|
||||||
|
class HashTable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef std::unordered_map<Key, Value> super;
|
typedef std::pair<Key, Value> KeyValPair;
|
||||||
|
std::vector<KeyValPair> table;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HashTable() : super() {}
|
HashTable() {}
|
||||||
|
|
||||||
explicit HashTable(const unsigned size) : super(size) {}
|
inline void Add(Key const &key, Value const &value)
|
||||||
|
{
|
||||||
|
table.emplace_back(std::move(key), std::move(value));
|
||||||
|
}
|
||||||
|
|
||||||
inline void Add(Key const &key, Value const &value) { super::emplace(key, value); }
|
inline void Clear()
|
||||||
|
{
|
||||||
|
table.clear();
|
||||||
|
}
|
||||||
|
|
||||||
inline const Value Find(Key const &key) const
|
inline const Value Find(Key const &key) const
|
||||||
{
|
{
|
||||||
auto iter = super::find(key);
|
for (const auto &key_val_pair : table)
|
||||||
if (iter == super::end())
|
|
||||||
{
|
{
|
||||||
return Value();
|
if (key_val_pair.first == key)
|
||||||
|
{
|
||||||
|
return key_val_pair.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return iter->second;
|
return Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const bool Holds(Key const &key) const
|
inline const bool Holds(Key const &key) const
|
||||||
{
|
{
|
||||||
if (super::find(key) == super::end())
|
for (const auto &key_val_pair : table)
|
||||||
{
|
{
|
||||||
return false;
|
if (key_val_pair.first == key)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ struct ExtractionWay
|
|||||||
id = SPECIAL_NODEID;
|
id = SPECIAL_NODEID;
|
||||||
nameID = INVALID_NAMEID;
|
nameID = INVALID_NAMEID;
|
||||||
path.clear();
|
path.clear();
|
||||||
keyVals.clear();
|
keyVals.Clear();
|
||||||
direction = ExtractionWay::notSure;
|
direction = ExtractionWay::notSure;
|
||||||
speed = -1;
|
speed = -1;
|
||||||
backward_speed = -1;
|
backward_speed = -1;
|
||||||
|
@ -40,7 +40,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <osrm/Coordinate.h>
|
#include <osrm/Coordinate.h>
|
||||||
|
|
||||||
XMLParser::XMLParser(const char *filename, ExtractorCallbacks *extractor_callbacks, ScriptingEnvironment &scripting_environment)
|
XMLParser::XMLParser(const char *filename,
|
||||||
|
ExtractorCallbacks *extractor_callbacks,
|
||||||
|
ScriptingEnvironment &scripting_environment)
|
||||||
: BaseParser(extractor_callbacks, scripting_environment)
|
: BaseParser(extractor_callbacks, scripting_environment)
|
||||||
{
|
{
|
||||||
inputReader = inputReaderFactory(filename);
|
inputReader = inputReaderFactory(filename);
|
||||||
@ -81,7 +83,8 @@ bool XMLParser::Parse()
|
|||||||
if (use_turn_restrictions && xmlStrEqual(currentName, (const xmlChar *)"relation") == 1)
|
if (use_turn_restrictions && xmlStrEqual(currentName, (const xmlChar *)"relation") == 1)
|
||||||
{
|
{
|
||||||
InputRestrictionContainer current_restriction = ReadXMLRestriction();
|
InputRestrictionContainer current_restriction = ReadXMLRestriction();
|
||||||
if ((UINT_MAX != current_restriction.fromWay) && !extractor_callbacks->ProcessRestriction(current_restriction))
|
if ((UINT_MAX != current_restriction.fromWay) &&
|
||||||
|
!extractor_callbacks->ProcessRestriction(current_restriction))
|
||||||
{
|
{
|
||||||
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
|
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
|
||||||
}
|
}
|
||||||
@ -135,7 +138,7 @@ InputRestrictionContainer XMLParser::ReadXMLRestriction()
|
|||||||
if (key != NULL && value != NULL)
|
if (key != NULL && value != NULL)
|
||||||
{
|
{
|
||||||
if (xmlStrEqual(key, (const xmlChar *)"restriction") &&
|
if (xmlStrEqual(key, (const xmlChar *)"restriction") &&
|
||||||
StringStartsWith((const char*)value, "only_") )
|
StringStartsWith((const char *)value, "only_"))
|
||||||
{
|
{
|
||||||
restriction.restriction.flags.isOnly = true;
|
restriction.restriction.flags.isOnly = true;
|
||||||
}
|
}
|
||||||
@ -195,7 +198,6 @@ InputRestrictionContainer XMLParser::ReadXMLRestriction()
|
|||||||
xmlFree(child_name);
|
xmlFree(child_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ShouldIgnoreRestriction(except_tag_string))
|
if (ShouldIgnoreRestriction(except_tag_string))
|
||||||
{
|
{
|
||||||
restriction.fromWay = UINT_MAX; // workaround to ignore the restriction
|
restriction.fromWay = UINT_MAX; // workaround to ignore the restriction
|
||||||
|
@ -38,7 +38,9 @@ class ExtractorCallbacks;
|
|||||||
class XMLParser : public BaseParser
|
class XMLParser : public BaseParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XMLParser(const char *filename, ExtractorCallbacks *extractor_callbacks, ScriptingEnvironment &scripting_environment);
|
XMLParser(const char *filename,
|
||||||
|
ExtractorCallbacks *extractor_callbacks,
|
||||||
|
ScriptingEnvironment &scripting_environment);
|
||||||
bool ReadHeader();
|
bool ReadHeader();
|
||||||
bool Parse();
|
bool Parse();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user