osrm-backend/include/partitioner/serialization.hpp

98 lines
4.0 KiB
C++
Raw Normal View History

#ifndef OSRM_PARTITIONER_SERIALIZATION_HPP
#define OSRM_PARTITIONER_SERIALIZATION_HPP
2017-03-01 17:55:18 -05:00
#include "partitioner/cell_storage.hpp"
#include "partitioner/edge_based_graph.hpp"
#include "partitioner/multi_level_graph.hpp"
#include "partitioner/multi_level_partition.hpp"
#include "storage/block.hpp"
2017-03-01 17:55:18 -05:00
#include "storage/io.hpp"
#include "storage/serialization.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "storage/tar.hpp"
2017-03-01 17:55:18 -05:00
namespace osrm
{
namespace partitioner
2017-03-01 17:55:18 -05:00
{
2017-04-01 17:56:47 -04:00
namespace serialization
2017-03-01 17:55:18 -05:00
{
template <typename EdgeDataT, storage::Ownership Ownership>
2018-03-15 06:38:48 -04:00
inline void read(storage::tar::FileReader &reader,
const std::string &name,
MultiLevelGraph<EdgeDataT, Ownership> &graph,
std::uint32_t &connectivity_checksum)
{
2018-03-15 06:38:48 -04:00
storage::serialization::read(reader, name + "/node_array", graph.node_array);
storage::serialization::read(reader, name + "/edge_array", graph.edge_array);
storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset);
connectivity_checksum = reader.ReadOne<std::uint32_t>(name + "/connectivity_checksum");
}
template <typename EdgeDataT, storage::Ownership Ownership>
2018-03-15 06:38:48 -04:00
inline void write(storage::tar::FileWriter &writer,
const std::string &name,
const MultiLevelGraph<EdgeDataT, Ownership> &graph,
const std::uint32_t connectivity_checksum)
{
2018-03-15 06:38:48 -04:00
storage::serialization::write(writer, name + "/node_array", graph.node_array);
storage::serialization::write(writer, name + "/edge_array", graph.edge_array);
storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset);
writer.WriteElementCount64(name + "/connectivity_checksum", 1);
2018-03-15 06:38:48 -04:00
writer.WriteOne(name + "/connectivity_checksum", connectivity_checksum);
}
2017-04-02 12:35:28 -04:00
template <storage::Ownership Ownership>
inline void read(storage::tar::FileReader &reader,
const std::string &name,
detail::MultiLevelPartitionImpl<Ownership> &mlp)
2017-03-06 09:50:04 -05:00
{
*mlp.level_data = reader.ReadOne<typename std::remove_reference_t<decltype(mlp)>::LevelData>(name + "/level_data");
storage::serialization::read(reader, name + "/partition", mlp.partition);
storage::serialization::read(reader, name + "/cell_to_children", mlp.cell_to_children);
2017-03-06 09:50:04 -05:00
}
2017-04-02 12:35:28 -04:00
template <storage::Ownership Ownership>
inline void write(storage::tar::FileWriter &writer,
const std::string &name,
2017-04-02 12:35:28 -04:00
const detail::MultiLevelPartitionImpl<Ownership> &mlp)
2017-03-01 17:55:18 -05:00
{
writer.WriteElementCount64(name + "/level_data", 1);
writer.WriteOne(name + "/level_data", *mlp.level_data);
storage::serialization::write(writer, name + "/partition", mlp.partition);
storage::serialization::write(writer, name + "/cell_to_children", mlp.cell_to_children);
2017-03-01 17:55:18 -05:00
}
2017-03-04 13:36:29 -05:00
2017-04-02 12:35:28 -04:00
template <storage::Ownership Ownership>
inline void read(storage::tar::FileReader &reader,
const std::string &name,
detail::CellStorageImpl<Ownership> &storage)
{
storage::serialization::read(reader, name + "/source_boundary", storage.source_boundary);
storage::serialization::read(
reader, name + "/destination_boundary", storage.destination_boundary);
storage::serialization::read(reader, name + "/cells", storage.cells);
storage::serialization::read(
reader, name + "/level_to_cell_offset", storage.level_to_cell_offset);
}
2017-04-02 12:35:28 -04:00
template <storage::Ownership Ownership>
inline void write(storage::tar::FileWriter &writer,
const std::string &name,
2017-04-02 12:35:28 -04:00
const detail::CellStorageImpl<Ownership> &storage)
2017-03-04 13:36:29 -05:00
{
storage::serialization::write(writer, name + "/source_boundary", storage.source_boundary);
storage::serialization::write(
writer, name + "/destination_boundary", storage.destination_boundary);
storage::serialization::write(writer, name + "/cells", storage.cells);
storage::serialization::write(
writer, name + "/level_to_cell_offset", storage.level_to_cell_offset);
2017-03-04 13:36:29 -05:00
}
2017-03-01 17:55:18 -05:00
}
}
}
#endif