Only use const-ref for coordinate vector

This commit is contained in:
Patrick Niklaus
2016-05-07 02:43:37 +02:00
parent f5aa5c0769
commit ddd128ce0e
6 changed files with 58 additions and 63 deletions
@@ -69,7 +69,7 @@ class InternalDataFacade final : public BaseDataFacade
std::unique_ptr<QueryGraph> m_query_graph;
std::string m_timestamp;
std::shared_ptr<util::ShM<util::Coordinate, false>::vector> m_coordinate_list;
util::ShM<util::Coordinate, false>::vector m_coordinate_list;
util::ShM<NodeID, false>::vector m_via_node_list;
util::ShM<unsigned, false>::vector m_name_ID_list;
util::ShM<extractor::guidance::TurnInstruction, false>::vector m_turn_instruction_list;
@@ -139,12 +139,12 @@ class InternalDataFacade final : public BaseDataFacade
extractor::QueryNode current_node;
unsigned number_of_coordinates = 0;
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned));
m_coordinate_list = std::make_shared<std::vector<util::Coordinate>>(number_of_coordinates);
m_coordinate_list.resize(number_of_coordinates);
for (unsigned i = 0; i < number_of_coordinates; ++i)
{
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode));
m_coordinate_list->at(i) = util::Coordinate(current_node.lon, current_node.lat);
BOOST_ASSERT(m_coordinate_list->at(i).IsValid());
m_coordinate_list[i] = util::Coordinate(current_node.lon, current_node.lat);
BOOST_ASSERT(m_coordinate_list[i].IsValid());
}
boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary);
@@ -253,7 +253,7 @@ class InternalDataFacade final : public BaseDataFacade
void LoadRTree()
{
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
BOOST_ASSERT_MSG(!m_coordinate_list.empty(), "coordinates must be loaded before r-tree");
m_static_rtree.reset(new InternalRTree(ram_index_path, file_index_path, m_coordinate_list));
m_geospatial_query.reset(
@@ -364,7 +364,7 @@ class InternalDataFacade final : public BaseDataFacade
// node and edge information access
util::Coordinate GetCoordinateOfNode(const unsigned id) const override final
{
return m_coordinate_list->at(id);
return m_coordinate_list[id];
}
extractor::guidance::TurnInstruction
@@ -72,7 +72,7 @@ class SharedDataFacade final : public BaseDataFacade
std::string m_timestamp;
extractor::ProfileProperties *m_profile_properties;
std::shared_ptr<util::ShM<util::Coordinate, true>::vector> m_coordinate_list;
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
util::ShM<NodeID, true>::vector m_via_node_list;
util::ShM<unsigned, true>::vector m_name_ID_list;
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
@@ -119,7 +119,7 @@ class SharedDataFacade final : public BaseDataFacade
void LoadRTree()
{
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
BOOST_ASSERT_MSG(!m_coordinate_list.empty(), "coordinates must be loaded before r-tree");
auto tree_ptr = data_layout->GetBlockPtr<RTreeNode>(
shared_memory, storage::SharedDataLayout::R_SEARCH_TREE);
@@ -149,8 +149,7 @@ class SharedDataFacade final : public BaseDataFacade
{
auto coordinate_list_ptr = data_layout->GetBlockPtr<util::Coordinate>(
shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
m_coordinate_list = util::make_unique<util::ShM<util::Coordinate, true>::vector>(
coordinate_list_ptr,
m_coordinate_list.reset(coordinate_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
auto travel_mode_list_ptr = data_layout->GetBlockPtr<extractor::TravelMode>(
@@ -353,13 +352,10 @@ class SharedDataFacade final : public BaseDataFacade
LoadRTree();
util::SimpleLogger().Write() << "number of geometries: "
<< m_coordinate_list->size();
for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
<< m_coordinate_list.size();
for (unsigned i = 0; i < m_coordinate_list.size(); ++i)
{
if (!GetCoordinateOfNode(i).IsValid())
{
util::SimpleLogger().Write() << "coordinate " << i << " not valid";
}
BOOST_ASSERT(GetCoordinateOfNode(i).IsValid());
}
}
util::SimpleLogger().Write(logDEBUG) << "Releasing exclusive lock";
@@ -412,7 +408,7 @@ class SharedDataFacade final : public BaseDataFacade
// node and edge information access
util::Coordinate GetCoordinateOfNode(const NodeID id) const override final
{
return m_coordinate_list->at(id);
return m_coordinate_list[id];
}
virtual void GetUncompressedGeometry(const EdgeID id,
+6 -6
View File
@@ -22,7 +22,7 @@ namespace engine
// Implements complex queries on top of an RTree and builds PhantomNodes from it.
//
// Only holds a weak reference on the RTree!
// Only holds a weak reference on the RTree and coordinates!
template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
{
using EdgeData = typename RTreeT::EdgeData;
@@ -31,9 +31,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
public:
GeospatialQuery(RTreeT &rtree_,
std::shared_ptr<CoordinateList> coordinates_,
const CoordinateList &coordinates_,
DataFacadeT &datafacade_)
: rtree(rtree_), coordinates(std::move(coordinates_)), datafacade(datafacade_)
: rtree(rtree_), coordinates(coordinates_), datafacade(datafacade_)
{
}
@@ -360,7 +360,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
double ratio;
const auto current_perpendicular_distance =
util::coordinate_calculation::perpendicularDistance(
coordinates->at(data.u), coordinates->at(data.v), input_coordinate,
coordinates[data.u], coordinates[data.v], input_coordinate,
point_on_segment, ratio);
// Find the node-based-edge that this belongs to, and directly
@@ -442,7 +442,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
!segment.data.reverse_segment_id.enabled);
const double forward_edge_bearing = util::coordinate_calculation::bearing(
coordinates->at(segment.data.u), coordinates->at(segment.data.v));
coordinates[segment.data.u], coordinates[segment.data.v]);
const double backward_edge_bearing = (forward_edge_bearing + 180) > 360
? (forward_edge_bearing - 180)
@@ -460,7 +460,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
}
RTreeT &rtree;
const std::shared_ptr<CoordinateList> coordinates;
const CoordinateList &coordinates;
DataFacadeT &datafacade;
};
}
+21 -21
View File
@@ -116,7 +116,7 @@ class StaticRTree
};
typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
std::shared_ptr<CoordinateListT> m_coordinate_list;
const CoordinateListT& m_coordinate_list;
boost::iostreams::mapped_file_source m_leaves_region;
// read-only view of leaves
@@ -132,6 +132,7 @@ class StaticRTree
const std::string &tree_node_filename,
const std::string &leaf_node_filename,
const std::vector<CoordinateT> &coordinate_list)
: m_coordinate_list(coordinate_list)
{
const uint64_t element_count = input_data_vector.size();
std::vector<WrappedInputElement> input_wrapper_vector(element_count);
@@ -140,7 +141,7 @@ class StaticRTree
tbb::parallel_for(
tbb::blocked_range<uint64_t>(0, element_count),
[&input_data_vector, &input_wrapper_vector,
&coordinate_list](const tbb::blocked_range<uint64_t> &range)
this](const tbb::blocked_range<uint64_t> &range)
{
for (uint64_t element_counter = range.begin(), end = range.end();
element_counter != end; ++element_counter)
@@ -151,11 +152,11 @@ class StaticRTree
EdgeDataT const &current_element = input_data_vector[element_counter];
// Get Hilbert-Value for centroid in mercartor projection
BOOST_ASSERT(current_element.u < coordinate_list.size());
BOOST_ASSERT(current_element.v < coordinate_list.size());
BOOST_ASSERT(current_element.u < m_coordinate_list.size());
BOOST_ASSERT(current_element.v < m_coordinate_list.size());
Coordinate current_centroid = coordinate_calculation::centroid(
coordinate_list[current_element.u], coordinate_list[current_element.v]);
m_coordinate_list[current_element.u], m_coordinate_list[current_element.v]);
current_centroid.lat =
FixedLatitude(COORDINATE_PRECISION *
web_mercator::latToY(toFloating(current_centroid.lat)));
@@ -194,7 +195,7 @@ class StaticRTree
// generate tree node that resemble the objects in leaf and store it for next level
InitializeMBRectangle(current_node.minimum_bounding_rectangle, current_leaf.objects,
current_leaf.object_count, coordinate_list);
current_leaf.object_count, m_coordinate_list);
current_node.child_is_on_disk = true;
current_node.children[0] = tree_nodes_in_level.size();
tree_nodes_in_level.emplace_back(current_node);
@@ -275,11 +276,10 @@ class StaticRTree
explicit StaticRTree(const boost::filesystem::path &node_file,
const boost::filesystem::path &leaf_file,
const std::shared_ptr<CoordinateListT> coordinate_list)
const CoordinateListT& coordinate_list)
: m_coordinate_list(coordinate_list)
{
// open tree node file and load into RAM.
m_coordinate_list = coordinate_list;
if (!boost::filesystem::exists(node_file))
{
throw exception("ram index file does not exist");
@@ -305,9 +305,9 @@ class StaticRTree
explicit StaticRTree(TreeNode *tree_node_ptr,
const uint64_t number_of_nodes,
const boost::filesystem::path &leaf_file,
std::shared_ptr<CoordinateListT> coordinate_list)
const CoordinateListT& coordinate_list)
: m_search_tree(tree_node_ptr, number_of_nodes)
, m_coordinate_list(std::move(coordinate_list))
, m_coordinate_list(coordinate_list)
{
MapLeafNodesFile(leaf_file);
}
@@ -355,14 +355,14 @@ class StaticRTree
// we don't need to project the coordinates here,
// because we use the unprojected rectangle to test against
const Rectangle bbox{std::min((*m_coordinate_list)[current_edge.u].lon,
(*m_coordinate_list)[current_edge.v].lon),
std::max((*m_coordinate_list)[current_edge.u].lon,
(*m_coordinate_list)[current_edge.v].lon),
std::min((*m_coordinate_list)[current_edge.u].lat,
(*m_coordinate_list)[current_edge.v].lat),
std::max((*m_coordinate_list)[current_edge.u].lat,
(*m_coordinate_list)[current_edge.v].lat)};
const Rectangle bbox{std::min(m_coordinate_list[current_edge.u].lon,
m_coordinate_list[current_edge.v].lon),
std::max(m_coordinate_list[current_edge.u].lon,
m_coordinate_list[current_edge.v].lon),
std::min(m_coordinate_list[current_edge.u].lat,
m_coordinate_list[current_edge.v].lat),
std::max(m_coordinate_list[current_edge.u].lat,
m_coordinate_list[current_edge.v].lat)};
// use the _unprojected_ input rectangle here
if (bbox.Intersects(search_rectangle))
@@ -481,8 +481,8 @@ class StaticRTree
for (const auto i : irange(0u, current_leaf_node.object_count))
{
const auto &current_edge = current_leaf_node.objects[i];
const auto projected_u = web_mercator::fromWGS84((*m_coordinate_list)[current_edge.u]);
const auto projected_v = web_mercator::fromWGS84((*m_coordinate_list)[current_edge.v]);
const auto projected_u = web_mercator::fromWGS84(m_coordinate_list[current_edge.u]);
const auto projected_v = web_mercator::fromWGS84(m_coordinate_list[current_edge.v]);
FloatCoordinate projected_nearest;
std::tie(std::ignore, projected_nearest) =