No shared_memory_wrapper, (De)SerializeVector

This commit is contained in:
Patrick Niklaus
2017-04-04 22:00:17 +00:00
committed by Patrick Niklaus
parent dce0ce0e17
commit d94017dfae
24 changed files with 292 additions and 321 deletions
+15 -15
View File
@@ -2,7 +2,7 @@
#define OSRM_EXTRACTOR_FILES_HPP
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/seralization.hpp"
#include "extractor/serialization.hpp"
#include "util/coordinate.hpp"
#include "util/packed_vector.hpp"
@@ -20,26 +20,26 @@ namespace files
// reads .osrm.nodes
template<storage::Ownership Ownership>
inline void readNodes(const boost::filesystem::path &path,
typename util::ShM<util::Coordinate, Ownership>::vector &coordinates,
util::ViewOrVector<util::Coordinate, Ownership> &coordinates,
util::detail::PackedVector<OSMNodeID, Ownership> &osm_node_ids)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.DeserializeVector(coordinates);
storage::serialization::read(reader, coordinates);
util::serialization::read(reader, osm_node_ids);
}
// writes .osrm.nodes
template<storage::Ownership Ownership>
inline void writeNodes(const boost::filesystem::path &path,
const typename util::ShM<util::Coordinate, Ownership>::vector &coordinates,
const util::ViewOrVector<util::Coordinate, Ownership> &coordinates,
const util::detail::PackedVector<OSMNodeID, Ownership> &osm_node_ids)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.SerializeVector(coordinates);
storage::serialization::write(writer, coordinates);
util::serialization::write(writer, osm_node_ids);
}
@@ -49,7 +49,7 @@ inline void readNBGMapping(const boost::filesystem::path &path, std::vector<NBGT
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, mapping);
storage::serialization::read(reader, mapping);
}
// writes .osrm.cnbg_to_ebg
@@ -59,7 +59,7 @@ inline void writeNBGMapping(const boost::filesystem::path &path,
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, mapping);
storage::serialization::write(writer, mapping);
}
// reads .osrm.datasource_names
@@ -127,27 +127,27 @@ inline void writeTurnData(const boost::filesystem::path &path,
// reads .osrm.tls
template <storage::Ownership Ownership>
inline void readTurnLaneDescriptions(const boost::filesystem::path &path,
typename util::ShM<std::uint32_t, Ownership>::vector &turn_offsets,
typename util::ShM<extractor::guidance::TurnLaneType::Mask, Ownership>::vector &turn_masks)
util::ViewOrVector<std::uint32_t, Ownership> &turn_offsets,
util::ViewOrVector<extractor::guidance::TurnLaneType::Mask, Ownership> &turn_masks)
{
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.DeserializeVector(turn_offsets);
reader.DeserializeVector(turn_masks);
storage::serialization::read(reader, turn_offsets);
storage::serialization::read(reader, turn_masks);
}
// writes .osrm.tls
template <storage::Ownership Ownership>
inline void writeTurnLaneDescriptions(const boost::filesystem::path &path,
const typename util::ShM<std::uint32_t, Ownership>::vector &turn_offsets,
const typename util::ShM<extractor::guidance::TurnLaneType::Mask, Ownership>::vector &turn_masks)
const util::ViewOrVector<std::uint32_t, Ownership> &turn_offsets,
const util::ViewOrVector<extractor::guidance::TurnLaneType::Mask, Ownership> &turn_masks)
{
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.SerializeVector(turn_offsets);
writer.SerializeVector(turn_masks);
storage::serialization::write(writer, turn_offsets);
storage::serialization::write(writer, turn_masks);
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
#define OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
#include "storage/shared_memory_ownership.hpp"
@@ -50,7 +50,7 @@ namespace detail
{
template <storage::Ownership Ownership> class SegmentDataContainerImpl
{
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
friend CompressedEdgeContainer;
-97
View File
@@ -1,97 +0,0 @@
#ifndef OSRM_EXTRACTOR_IO_HPP
#define OSRM_EXTRACTOR_IO_HPP
#include "extractor/datasources.hpp"
#include "extractor/nbg_to_ebg.hpp"
#include "extractor/segment_data_container.hpp"
#include "extractor/turn_data_container.hpp"
#include "storage/io.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace extractor
{
namespace serialization
{
inline void read(storage::io::FileReader &reader, std::vector<NBGToEBG> &mapping)
{
reader.DeserializeVector(mapping);
}
inline void write(storage::io::FileWriter &writer, const std::vector<NBGToEBG> &mapping)
{
writer.SerializeVector(mapping);
}
inline void read(storage::io::FileReader &reader, Datasources &sources)
{
reader.ReadInto(sources);
}
inline void write(storage::io::FileWriter &writer, Datasources &sources)
{
writer.WriteFrom(sources);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
reader.DeserializeVector(segment_data.index);
reader.DeserializeVector(segment_data.nodes);
reader.DeserializeVector(segment_data.fwd_weights);
reader.DeserializeVector(segment_data.rev_weights);
reader.DeserializeVector(segment_data.fwd_durations);
reader.DeserializeVector(segment_data.rev_durations);
reader.DeserializeVector(segment_data.datasources);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
writer.SerializeVector(segment_data.index);
writer.SerializeVector(segment_data.nodes);
writer.SerializeVector(segment_data.fwd_weights);
writer.SerializeVector(segment_data.rev_weights);
writer.SerializeVector(segment_data.fwd_durations);
writer.SerializeVector(segment_data.rev_durations);
writer.SerializeVector(segment_data.datasources);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::TurnDataContainerImpl<Ownership> &turn_data_container)
{
reader.DeserializeVector(turn_data_container.geometry_ids);
reader.DeserializeVector(turn_data_container.name_ids);
reader.DeserializeVector(turn_data_container.turn_instructions);
reader.DeserializeVector(turn_data_container.lane_data_ids);
reader.DeserializeVector(turn_data_container.travel_modes);
reader.DeserializeVector(turn_data_container.entry_class_ids);
reader.DeserializeVector(turn_data_container.pre_turn_bearings);
reader.DeserializeVector(turn_data_container.post_turn_bearings);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::TurnDataContainerImpl<Ownership> &turn_data_container)
{
writer.SerializeVector(turn_data_container.geometry_ids);
writer.SerializeVector(turn_data_container.name_ids);
writer.SerializeVector(turn_data_container.turn_instructions);
writer.SerializeVector(turn_data_container.lane_data_ids);
writer.SerializeVector(turn_data_container.travel_modes);
writer.SerializeVector(turn_data_container.entry_class_ids);
writer.SerializeVector(turn_data_container.pre_turn_bearings);
writer.SerializeVector(turn_data_container.post_turn_bearings);
}
}
}
}
#endif
+88
View File
@@ -0,0 +1,88 @@
#ifndef OSRM_EXTRACTOR_IO_HPP
#define OSRM_EXTRACTOR_IO_HPP
#include "extractor/datasources.hpp"
#include "extractor/nbg_to_ebg.hpp"
#include "extractor/segment_data_container.hpp"
#include "extractor/turn_data_container.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace extractor
{
namespace serialization
{
inline void read(storage::io::FileReader &reader, Datasources &sources)
{
reader.ReadInto(sources);
}
inline void write(storage::io::FileWriter &writer, Datasources &sources)
{
writer.WriteFrom(sources);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
storage::serialization::read(reader, segment_data.index);
storage::serialization::read(reader, segment_data.nodes);
storage::serialization::read(reader, segment_data.fwd_weights);
storage::serialization::read(reader, segment_data.rev_weights);
storage::serialization::read(reader, segment_data.fwd_durations);
storage::serialization::read(reader, segment_data.rev_durations);
storage::serialization::read(reader, segment_data.datasources);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
storage::serialization::write(writer, segment_data.index);
storage::serialization::write(writer, segment_data.nodes);
storage::serialization::write(writer, segment_data.fwd_weights);
storage::serialization::write(writer, segment_data.rev_weights);
storage::serialization::write(writer, segment_data.fwd_durations);
storage::serialization::write(writer, segment_data.rev_durations);
storage::serialization::write(writer, segment_data.datasources);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::TurnDataContainerImpl<Ownership> &turn_data_container)
{
storage::serialization::read(reader, turn_data_container.geometry_ids);
storage::serialization::read(reader, turn_data_container.name_ids);
storage::serialization::read(reader, turn_data_container.turn_instructions);
storage::serialization::read(reader, turn_data_container.lane_data_ids);
storage::serialization::read(reader, turn_data_container.travel_modes);
storage::serialization::read(reader, turn_data_container.entry_class_ids);
storage::serialization::read(reader, turn_data_container.pre_turn_bearings);
storage::serialization::read(reader, turn_data_container.post_turn_bearings);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::TurnDataContainerImpl<Ownership> &turn_data_container)
{
storage::serialization::write(writer, turn_data_container.geometry_ids);
storage::serialization::write(writer, turn_data_container.name_ids);
storage::serialization::write(writer, turn_data_container.turn_instructions);
storage::serialization::write(writer, turn_data_container.lane_data_ids);
storage::serialization::write(writer, turn_data_container.travel_modes);
storage::serialization::write(writer, turn_data_container.entry_class_ids);
storage::serialization::write(writer, turn_data_container.pre_turn_bearings);
storage::serialization::write(writer, turn_data_container.post_turn_bearings);
}
}
}
}
#endif
+2 -2
View File
@@ -6,7 +6,7 @@
#include "storage/shared_memory_ownership.hpp"
#include "util/guidance/turn_bearing.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
@@ -43,7 +43,7 @@ namespace detail
{
template <storage::Ownership Ownership> class TurnDataContainerImpl
{
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
public:
TurnDataContainerImpl() = default;
+2 -2
View File
@@ -6,7 +6,7 @@
#include "util/assert.hpp"
#include "util/for_each_range.hpp"
#include "util/log.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
#include "storage/io.hpp"
@@ -74,7 +74,7 @@ template <storage::Ownership Ownership> class CellStorageImpl
};
private:
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
// Implementation of the cell view. We need a template parameter here
// because we need to derive a read-only and read-write view from this.
+2 -1
View File
@@ -6,6 +6,7 @@
#include "storage/shared_memory_ownership.hpp"
#include "util/static_graph.hpp"
#include "util/vector_view.hpp"
#include <tbb/parallel_sort.h>
@@ -41,7 +42,7 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
{
private:
using SuperT = util::StaticGraph<EdgeDataT, Ownership>;
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
public:
// We limit each node to have 255 edges
+2 -2
View File
@@ -4,7 +4,7 @@
#include "util/exception.hpp"
#include "util/for_each_pair.hpp"
#include "util/msb.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
#include "storage/io.hpp"
@@ -56,7 +56,7 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
static const constexpr std::uint8_t MAX_NUM_LEVEL = 16;
static const constexpr std::uint8_t NUM_PARTITION_BITS = sizeof(PartitionID) * CHAR_BIT;
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
public:
// Contains all data necessary to describe the level hierarchy
+21 -20
View File
@@ -7,6 +7,7 @@
#include "partition/multi_level_partition.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
#include "storage/shared_memory_ownership.hpp"
namespace osrm
@@ -19,26 +20,26 @@ namespace serialization
template <typename EdgeDataT, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, MultiLevelGraph<EdgeDataT, Ownership> &graph)
{
reader.DeserializeVector(graph.node_array);
reader.DeserializeVector(graph.edge_array);
reader.DeserializeVector(graph.node_to_edge_offset);
storage::serialization::read(reader, graph.node_array);
storage::serialization::read(reader, graph.edge_array);
storage::serialization::read(reader, graph.node_to_edge_offset);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const MultiLevelGraph<EdgeDataT, Ownership> &graph)
{
writer.SerializeVector(graph.node_array);
writer.SerializeVector(graph.edge_array);
writer.SerializeVector(graph.node_to_edge_offset);
storage::serialization::write(writer, graph.node_array);
storage::serialization::write(writer, graph.edge_array);
storage::serialization::write(writer, graph.node_to_edge_offset);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::MultiLevelPartitionImpl<Ownership> &mlp)
{
reader.ReadInto(*mlp.level_data);
reader.DeserializeVector(mlp.partition);
reader.DeserializeVector(mlp.cell_to_children);
storage::serialization::read(reader, mlp.partition);
storage::serialization::read(reader, mlp.cell_to_children);
}
template <storage::Ownership Ownership>
@@ -46,29 +47,29 @@ inline void write(storage::io::FileWriter &writer,
const detail::MultiLevelPartitionImpl<Ownership> &mlp)
{
writer.WriteOne(*mlp.level_data);
writer.SerializeVector(mlp.partition);
writer.SerializeVector(mlp.cell_to_children);
storage::serialization::write(writer, mlp.partition);
storage::serialization::write(writer, mlp.cell_to_children);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::CellStorageImpl<Ownership> &storage)
{
reader.DeserializeVector(storage.weights);
reader.DeserializeVector(storage.source_boundary);
reader.DeserializeVector(storage.destination_boundary);
reader.DeserializeVector(storage.cells);
reader.DeserializeVector(storage.level_to_cell_offset);
storage::serialization::read(reader, storage.weights);
storage::serialization::read(reader, storage.source_boundary);
storage::serialization::read(reader, storage.destination_boundary);
storage::serialization::read(reader, storage.cells);
storage::serialization::read(reader, storage.level_to_cell_offset);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::CellStorageImpl<Ownership> &storage)
{
writer.SerializeVector(storage.weights);
writer.SerializeVector(storage.source_boundary);
writer.SerializeVector(storage.destination_boundary);
writer.SerializeVector(storage.cells);
writer.SerializeVector(storage.level_to_cell_offset);
storage::serialization::write(writer, storage.weights);
storage::serialization::write(writer, storage.source_boundary);
storage::serialization::write(writer, storage.destination_boundary);
storage::serialization::write(writer, storage.cells);
storage::serialization::write(writer, storage.level_to_cell_offset);
}
}
}
-70
View File
@@ -128,20 +128,6 @@ class FileReader
std::uint32_t ReadElementCount32() { return ReadOne<std::uint32_t>(); }
std::uint64_t ReadElementCount64() { return ReadOne<std::uint64_t>(); }
template <typename VectorT> void DeserializeVector(VectorT &data)
{
const auto count = ReadElementCount64();
data.resize(count);
ReadInto(data.data(), count);
}
template <typename T> std::size_t GetVectorMemorySize()
{
const auto count = ReadElementCount64();
Skip<T>(count);
return sizeof(count) + sizeof(T) * count;
}
template <typename T> std::size_t ReadVectorSize()
{
const auto count = ReadElementCount64();
@@ -149,19 +135,6 @@ class FileReader
return count;
}
template <typename T> void *DeserializeVector(void *begin, const void *end)
{
auto count = ReadElementCount64();
auto required = reinterpret_cast<char *>(begin) + sizeof(count) + sizeof(T) * count;
if (required > end)
throw util::exception("Not enough memory ");
*reinterpret_cast<decltype(count) *>(begin) = count;
ReadInto(reinterpret_cast<T *>(reinterpret_cast<char *>(begin) + sizeof(decltype(count))),
count);
return required;
}
bool ReadAndCheckFingerprint()
{
auto loaded_fingerprint = ReadOne<util::FingerPrint>();
@@ -199,42 +172,6 @@ class FileReader
input_stream.seekg(current_pos, input_stream.beg);
return length;
}
std::vector<std::string> ReadLines()
{
std::vector<std::string> result;
std::string thisline;
try
{
while (std::getline(input_stream, thisline))
{
result.push_back(thisline);
}
}
catch (const std::ios_base::failure &)
{
// EOF is OK here, everything else, re-throw
if (!input_stream.eof())
throw;
}
return result;
}
std::string ReadLine()
{
std::string thisline;
try
{
std::getline(input_stream, thisline);
}
catch (const std::ios_base::failure & /*e*/)
{
// EOF is OK here, everything else, re-throw
if (!input_stream.eof())
throw;
}
return thisline;
}
};
class FileWriter
@@ -296,13 +233,6 @@ class FileWriter
void WriteElementCount32(const std::uint32_t count) { WriteOne<std::uint32_t>(count); }
void WriteElementCount64(const std::uint64_t count) { WriteOne<std::uint64_t>(count); }
template <typename VectorT> void SerializeVector(const VectorT &data)
{
const auto count = data.size();
WriteElementCount64(count);
return WriteFrom(data.data(), count);
}
void WriteFingerprint()
{
const auto fingerprint = util::FingerPrint::GetValid();
+47
View File
@@ -0,0 +1,47 @@
#ifndef OSRM_STORAGE_SERIALIZATION_HPP
#define OSRM_STORAGE_SERIALIZATION_HPP
#include "util/vector_view.hpp"
#include "storage/io.hpp"
namespace osrm
{
namespace storage
{
namespace serialization
{
template <typename T> void read(io::FileReader &reader, std::vector<T> &data)
{
const auto count = reader.ReadElementCount64();
data.resize(count);
reader.ReadInto(data.data(), count);
}
template <typename T> void write(io::FileWriter &writer, const std::vector<T> &data)
{
const auto count = data.size();
writer.WriteElementCount64(count);
return writer.WriteFrom(data.data(), count);
}
template <typename T> void read(io::FileReader &reader, util::vector_view<T> &data)
{
const auto count = reader.ReadElementCount64();
data.resize(count);
reader.ReadInto(data.data(), count);
}
template <typename T> void write(io::FileWriter &writer, const util::vector_view<T> &data)
{
const auto count = data.size();
writer.WriteElementCount64(count);
return writer.WriteFrom(data.data(), count);
}
}
}
}
#endif
-1
View File
@@ -2,7 +2,6 @@
#define OSRM_UTIL_NAME_TABLE_HPP
#include "util/indexed_data.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef PACKED_VECTOR_HPP
#define PACKED_VECTOR_HPP
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
#include "storage/io.hpp"
@@ -171,7 +171,7 @@ template <typename T, storage::Ownership Ownership> class PackedVector
const detail::PackedVector<T, Ownership> &vec);
private:
typename util::ShM<std::uint64_t, Ownership>::vector vec;
util::ViewOrVector<std::uint64_t, Ownership> vec;
std::uint64_t num_elements = 0;
+3 -3
View File
@@ -4,7 +4,7 @@
#include "storage/io.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "util/integer_range.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include <array>
#include <fstream>
@@ -41,8 +41,8 @@ template <unsigned BLOCK_SIZE, storage::Ownership Ownership> class RangeTable
{
public:
using BlockT = std::array<unsigned char, BLOCK_SIZE>;
using BlockContainerT = typename ShM<BlockT, Ownership>::vector;
using OffsetContainerT = typename ShM<unsigned, Ownership>::vector;
using BlockContainerT = util::ViewOrVector<BlockT, Ownership>;
using OffsetContainerT = util::ViewOrVector<unsigned, Ownership>;
using RangeT = range<unsigned>;
friend std::ostream &operator<<<>(std::ostream &out, const RangeTable &table);
+10 -8
View File
@@ -4,7 +4,9 @@
#include "util/packed_vector.hpp"
#include "util/static_graph.hpp"
#include "util/dynamic_graph.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
namespace osrm
{
@@ -17,7 +19,7 @@ inline void read(storage::io::FileReader &reader,
detail::PackedVector<T, Ownership> &vec)
{
vec.num_elements =reader.ReadOne<std::uint64_t>();
reader.DeserializeVector(vec.vec);
storage::serialization::read(reader, vec.vec);
}
template <typename T, storage::Ownership Ownership>
@@ -25,30 +27,30 @@ inline void write(storage::io::FileWriter &writer,
const detail::PackedVector<T, Ownership> &vec)
{
writer.WriteOne(vec.num_elements);
writer.SerializeVector(vec.vec);
storage::serialization::write(writer, vec.vec);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
StaticGraph<EdgeDataT, Ownership> &graph)
{
reader.DeserializeVector(graph.node_array);
reader.DeserializeVector(graph.edge_array);
storage::serialization::read(reader, graph.node_array);
storage::serialization::read(reader, graph.edge_array);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const StaticGraph<EdgeDataT, Ownership> &graph)
{
writer.SerializeVector(graph.node_array);
writer.SerializeVector(graph.edge_array);
storage::serialization::write(writer, graph.node_array);
storage::serialization::write(writer, graph.edge_array);
}
template <typename EdgeDataT>
inline void read(storage::io::FileReader &reader,
DynamicGraph<EdgeDataT> &graph)
{
reader.DeserializeVector(graph.node_array);
storage::serialization::read(reader, graph.node_array);
auto num_edges = reader.ReadElementCount64();
graph.edge_list.resize(num_edges);
for (auto index : irange<std::size_t>(0, num_edges))
@@ -63,7 +65,7 @@ template <typename EdgeDataT>
inline void write(storage::io::FileWriter &writer,
const DynamicGraph<EdgeDataT> &graph)
{
writer.SerializeVector(graph.node_array);
storage::serialization::write(writer, graph.node_array);
writer.WriteElementCount64(graph.number_of_edges);
for (auto index : irange<std::size_t>(0, graph.number_of_edges))
{
+2 -2
View File
@@ -4,7 +4,7 @@
#include "util/graph_traits.hpp"
#include "util/integer_range.hpp"
#include "util/percent.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
#include "storage/shared_memory_ownership.hpp"
@@ -122,7 +122,7 @@ EntryT edgeToEntry(const OtherEdge &from, std::false_type)
template <typename EdgeDataT, storage::Ownership Ownership = storage::Ownership::Container>
class StaticGraph
{
template <typename T> using Vector = typename util::ShM<T, Ownership>::vector;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
public:
using InputEdge = static_graph_details::SortableEdgeWithData<EdgeDataT>;
+3 -3
View File
@@ -9,7 +9,7 @@
#include "util/hilbert_value.hpp"
#include "util/integer_range.hpp"
#include "util/rectangle.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
#include "util/web_mercator.hpp"
@@ -58,7 +58,7 @@ template <class EdgeDataT,
std::uint32_t LEAF_PAGE_SIZE = 4096>
class StaticRTree
{
template <typename T> using Vector = typename ShM<T, Ownership>::vector;
template <typename T> using Vector = ViewOrVector<T, Ownership>;
public:
using Rectangle = RectangleInt2D;
@@ -160,7 +160,7 @@ class StaticRTree
boost::iostreams::mapped_file_source m_leaves_region;
// read-only view of leaves
typename ShM<const LeafNode, storage::Ownership::View>::vector m_leaves;
util::vector_view<const LeafNode> m_leaves;
public:
StaticRTree(const StaticRTree &) = delete;
@@ -1,5 +1,5 @@
#ifndef SHARED_MEMORY_VECTOR_WRAPPER_HPP
#define SHARED_MEMORY_VECTOR_WRAPPER_HPP
#ifndef UTIL_VECTOR_VIEW_HPP
#define UTIL_VECTOR_VIEW_HPP
#include "util/exception.hpp"
#include "util/log.hpp"
@@ -25,11 +25,13 @@ namespace util
{
template <typename DataT>
class ShMemIterator
: public boost::iterator_facade<ShMemIterator<DataT>, DataT, boost::random_access_traversal_tag>
class VectorViewIterator : public boost::iterator_facade<VectorViewIterator<DataT>,
DataT,
boost::random_access_traversal_tag>
{
typedef boost::iterator_facade<ShMemIterator<DataT>, DataT, boost::random_access_traversal_tag>
base_t;
typedef boost::
iterator_facade<VectorViewIterator<DataT>, DataT, boost::random_access_traversal_tag>
base_t;
public:
typedef typename base_t::value_type value_type;
@@ -37,16 +39,16 @@ class ShMemIterator
typedef typename base_t::reference reference;
typedef std::random_access_iterator_tag iterator_category;
explicit ShMemIterator() : m_value(nullptr) {}
explicit ShMemIterator(DataT *x) : m_value(x) {}
explicit VectorViewIterator() : m_value(nullptr) {}
explicit VectorViewIterator(DataT *x) : m_value(x) {}
private:
void increment() { ++m_value; }
void decrement() { --m_value; }
void advance(difference_type offset) { m_value += offset; }
bool equal(const ShMemIterator &other) const { return m_value == other.m_value; }
bool equal(const VectorViewIterator &other) const { return m_value == other.m_value; }
reference dereference() const { return *m_value; }
difference_type distance_to(const ShMemIterator &other) const
difference_type distance_to(const VectorViewIterator &other) const
{
return other.m_value - m_value;
}
@@ -63,8 +65,8 @@ template <typename DataT> class vector_view
public:
using value_type = DataT;
using iterator = ShMemIterator<DataT>;
using const_iterator = ShMemIterator<const DataT>;
using iterator = VectorViewIterator<DataT>;
using const_iterator = VectorViewIterator<const DataT>;
using reverse_iterator = boost::reverse_iterator<iterator>;
vector_view() : m_ptr(nullptr), m_size(0) {}
@@ -88,7 +90,9 @@ template <typename DataT> class vector_view
{
if (m_size != size)
{
throw util::exception("Invalid resize " + std::to_string(size) + " on immutable vector view of size " + std::to_string(m_size) + ".");
throw util::exception("Invalid resize " + std::to_string(size) +
" on immutable vector view of size " + std::to_string(m_size) +
".");
}
}
@@ -189,12 +193,10 @@ template <typename DataT> void swap(vector_view<DataT> &lhs, vector_view<DataT>
std::swap(lhs.m_size, rhs.m_size);
}
template <typename DataT, storage::Ownership Ownership> struct ShM
{
using vector = typename std::conditional<Ownership == storage::Ownership::View,
vector_view<DataT>,
std::vector<DataT>>::type;
};
template <typename DataT, storage::Ownership Ownership>
using ViewOrVector = typename std::conditional<Ownership == storage::Ownership::View,
vector_view<DataT>,
std::vector<DataT>>::type;
}
}