2017-03-07 19:38:08 -05:00
|
|
|
#ifndef OSRM_UPDATER_SOURCE_HPP
|
|
|
|
#define OSRM_UPDATER_SOURCE_HPP
|
|
|
|
|
|
|
|
#include "util/typedefs.hpp"
|
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::updater
|
2017-03-07 19:38:08 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
template <typename Key, typename Value> struct LookupTable
|
|
|
|
{
|
|
|
|
boost::optional<Value> operator()(const Key &key) const
|
|
|
|
{
|
|
|
|
using Result = boost::optional<Value>;
|
2024-05-06 03:14:46 -04:00
|
|
|
const auto it =
|
|
|
|
std::lower_bound(lookup.begin(),
|
|
|
|
lookup.end(),
|
|
|
|
key,
|
|
|
|
[](const auto &lhs, const auto &rhs) { return rhs < lhs.first; });
|
2017-03-07 19:38:08 -05:00
|
|
|
return it != std::end(lookup) && !(it->first < key) ? Result(it->second) : Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<Key, Value>> lookup;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Segment final
|
|
|
|
{
|
|
|
|
std::uint64_t from, to;
|
|
|
|
Segment() : from(0), to(0) {}
|
|
|
|
Segment(const std::uint64_t from, const std::uint64_t to) : from(from), to(to) {}
|
|
|
|
Segment(const OSMNodeID from, const OSMNodeID to)
|
|
|
|
: from(static_cast<std::uint64_t>(from)), to(static_cast<std::uint64_t>(to))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const Segment &rhs) const
|
|
|
|
{
|
|
|
|
return std::tie(from, to) < std::tie(rhs.from, rhs.to);
|
|
|
|
}
|
|
|
|
bool operator==(const Segment &rhs) const
|
|
|
|
{
|
|
|
|
return std::tie(from, to) == std::tie(rhs.from, rhs.to);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SpeedSource final
|
|
|
|
{
|
2022-08-30 09:34:46 -04:00
|
|
|
SpeedSource() : speed(0.), rate() {}
|
|
|
|
double speed;
|
2017-08-31 17:51:05 -04:00
|
|
|
boost::optional<double> rate;
|
2017-03-07 19:38:08 -05:00
|
|
|
std::uint8_t source;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Turn final
|
|
|
|
{
|
|
|
|
std::uint64_t from, via, to;
|
|
|
|
Turn() : from(0), via(0), to(0) {}
|
|
|
|
Turn(const std::uint64_t from, const std::uint64_t via, const std::uint64_t to)
|
|
|
|
: from(from), via(via), to(to)
|
|
|
|
{
|
|
|
|
}
|
2017-05-11 06:13:52 -04:00
|
|
|
Turn(const OSMNodeID &from_id, const OSMNodeID &via_id, const OSMNodeID &to_id)
|
|
|
|
: from(static_cast<std::uint64_t>(from_id)), via(static_cast<std::uint64_t>(via_id)),
|
|
|
|
to(static_cast<std::uint64_t>(to_id))
|
2017-03-07 19:38:08 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
bool operator<(const Turn &rhs) const
|
|
|
|
{
|
|
|
|
return std::tie(from, via, to) < std::tie(rhs.from, rhs.via, rhs.to);
|
|
|
|
}
|
|
|
|
bool operator==(const Turn &rhs) const
|
|
|
|
{
|
|
|
|
return std::tie(from, via, to) == std::tie(rhs.from, rhs.via, rhs.to);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PenaltySource final
|
|
|
|
{
|
|
|
|
PenaltySource() : duration(0.), weight(std::numeric_limits<double>::quiet_NaN()) {}
|
|
|
|
double duration;
|
|
|
|
double weight;
|
|
|
|
std::uint8_t source;
|
|
|
|
};
|
|
|
|
|
|
|
|
using SegmentLookupTable = LookupTable<Segment, SpeedSource>;
|
|
|
|
using TurnLookupTable = LookupTable<Turn, PenaltySource>;
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::updater
|
2017-03-07 19:38:08 -05:00
|
|
|
|
|
|
|
#endif
|