Split QueryNode into coordinates and osm id

This commit is contained in:
Patrick Niklaus
2017-04-02 23:58:06 +00:00
committed by Patrick Niklaus
parent 786a3d8919
commit 7f6e0c478b
38 changed files with 236 additions and 248 deletions
+8 -5
View File
@@ -10,6 +10,7 @@
#include "util/fingerprint.hpp"
#include "util/log.hpp"
#include "util/typedefs.hpp"
#include "util/packed_vector.hpp"
#include <boost/assert.hpp>
#include <boost/filesystem.hpp>
@@ -57,21 +58,23 @@ template <typename BarrierOutIter, typename TrafficSignalsOutIter>
NodeID loadNodesFromFile(storage::io::FileReader &file_reader,
BarrierOutIter barriers,
TrafficSignalsOutIter traffic_signals,
std::vector<extractor::QueryNode> &node_array)
std::vector<util::Coordinate> &coordinates,
util::PackedVector<OSMNodeID> &osm_node_ids)
{
NodeID number_of_nodes = file_reader.ReadElementCount32();
Log() << "Importing number_of_nodes new = " << number_of_nodes << " nodes ";
node_array.resize(number_of_nodes);
coordinates.resize(number_of_nodes);
osm_node_ids.reserve(number_of_nodes);
extractor::ExternalMemoryNode current_node;
for (NodeID i = 0; i < number_of_nodes; ++i)
{
file_reader.ReadInto(&current_node, 1);
node_array[i].lon = current_node.lon;
node_array[i].lat = current_node.lat;
node_array[i].node_id = current_node.node_id;
coordinates[i].lon = current_node.lon;
coordinates[i].lat = current_node.lat;
osm_node_ids.push_back(current_node.node_id);
if (current_node.barrier)
{
+31 -4
View File
@@ -4,6 +4,7 @@
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
#include "storage/io.hpp"
#include "storage/shared_memory_ownership.hpp"
#include <cmath>
@@ -13,7 +14,22 @@ namespace osrm
{
namespace util
{
namespace detail
{
template <typename T, storage::Ownership Ownership> class PackedVector;
}
namespace serialization
{
template <typename T, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::PackedVector<T, Ownership> &vec);
template <typename T, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer, const detail::PackedVector<T, Ownership> &vec);
}
namespace detail
{
/**
* Since OSM node IDs are (at the time of writing) not quite yet overflowing 32 bits, and
* will predictably be containable within 33 bits for a long time, the following packs
@@ -22,8 +38,7 @@ namespace util
* NOTE: this type is templated for future use, but will require a slight refactor to
* configure BITSIZE and ELEMSIZE
*/
template <typename T, storage::Ownership Ownership = storage::Ownership::Container>
class PackedVector
template <typename T, storage::Ownership Ownership> class PackedVector
{
static const constexpr std::size_t BITSIZE = 33;
static const constexpr std::size_t ELEMSIZE = 64;
@@ -80,7 +95,9 @@ class PackedVector
num_elements++;
}
T at(const std::size_t &a_index) const
T operator[](const std::size_t index) const { return at(index); }
T at(const std::size_t a_index) const
{
BOOST_ASSERT(a_index < num_elements);
@@ -147,10 +164,16 @@ class PackedVector
return std::floor(static_cast<double>(vec.capacity()) * ELEMSIZE / BITSIZE);
}
friend void serialization::read<T, Ownership>(storage::io::FileReader &reader,
detail::PackedVector<T, Ownership> &vec);
friend void serialization::write<T, Ownership>(storage::io::FileWriter &writer,
const detail::PackedVector<T, Ownership> &vec);
private:
typename util::ShM<std::uint64_t, Ownership>::vector vec;
std::size_t num_elements = 0;
std::uint64_t num_elements = 0;
signed cursor = -1;
@@ -192,6 +215,10 @@ class PackedVector
}
};
}
template <typename T> using PackedVector = detail::PackedVector<T, storage::Ownership::Container>;
template <typename T> using PackedVectorView = detail::PackedVector<T, storage::Ownership::View>;
}
}
#endif /* PACKED_VECTOR_HPP */
+16
View File
@@ -1,6 +1,7 @@
#ifndef OSMR_UTIL_SERIALIZATION_HPP
#define OSMR_UTIL_SERIALIZATION_HPP
#include "util/packed_vector.hpp"
#include "util/static_graph.hpp"
#include "util/dynamic_graph.hpp"
#include "storage/io.hpp"
@@ -11,6 +12,21 @@ namespace util
{
namespace serialization
{
template <typename T, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::PackedVector<T, Ownership> &vec)
{
vec.num_elements =reader.ReadOne<std::uint64_t>();
reader.DeserializeVector(vec.vec);
}
template <typename T, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::PackedVector<T, Ownership> &vec)
{
writer.WriteOne(vec.num_elements);
writer.SerializeVector(vec.vec);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
+8 -8
View File
@@ -53,16 +53,17 @@ namespace util
// All coordinates are pojected first to Web Mercator before the bounding boxes
// are computed, this means the internal distance metric doesn not represent meters!
template <class EdgeDataT,
class CoordinateListT = std::vector<Coordinate>,
storage::Ownership Ownership = storage::Ownership::Container,
std::uint32_t BRANCHING_FACTOR = 128,
std::uint32_t LEAF_PAGE_SIZE = 4096>
class StaticRTree
{
template <typename T> using Vector = typename ShM<T, Ownership>::vector;
public:
using Rectangle = RectangleInt2D;
using EdgeData = EdgeDataT;
using CoordinateList = CoordinateListT;
using CoordinateList = Vector<util::Coordinate>;
static_assert(LEAF_PAGE_SIZE >= sizeof(uint32_t) + sizeof(EdgeDataT), "page size is too small");
static_assert(((LEAF_PAGE_SIZE - 1) & LEAF_PAGE_SIZE) == 0, "page size is not a power of 2");
@@ -154,8 +155,8 @@ class StaticRTree
Coordinate fixed_projected_coordinate;
};
typename ShM<TreeNode, Ownership>::vector m_search_tree;
const CoordinateListT &m_coordinate_list;
Vector<TreeNode> m_search_tree;
const Vector<Coordinate> &m_coordinate_list;
boost::iostreams::mapped_file_source m_leaves_region;
// read-only view of leaves
@@ -165,12 +166,11 @@ class StaticRTree
StaticRTree(const StaticRTree &) = delete;
StaticRTree &operator=(const StaticRTree &) = delete;
template <typename CoordinateT>
// Construct a packed Hilbert-R-Tree with Kamel-Faloutsos algorithm [1]
explicit StaticRTree(const std::vector<EdgeDataT> &input_data_vector,
const std::string &tree_node_filename,
const std::string &leaf_node_filename,
const std::vector<CoordinateT> &coordinate_list)
const Vector<Coordinate> &coordinate_list)
: m_coordinate_list(coordinate_list)
{
const uint64_t element_count = input_data_vector.size();
@@ -347,7 +347,7 @@ class StaticRTree
explicit StaticRTree(const boost::filesystem::path &node_file,
const boost::filesystem::path &leaf_file,
const CoordinateListT &coordinate_list)
const Vector<Coordinate> &coordinate_list)
: m_coordinate_list(coordinate_list)
{
storage::io::FileReader tree_node_file(node_file,
@@ -364,7 +364,7 @@ class StaticRTree
explicit StaticRTree(TreeNode *tree_node_ptr,
const uint64_t number_of_nodes,
const boost::filesystem::path &leaf_file,
const CoordinateListT &coordinate_list)
const Vector<Coordinate> &coordinate_list)
: m_search_tree(tree_node_ptr, number_of_nodes), m_coordinate_list(coordinate_list)
{
MapLeafNodesFile(leaf_file);