Refactor compressed geometry in own abstraction with read/write
This commit is contained in:
committed by
Patrick Niklaus
parent
83820bf82c
commit
1b5ab37dfd
@@ -1,6 +1,8 @@
|
||||
#ifndef GEOMETRY_COMPRESSOR_HPP_
|
||||
#define GEOMETRY_COMPRESSOR_HPP_
|
||||
|
||||
#include "extractor/segment_data_container.hpp"
|
||||
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -48,7 +50,6 @@ class CompressedEdgeContainer
|
||||
bool HasZippedEntryForForwardID(const EdgeID edge_id) const;
|
||||
bool HasZippedEntryForReverseID(const EdgeID edge_id) const;
|
||||
void PrintStatistics() const;
|
||||
void SerializeInternalVector(const std::string &path) const;
|
||||
unsigned GetPositionForID(const EdgeID edge_id) const;
|
||||
unsigned GetZippedPositionForForwardID(const EdgeID edge_id) const;
|
||||
unsigned GetZippedPositionForReverseID(const EdgeID edge_id) const;
|
||||
@@ -58,21 +59,19 @@ class CompressedEdgeContainer
|
||||
NodeID GetLastEdgeTargetID(const EdgeID edge_id) const;
|
||||
NodeID GetLastEdgeSourceID(const EdgeID edge_id) const;
|
||||
|
||||
// Invalidates the internal storage
|
||||
SegmentDataContainer ToSegmentData();
|
||||
|
||||
private:
|
||||
int free_list_maximum = 0;
|
||||
|
||||
void IncreaseFreeList();
|
||||
std::vector<OnewayEdgeBucket> m_compressed_oneway_geometries;
|
||||
std::vector<unsigned> m_compressed_geometry_index;
|
||||
std::vector<NodeID> m_compressed_geometry_nodes;
|
||||
std::vector<EdgeWeight> m_compressed_geometry_fwd_weights;
|
||||
std::vector<EdgeWeight> m_compressed_geometry_rev_weights;
|
||||
std::vector<EdgeWeight> m_compressed_geometry_fwd_durations;
|
||||
std::vector<EdgeWeight> m_compressed_geometry_rev_durations;
|
||||
std::vector<unsigned> m_free_list;
|
||||
std::unordered_map<EdgeID, unsigned> m_edge_id_to_list_index_map;
|
||||
std::unordered_map<EdgeID, unsigned> m_forward_edge_id_to_zipped_index_map;
|
||||
std::unordered_map<EdgeID, unsigned> m_reverse_edge_id_to_zipped_index_map;
|
||||
SegmentDataContainer segment_data;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef OSRM_EXTRACTOR_IO_HPP
|
||||
#define OSRM_EXTRACTOR_IO_HPP
|
||||
|
||||
#include "extractor/segment_data_container.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
|
||||
template <>
|
||||
void read(const boost::filesystem::path &path, SegmentDataContainer &segment_data)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
|
||||
storage::io::FileReader reader{path, fingerprint};
|
||||
|
||||
auto num_indices = reader.ReadElementCount32();
|
||||
segment_data.index.resize(num_indices);
|
||||
reader.ReadInto(segment_data.index.data(), num_indices);
|
||||
|
||||
auto num_entries = reader.ReadElementCount32();
|
||||
segment_data.nodes.resize(num_entries);
|
||||
segment_data.fwd_weights.resize(num_entries);
|
||||
segment_data.rev_weights.resize(num_entries);
|
||||
segment_data.fwd_durations.resize(num_entries);
|
||||
segment_data.rev_durations.resize(num_entries);
|
||||
|
||||
reader.ReadInto(segment_data.nodes.data(), segment_data.nodes.size());
|
||||
reader.ReadInto(segment_data.fwd_weights.data(), segment_data.fwd_weights.size());
|
||||
reader.ReadInto(segment_data.rev_weights.data(), segment_data.rev_weights.size());
|
||||
reader.ReadInto(segment_data.fwd_durations.data(), segment_data.fwd_durations.size());
|
||||
reader.ReadInto(segment_data.rev_durations.data(), segment_data.rev_durations.size());
|
||||
}
|
||||
|
||||
template <> void write(const boost::filesystem::path &path, const SegmentDataContainer &segment_data)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
|
||||
storage::io::FileWriter writer{path, fingerprint};
|
||||
|
||||
// FIXME this _should_ just be size and the senitel below need to be removed
|
||||
writer.WriteElementCount32(segment_data.index.size() + 1);
|
||||
writer.WriteFrom(segment_data.index.data(), segment_data.index.size());
|
||||
// FIMXE remove unnecessary senitel
|
||||
writer.WriteElementCount32(segment_data.nodes.size());
|
||||
|
||||
writer.WriteElementCount32(segment_data.nodes.size());
|
||||
writer.WriteFrom(segment_data.nodes.data(), segment_data.nodes.size());
|
||||
writer.WriteFrom(segment_data.fwd_weights.data(), segment_data.fwd_weights.size());
|
||||
writer.WriteFrom(segment_data.rev_weights.data(), segment_data.rev_weights.size());
|
||||
writer.WriteFrom(segment_data.fwd_durations.data(), segment_data.fwd_durations.size());
|
||||
writer.WriteFrom(segment_data.rev_durations.data(), segment_data.rev_durations.size());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
#ifndef OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
|
||||
#define OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
|
||||
|
||||
#include "util/shared_memory_vector_wrapper.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
class CompressedEdgeContainer;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool UseShareMemory> class SegmentDataContainerImpl;
|
||||
}
|
||||
|
||||
namespace io
|
||||
{
|
||||
template <bool UseShareMemory>
|
||||
inline void read(const boost::filesystem::path &path, detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
|
||||
template <bool UseShareMemory>
|
||||
inline void write(const boost::filesystem::path &path, const detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <bool UseShareMemory> class SegmentDataContainerImpl
|
||||
{
|
||||
template <typename T> using Vector = typename util::ShM<T, UseShareMemory>::vector;
|
||||
|
||||
friend CompressedEdgeContainer;
|
||||
|
||||
public:
|
||||
using SegmentID = std::uint32_t;
|
||||
|
||||
SegmentDataContainerImpl() = default;
|
||||
|
||||
SegmentDataContainerImpl(Vector<std::uint32_t> index_,
|
||||
Vector<NodeID> nodes_,
|
||||
Vector<EdgeWeight> fwd_weights_,
|
||||
Vector<EdgeWeight> rev_weights_,
|
||||
Vector<EdgeWeight> fwd_durations_,
|
||||
Vector<EdgeWeight> rev_durations_)
|
||||
: index(std::move(index_)), nodes(std::move(nodes_)), fwd_weights(std::move(fwd_weights_)),
|
||||
rev_weights(std::move(rev_weights_)), fwd_durations(std::move(fwd_durations_)),
|
||||
rev_durations(std::move(rev_durations_))
|
||||
{
|
||||
}
|
||||
|
||||
auto GetForwardGeometry(const SegmentID id) const
|
||||
{
|
||||
const auto begin = nodes.begin() + index.at(id);
|
||||
const auto end = nodes.begin() + index.at(id + 1);
|
||||
|
||||
return boost::make_iterator_range(begin, end);
|
||||
}
|
||||
|
||||
auto GetReverseGeometry(const SegmentID id) const
|
||||
{
|
||||
return boost::adaptors::reverse(GetForwardGeometry(id));
|
||||
}
|
||||
|
||||
auto GetForwardDurations(const SegmentID id) const
|
||||
{
|
||||
const auto begin = fwd_durations.begin() + index.at(id) + 1;
|
||||
const auto end = fwd_durations.begin() + index.at(id + 1);
|
||||
|
||||
return boost::make_iterator_range(begin, end);
|
||||
}
|
||||
|
||||
auto GetReverseDurations(const SegmentID id) const
|
||||
{
|
||||
const auto begin = rev_durations.begin() + index.at(id);
|
||||
const auto end = rev_durations.begin() + index.at(id + 1) - 1;
|
||||
|
||||
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
|
||||
}
|
||||
|
||||
auto GetForwardWeights(const SegmentID id) const
|
||||
{
|
||||
const auto begin = fwd_weights.begin() + index.at(id) + 1;
|
||||
const auto end = fwd_weights.begin() + index.at(id + 1);
|
||||
|
||||
return boost::make_iterator_range(begin, end);
|
||||
}
|
||||
|
||||
auto GetReverseWeights(const SegmentID id) const
|
||||
{
|
||||
const auto begin = rev_weights.begin() + index.at(id);
|
||||
const auto end = rev_weights.begin() + index.at(id + 1) - 1;
|
||||
|
||||
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
|
||||
}
|
||||
|
||||
friend void io::read<UseShareMemory>(const boost::filesystem::path &path,
|
||||
detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
|
||||
friend void io::write<UseShareMemory>(const boost::filesystem::path &path,
|
||||
const detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
|
||||
|
||||
private:
|
||||
Vector<std::uint32_t> index;
|
||||
Vector<NodeID> nodes;
|
||||
Vector<EdgeWeight> fwd_weights;
|
||||
Vector<EdgeWeight> rev_weights;
|
||||
Vector<EdgeWeight> fwd_durations;
|
||||
Vector<EdgeWeight> rev_durations;
|
||||
};
|
||||
}
|
||||
|
||||
using SegmentDataView = detail::SegmentDataContainerImpl<true>;
|
||||
using SegmentDataContainer = detail::SegmentDataContainerImpl<false>;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user