2017-04-02 19:02:57 -04:00
|
|
|
#ifndef OSRM_CONTRACTOR_FILES_HPP
|
|
|
|
#define OSRM_CONTRACTOR_FILES_HPP
|
|
|
|
|
|
|
|
#include "contractor/query_graph.hpp"
|
|
|
|
|
|
|
|
#include "util/serialization.hpp"
|
|
|
|
|
2017-04-07 05:02:02 -04:00
|
|
|
#include "storage/serialization.hpp"
|
2018-03-22 14:26:40 -04:00
|
|
|
#include "storage/tar.hpp"
|
2017-04-02 19:02:57 -04:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace contractor
|
|
|
|
{
|
|
|
|
namespace files
|
|
|
|
{
|
|
|
|
// reads .osrm.hsgr file
|
2017-08-20 19:24:05 -04:00
|
|
|
template <typename QueryGraphT, typename EdgeFilterT>
|
|
|
|
inline void readGraph(const boost::filesystem::path &path,
|
|
|
|
unsigned &checksum,
|
|
|
|
QueryGraphT &graph,
|
2018-02-01 10:00:15 -05:00
|
|
|
std::vector<EdgeFilterT> &edge_filter,
|
|
|
|
std::uint32_t &connectivity_checksum)
|
2017-04-02 19:02:57 -04:00
|
|
|
{
|
2017-04-03 10:21:13 -04:00
|
|
|
static_assert(std::is_same<QueryGraphView, QueryGraphT>::value ||
|
|
|
|
std::is_same<QueryGraph, QueryGraphT>::value,
|
|
|
|
"graph must be of type QueryGraph<>");
|
2017-08-20 19:24:05 -04:00
|
|
|
static_assert(std::is_same<EdgeFilterT, std::vector<bool>>::value ||
|
|
|
|
std::is_same<EdgeFilterT, util::vector_view<bool>>::value,
|
|
|
|
"edge_filter must be a container of vector<bool> or vector_view<bool>");
|
2017-04-03 10:21:13 -04:00
|
|
|
|
2018-03-15 16:10:21 -04:00
|
|
|
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
|
|
|
|
storage::tar::FileReader reader{path, fingerprint};
|
2017-04-02 19:02:57 -04:00
|
|
|
|
2018-03-19 19:31:49 -04:00
|
|
|
reader.ReadInto("/ch/checksum", checksum);
|
2018-03-15 16:10:21 -04:00
|
|
|
util::serialization::read(reader, "/ch/contracted_graph", graph);
|
|
|
|
|
|
|
|
auto count = reader.ReadElementCount64("/ch/edge_filter");
|
2017-08-20 19:24:05 -04:00
|
|
|
edge_filter.resize(count);
|
|
|
|
for (const auto index : util::irange<std::size_t>(0, count))
|
|
|
|
{
|
2018-03-22 14:26:40 -04:00
|
|
|
storage::serialization::read(
|
|
|
|
reader, "/ch/edge_filter/" + std::to_string(index), edge_filter[index]);
|
2017-08-20 19:24:05 -04:00
|
|
|
}
|
2018-03-15 16:10:21 -04:00
|
|
|
|
2018-03-22 14:26:40 -04:00
|
|
|
reader.ReadInto("/ch/connectivity_checksum", connectivity_checksum);
|
2017-04-02 19:02:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// writes .osrm.hsgr file
|
2017-08-20 19:24:05 -04:00
|
|
|
template <typename QueryGraphT, typename EdgeFilterT>
|
|
|
|
inline void writeGraph(const boost::filesystem::path &path,
|
|
|
|
unsigned checksum,
|
|
|
|
const QueryGraphT &graph,
|
2018-02-01 10:00:15 -05:00
|
|
|
const std::vector<EdgeFilterT> &edge_filter,
|
|
|
|
const std::uint32_t connectivity_checksum)
|
2017-04-02 19:02:57 -04:00
|
|
|
{
|
2017-04-03 10:21:13 -04:00
|
|
|
static_assert(std::is_same<QueryGraphView, QueryGraphT>::value ||
|
|
|
|
std::is_same<QueryGraph, QueryGraphT>::value,
|
|
|
|
"graph must be of type QueryGraph<>");
|
2017-08-20 19:24:05 -04:00
|
|
|
static_assert(std::is_same<EdgeFilterT, std::vector<bool>>::value ||
|
|
|
|
std::is_same<EdgeFilterT, util::vector_view<bool>>::value,
|
|
|
|
"edge_filter must be a container of vector<bool> or vector_view<bool>");
|
2018-03-15 16:10:21 -04:00
|
|
|
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
|
|
|
|
storage::tar::FileWriter writer{path, fingerprint};
|
2017-04-02 19:02:57 -04:00
|
|
|
|
2018-03-15 16:10:21 -04:00
|
|
|
writer.WriteElementCount64("/ch/checksum", 1);
|
2018-03-19 19:31:49 -04:00
|
|
|
writer.WriteFrom("/ch/checksum", checksum);
|
2018-03-15 16:10:21 -04:00
|
|
|
util::serialization::write(writer, "/ch/contracted_graph", graph);
|
|
|
|
|
|
|
|
writer.WriteElementCount64("/ch/edge_filter", edge_filter.size());
|
2018-03-16 10:59:05 -04:00
|
|
|
for (const auto index : util::irange<std::size_t>(0, edge_filter.size()))
|
2017-08-20 19:24:05 -04:00
|
|
|
{
|
2018-03-22 14:26:40 -04:00
|
|
|
storage::serialization::write(
|
|
|
|
writer, "/ch/edge_filter/" + std::to_string(index), edge_filter[index]);
|
2017-08-20 19:24:05 -04:00
|
|
|
}
|
2018-03-15 16:10:21 -04:00
|
|
|
|
|
|
|
writer.WriteElementCount64("/ch/connectivity_checksum", 1);
|
2018-03-19 19:31:49 -04:00
|
|
|
writer.WriteFrom("/ch/connectivity_checksum", connectivity_checksum);
|
2017-04-02 19:02:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|