Switch code to use packed vector for segment weights/durations
This commit is contained in:
committed by
Patrick Niklaus
parent
5c61f00ffa
commit
3599d1db8e
@@ -434,35 +434,47 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
||||
util::vector_view<unsigned> geometry_begin_indices(
|
||||
geometries_index_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_INDEX]);
|
||||
|
||||
auto num_entries = data_layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST];
|
||||
|
||||
auto geometries_node_list_ptr = data_layout.GetBlockPtr<NodeID>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_NODE_LIST);
|
||||
util::vector_view<NodeID> geometry_node_list(
|
||||
geometries_node_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST]);
|
||||
util::vector_view<NodeID> geometry_node_list(geometries_node_list_ptr, num_entries);
|
||||
|
||||
auto geometries_fwd_weight_list_ptr = data_layout.GetBlockPtr<SegmentWeight>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST);
|
||||
util::vector_view<SegmentWeight> geometry_fwd_weight_list(
|
||||
geometries_fwd_weight_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]);
|
||||
auto geometries_fwd_weight_list_ptr =
|
||||
data_layout.GetBlockPtr<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST);
|
||||
extractor::SegmentDataView::SegmentWeightVector geometry_fwd_weight_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
geometries_fwd_weight_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto geometries_rev_weight_list_ptr = data_layout.GetBlockPtr<SegmentWeight>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST);
|
||||
util::vector_view<SegmentWeight> geometry_rev_weight_list(
|
||||
geometries_rev_weight_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]);
|
||||
auto geometries_rev_weight_list_ptr =
|
||||
data_layout.GetBlockPtr<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST);
|
||||
extractor::SegmentDataView::SegmentWeightVector geometry_rev_weight_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentWeightVector::block_type>(
|
||||
geometries_rev_weight_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto geometries_fwd_duration_list_ptr = data_layout.GetBlockPtr<SegmentDuration>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST);
|
||||
util::vector_view<SegmentDuration> geometry_fwd_duration_list(
|
||||
geometries_fwd_duration_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]);
|
||||
auto geometries_fwd_duration_list_ptr =
|
||||
data_layout.GetBlockPtr<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST);
|
||||
extractor::SegmentDataView::SegmentDurationVector geometry_fwd_duration_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
geometries_fwd_duration_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto geometries_rev_duration_list_ptr = data_layout.GetBlockPtr<SegmentDuration>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST);
|
||||
util::vector_view<SegmentDuration> geometry_rev_duration_list(
|
||||
geometries_rev_duration_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]);
|
||||
auto geometries_rev_duration_list_ptr =
|
||||
data_layout.GetBlockPtr<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
memory_block, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST);
|
||||
extractor::SegmentDataView::SegmentDurationVector geometry_rev_duration_list(
|
||||
util::vector_view<extractor::SegmentDataView::SegmentDurationVector::block_type>(
|
||||
geometries_rev_duration_list_ptr,
|
||||
data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]),
|
||||
num_entries);
|
||||
|
||||
auto datasources_list_ptr = data_layout.GetBlockPtr<DatasourceID>(
|
||||
memory_block, storage::DataLayout::DATASOURCES_LIST);
|
||||
|
||||
@@ -425,7 +425,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
|
||||
// check phantom node segments validity
|
||||
auto areSegmentsValid = [](auto first, auto last) -> bool {
|
||||
return std::find(first, last, INVALID_EDGE_WEIGHT) == last;
|
||||
return std::find(first, last, INVALID_SEGMENT_WEIGHT) == last;
|
||||
};
|
||||
bool is_forward_valid_source =
|
||||
areSegmentsValid(forward_weight_vector.begin(), forward_weight_vector.end());
|
||||
@@ -503,7 +503,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
|
||||
/**
|
||||
* Checks to see if the edge weights are valid. We might have an edge,
|
||||
* but a traffic update might set the speed to 0 (weight == INVALID_EDGE_WEIGHT).
|
||||
* but a traffic update might set the speed to 0 (weight == INVALID_SEGMENT_WEIGHT).
|
||||
* which means that this edge is not currently traversible. If this is the case,
|
||||
* then we shouldn't snap to this edge.
|
||||
*/
|
||||
@@ -521,7 +521,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
const std::vector<EdgeWeight> forward_weight_vector =
|
||||
datafacade.GetUncompressedForwardWeights(geometry_id);
|
||||
|
||||
if (forward_weight_vector[data.fwd_segment_position] != INVALID_EDGE_WEIGHT)
|
||||
if (forward_weight_vector[data.fwd_segment_position] != INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
forward_edge_valid = data.forward_segment_id.enabled;
|
||||
}
|
||||
@@ -529,7 +529,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
const std::vector<EdgeWeight> reverse_weight_vector =
|
||||
datafacade.GetUncompressedReverseWeights(geometry_id);
|
||||
if (reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1] !=
|
||||
INVALID_EDGE_WEIGHT)
|
||||
INVALID_SEGMENT_WEIGHT)
|
||||
{
|
||||
reverse_edge_valid = data.reverse_segment_id.enabled;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,12 @@ class CompressedEdgeContainer
|
||||
std::unique_ptr<SegmentDataContainer> ToSegmentData();
|
||||
|
||||
private:
|
||||
SegmentWeight ClipWeight(const SegmentWeight weight);
|
||||
SegmentDuration ClipDuration(const SegmentDuration duration);
|
||||
|
||||
int free_list_maximum = 0;
|
||||
std::atomic_size_t clipped_weights;
|
||||
std::atomic_size_t clipped_durations;
|
||||
std::atomic_size_t clipped_weights{0};
|
||||
std::atomic_size_t clipped_durations{0};
|
||||
|
||||
void IncreaseFreeList();
|
||||
std::vector<OnewayEdgeBucket> m_compressed_oneway_geometries;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
|
||||
#define OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
|
||||
|
||||
#include "util/packed_vector.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
#include "util/vector_view.hpp"
|
||||
|
||||
@@ -43,6 +44,8 @@ namespace detail
|
||||
template <storage::Ownership Ownership> class SegmentDataContainerImpl
|
||||
{
|
||||
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
|
||||
template <typename T, std::size_t Bits>
|
||||
using PackedVector = util::detail::PackedVector<T, Bits, Ownership>;
|
||||
|
||||
friend CompressedEdgeContainer;
|
||||
|
||||
@@ -50,15 +53,17 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
|
||||
// FIXME We should change the indexing to Edge-Based-Node id
|
||||
using DirectionalGeometryID = std::uint32_t;
|
||||
using SegmentOffset = std::uint32_t;
|
||||
using SegmentWeightVector = PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS>;
|
||||
using SegmentDurationVector = PackedVector<SegmentDuration, SEGMENT_DURAITON_BITS>;
|
||||
|
||||
SegmentDataContainerImpl() = default;
|
||||
|
||||
SegmentDataContainerImpl(Vector<std::uint32_t> index_,
|
||||
Vector<NodeID> nodes_,
|
||||
Vector<SegmentWeight> fwd_weights_,
|
||||
Vector<SegmentWeight> rev_weights_,
|
||||
Vector<SegmentDuration> fwd_durations_,
|
||||
Vector<SegmentDuration> rev_durations_,
|
||||
SegmentWeightVector fwd_weights_,
|
||||
SegmentWeightVector rev_weights_,
|
||||
SegmentDurationVector fwd_durations_,
|
||||
SegmentDurationVector 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_)),
|
||||
@@ -201,10 +206,10 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
|
||||
private:
|
||||
Vector<std::uint32_t> index;
|
||||
Vector<NodeID> nodes;
|
||||
Vector<SegmentWeight> fwd_weights;
|
||||
Vector<SegmentWeight> rev_weights;
|
||||
Vector<SegmentDuration> fwd_durations;
|
||||
Vector<SegmentDuration> rev_durations;
|
||||
SegmentWeightVector fwd_weights;
|
||||
SegmentWeightVector rev_weights;
|
||||
SegmentDurationVector fwd_durations;
|
||||
SegmentDurationVector rev_durations;
|
||||
Vector<DatasourceID> datasources;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ inline void read(storage::io::FileReader &reader,
|
||||
{
|
||||
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);
|
||||
util::serialization::read(reader, segment_data.fwd_weights);
|
||||
util::serialization::read(reader, segment_data.rev_weights);
|
||||
util::serialization::read(reader, segment_data.fwd_durations);
|
||||
util::serialization::read(reader, segment_data.rev_durations);
|
||||
storage::serialization::read(reader, segment_data.datasources);
|
||||
}
|
||||
|
||||
@@ -51,10 +51,10 @@ inline void write(storage::io::FileWriter &writer,
|
||||
{
|
||||
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);
|
||||
util::serialization::write(writer, segment_data.fwd_weights);
|
||||
util::serialization::write(writer, segment_data.rev_weights);
|
||||
util::serialization::write(writer, segment_data.fwd_durations);
|
||||
util::serialization::write(writer, segment_data.rev_durations);
|
||||
storage::serialization::write(writer, segment_data.datasources);
|
||||
}
|
||||
|
||||
|
||||
@@ -411,6 +411,8 @@ template <typename T, std::size_t Bits, storage::Ownership Ownership> class Pack
|
||||
|
||||
void push_back(const T value)
|
||||
{
|
||||
BOOST_ASSERT_MSG(value <= T{(1ULL << Bits) - 1}, "Value too big for packed storage.");
|
||||
|
||||
auto internal_index = get_internal_index(num_elements);
|
||||
|
||||
while (internal_index.lower_word + 1 >= vec.size())
|
||||
|
||||
@@ -96,8 +96,12 @@ static const EdgeID SPECIAL_EDGEID = std::numeric_limits<EdgeID>::max();
|
||||
static const NameID INVALID_NAMEID = std::numeric_limits<NameID>::max();
|
||||
static const NameID EMPTY_NAMEID = 0;
|
||||
static const unsigned INVALID_COMPONENTID = 0;
|
||||
static const SegmentWeight INVALID_SEGMENT_WEIGHT = (1u << 20) - 1;
|
||||
static const SegmentDuration INVALID_SEGMENT_DURATION = (1u << 20) - 1;
|
||||
static const std::size_t SEGMENT_WEIGHT_BITS = 22;
|
||||
static const std::size_t SEGMENT_DURAITON_BITS = 22;
|
||||
static const SegmentWeight INVALID_SEGMENT_WEIGHT = (1u << SEGMENT_WEIGHT_BITS) - 1;
|
||||
static const SegmentDuration INVALID_SEGMENT_DURATION = (1u << SEGMENT_DURAITON_BITS) - 1;
|
||||
static const SegmentWeight MAX_SEGMENT_WEIGHT = INVALID_SEGMENT_WEIGHT - 1;
|
||||
static const SegmentDuration MAX_SEGMENT_DURATION = INVALID_SEGMENT_DURATION - 1;
|
||||
static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max();
|
||||
static const EdgeDuration MAXIMAL_EDGE_DURATION = std::numeric_limits<EdgeDuration>::max();
|
||||
static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>::max();
|
||||
|
||||
Reference in New Issue
Block a user