Include datasources in .geometries file and refactor .datasource_names
This commit is contained in:
committed by
Patrick Niklaus
parent
ffd6311e7d
commit
a636e8cc13
@@ -0,0 +1,48 @@
|
||||
#ifndef OSRM_EXTRACT_DATASOURCES_HPP
|
||||
#define OSRM_EXTRACT_DATASOURCES_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <util/string_view.hpp>
|
||||
#include <util/typedefs.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
class Datasources
|
||||
{
|
||||
static constexpr const std::uint8_t MAX_NUM_SOURES = 255;
|
||||
static constexpr const std::uint8_t MAX_LENGTH_NAME = 255;
|
||||
|
||||
public:
|
||||
Datasources()
|
||||
{
|
||||
std::fill(lengths.begin(), lengths.end(), 0);
|
||||
std::fill(sources.begin(), sources.end(), '\0');
|
||||
}
|
||||
|
||||
util::StringView GetSourceName(DatasourceID id) const
|
||||
{
|
||||
auto begin = sources.data() + (MAX_LENGTH_NAME * id);
|
||||
|
||||
return util::StringView{begin, lengths[id]};
|
||||
}
|
||||
|
||||
void SetSourceName(DatasourceID id, const std::string &name)
|
||||
{
|
||||
BOOST_ASSERT(name.size() < MAX_LENGTH_NAME);
|
||||
lengths[id] = std::min<std::uint32_t>(name.size(), MAX_LENGTH_NAME);
|
||||
|
||||
auto out = sources.data() + (MAX_LENGTH_NAME * id);
|
||||
std::copy(name.begin(), name.begin() + lengths[id], out);
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<std::uint32_t, MAX_NUM_SOURES> lengths;
|
||||
std::array<char, MAX_LENGTH_NAME * MAX_NUM_SOURES> sources;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,10 +1,13 @@
|
||||
#ifndef OSRM_EXTRACTOR_IO_HPP
|
||||
#define OSRM_EXTRACTOR_IO_HPP
|
||||
|
||||
#include "extractor/datasources.hpp"
|
||||
#include "extractor/segment_data_container.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
@@ -12,6 +15,22 @@ namespace extractor
|
||||
namespace io
|
||||
{
|
||||
|
||||
void read(const boost::filesystem::path &path, Datasources &sources)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
|
||||
storage::io::FileReader reader{path, fingerprint};
|
||||
|
||||
reader.ReadInto(sources);
|
||||
}
|
||||
|
||||
void write(const boost::filesystem::path &path, Datasources &sources)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
|
||||
storage::io::FileWriter writer{path, fingerprint};
|
||||
|
||||
writer.WriteFrom(sources);
|
||||
}
|
||||
|
||||
template <> void read(const boost::filesystem::path &path, SegmentDataContainer &segment_data)
|
||||
{
|
||||
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
|
||||
@@ -27,12 +46,14 @@ template <> void read(const boost::filesystem::path &path, SegmentDataContainer
|
||||
segment_data.rev_weights.resize(num_entries);
|
||||
segment_data.fwd_durations.resize(num_entries);
|
||||
segment_data.rev_durations.resize(num_entries);
|
||||
segment_data.datasources.resize(num_entries);
|
||||
|
||||
reader.ReadInto(segment_data.nodes);
|
||||
reader.ReadInto(segment_data.fwd_weights);
|
||||
reader.ReadInto(segment_data.rev_weights);
|
||||
reader.ReadInto(segment_data.fwd_durations);
|
||||
reader.ReadInto(segment_data.rev_durations);
|
||||
reader.ReadInto(segment_data.datasources);
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -45,11 +66,17 @@ void write(const boost::filesystem::path &path, const SegmentDataContainer &segm
|
||||
writer.WriteFrom(segment_data.index);
|
||||
|
||||
writer.WriteElementCount32(segment_data.nodes.size());
|
||||
BOOST_ASSERT(segment_data.fwd_weights.size() == segment_data.nodes.size());
|
||||
BOOST_ASSERT(segment_data.rev_weights.size() == segment_data.nodes.size());
|
||||
BOOST_ASSERT(segment_data.fwd_durations.size() == segment_data.nodes.size());
|
||||
BOOST_ASSERT(segment_data.rev_durations.size() == segment_data.nodes.size());
|
||||
BOOST_ASSERT(segment_data.datasources.size() == segment_data.nodes.size());
|
||||
writer.WriteFrom(segment_data.nodes);
|
||||
writer.WriteFrom(segment_data.fwd_weights);
|
||||
writer.WriteFrom(segment_data.rev_weights);
|
||||
writer.WriteFrom(segment_data.fwd_durations);
|
||||
writer.WriteFrom(segment_data.rev_durations);
|
||||
writer.WriteFrom(segment_data.datasources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +55,11 @@ template <bool UseShareMemory> class SegmentDataContainerImpl
|
||||
Vector<EdgeWeight> fwd_weights_,
|
||||
Vector<EdgeWeight> rev_weights_,
|
||||
Vector<EdgeWeight> fwd_durations_,
|
||||
Vector<EdgeWeight> rev_durations_)
|
||||
Vector<EdgeWeight> rev_durations_,
|
||||
Vector<DatasourceID> datasources_)
|
||||
: 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_))
|
||||
rev_durations(std::move(rev_durations_)), datasources(std::move(datasources_))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,11 +80,13 @@ template <bool UseShareMemory> class SegmentDataContainerImpl
|
||||
{
|
||||
return rev_weights[index[id] + offset];
|
||||
}
|
||||
// TODO we only need this for the datasource file since it breaks this
|
||||
// abstraction, but uses this index
|
||||
auto GetOffset(const DirectionalGeometryID id, const SegmentOffset offset) const
|
||||
auto &ForwardDatasource(const DirectionalGeometryID id, const SegmentOffset offset)
|
||||
{
|
||||
return index[id] + offset;
|
||||
return datasources[index[id] + 1 + offset];
|
||||
}
|
||||
auto &ReverseDatasource(const DirectionalGeometryID id, const SegmentOffset offset)
|
||||
{
|
||||
return datasources[index[id] + offset];
|
||||
}
|
||||
|
||||
auto GetForwardGeometry(const DirectionalGeometryID id) const
|
||||
@@ -131,6 +134,22 @@ template <bool UseShareMemory> class SegmentDataContainerImpl
|
||||
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
|
||||
}
|
||||
|
||||
auto GetForwardDatasources(const DirectionalGeometryID id) const
|
||||
{
|
||||
const auto begin = datasources.cbegin() + index.at(id) + 1;
|
||||
const auto end = datasources.cbegin() + index.at(id + 1);
|
||||
|
||||
return boost::make_iterator_range(begin, end);
|
||||
}
|
||||
|
||||
auto GetReverseDatasources(const DirectionalGeometryID id) const
|
||||
{
|
||||
const auto begin = datasources.cbegin() + index.at(id);
|
||||
const auto end = datasources.cbegin() + index.at(id + 1) - 1;
|
||||
|
||||
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
|
||||
}
|
||||
|
||||
auto GetNumberOfSegments() const { return fwd_weights.size(); }
|
||||
|
||||
friend void
|
||||
@@ -147,6 +166,7 @@ template <bool UseShareMemory> class SegmentDataContainerImpl
|
||||
Vector<EdgeWeight> rev_weights;
|
||||
Vector<EdgeWeight> fwd_durations;
|
||||
Vector<EdgeWeight> rev_durations;
|
||||
Vector<DatasourceID> datasources;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user