osrm-backend/include/extractor/restriction_map.hpp

111 lines
2.9 KiB
C++
Raw Normal View History

#ifndef RESTRICTION_MAP_HPP
#define RESTRICTION_MAP_HPP
#include "extractor/edge_based_edge.hpp"
2016-01-02 11:13:44 -05:00
#include "extractor/restriction.hpp"
#include "util/std_hash.hpp"
#include "util/typedefs.hpp"
#include <boost/assert.hpp>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>
2016-01-05 10:51:13 -05:00
namespace osrm
{
namespace extractor
{
struct RestrictionSource
{
NodeID start_node;
NodeID via_node;
2015-01-27 11:44:46 -05:00
RestrictionSource(NodeID start, NodeID via) : start_node(start), via_node(via) {}
friend inline bool operator==(const RestrictionSource &lhs, const RestrictionSource &rhs)
{
return (lhs.start_node == rhs.start_node && lhs.via_node == rhs.via_node);
}
};
struct RestrictionTarget
{
NodeID target_node;
bool is_only;
2015-01-27 11:44:46 -05:00
explicit RestrictionTarget(NodeID target, bool only) : target_node(target), is_only(only) {}
friend inline bool operator==(const RestrictionTarget &lhs, const RestrictionTarget &rhs)
{
return (lhs.target_node == rhs.target_node && lhs.is_only == rhs.is_only);
}
};
2016-01-05 10:51:13 -05:00
}
}
namespace std
{
2016-01-05 10:51:13 -05:00
template <> struct hash<osrm::extractor::RestrictionSource>
2014-06-26 07:50:15 -04:00
{
2016-01-05 10:51:13 -05:00
size_t operator()(const osrm::extractor::RestrictionSource &r_source) const
{
2014-06-26 07:50:15 -04:00
return hash_val(r_source.start_node, r_source.via_node);
}
};
2016-01-05 10:51:13 -05:00
template <> struct hash<osrm::extractor::RestrictionTarget>
2014-06-26 07:50:15 -04:00
{
2016-01-05 10:51:13 -05:00
size_t operator()(const osrm::extractor::RestrictionTarget &r_target) const
{
2014-06-26 07:50:15 -04:00
return hash_val(r_target.target_node, r_target.is_only);
}
};
}
2016-01-05 10:51:13 -05:00
namespace osrm
{
namespace extractor
{
/**
\brief Efficent look up if an edge is the start + via node of a TurnRestriction
EdgeBasedEdgeFactory decides by it if edges are inserted or geometry is compressed
*/
class RestrictionMap
{
public:
2016-05-27 15:05:04 -04:00
RestrictionMap() : m_count(0) {}
RestrictionMap(const std::vector<TurnRestriction> &restriction_list);
bool IsViaNode(const NodeID node) const;
// Check if edge (u, v) is the start of any turn restriction.
// If so returns id of first target node.
NodeID CheckForEmanatingIsOnlyTurn(const NodeID node_u, const NodeID node_v) const;
// Checks if turn <u,v,w> is actually a turn restriction.
2015-01-27 11:44:46 -05:00
bool
CheckIfTurnIsRestricted(const NodeID node_u, const NodeID node_v, const NodeID node_w) const;
std::size_t size() const { return m_count; }
private:
// check of node is the start of any restriction
bool IsSourceNode(const NodeID node) const;
using EmanatingRestrictionsVector = std::vector<RestrictionTarget>;
std::size_t m_count;
//! index -> list of (target, isOnly)
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
//! maps (start, via) -> bucket index
std::unordered_map<RestrictionSource, unsigned> m_restriction_map;
std::unordered_set<NodeID> m_restriction_start_nodes;
std::unordered_set<NodeID> m_no_turn_via_node_set;
};
2016-01-05 10:51:13 -05:00
}
}
2015-01-27 11:44:46 -05:00
#endif // RESTRICTION_MAP_HPP