Use mmap instead of read - it's a lot faster here.

Also clean up construction of STRONG_TYPEDEF so that it can be
packed properly in structs (this explains all the () -> {}) changes
here.
This commit is contained in:
Daniel Patterson
2016-06-23 22:01:37 -07:00
parent 5905708111
commit ec02cdc4cc
34 changed files with 463 additions and 423 deletions
@@ -43,6 +43,34 @@ namespace osrm
namespace extractor
{
namespace lookup
{
// Set to 1 byte alignment
struct SegmentHeaderBlock
{
std::uint32_t num_osm_nodes;
OSMNodeID previous_osm_node_id;
} __attribute ((packed));
static_assert(sizeof(SegmentHeaderBlock) == 12, "SegmentHeaderBlock is not packed correctly");
struct SegmentBlock
{
OSMNodeID this_osm_node_id;
double segment_length;
std::int32_t segment_weight;
} __attribute ((packed));
static_assert(sizeof(SegmentBlock) == 20, "SegmentBlock is not packed correctly");
struct PenaltyBlock
{
std::uint32_t fixed_penalty;
OSMNodeID from_id;
OSMNodeID via_id;
OSMNodeID to_id;
} __attribute ((packed));
static_assert(sizeof(PenaltyBlock) == 28, "PenaltyBlock is not packed correctly");
}
class EdgeBasedGraphFactory
{
public:
+5 -3
View File
@@ -5,6 +5,8 @@
#include "util/typedefs.hpp"
#include <cstdint>
namespace osrm
{
namespace extractor
@@ -26,13 +28,13 @@ struct ExternalMemoryNode : QueryNode
static ExternalMemoryNode min_value()
{
return ExternalMemoryNode(
util::FixedLongitude(0), util::FixedLatitude(0), MIN_OSM_NODEID, false, false);
util::FixedLongitude{0}, util::FixedLatitude{0}, MIN_OSM_NODEID, false, false);
}
static ExternalMemoryNode max_value()
{
return ExternalMemoryNode(util::FixedLongitude(std::numeric_limits<int>::max()),
util::FixedLatitude(std::numeric_limits<int>::max()),
return ExternalMemoryNode(util::FixedLongitude{std::numeric_limits<std::int32_t>::max()},
util::FixedLatitude{std::numeric_limits<std::int32_t>::max()},
MAX_OSM_NODEID,
false,
false);
@@ -68,8 +68,8 @@ struct InternalExtractorEdge
bool is_split,
LaneDescriptionID lane_description,
guidance::RoadClassificationData road_classification)
: result(OSMNodeID(source),
OSMNodeID(target),
: result(source,
target,
name_id,
0,
forward,
+9 -8
View File
@@ -6,6 +6,7 @@
#include "util/coordinate.hpp"
#include <limits>
#include <cstdint>
namespace osrm
{
@@ -15,16 +16,16 @@ namespace extractor
struct QueryNode
{
using key_type = OSMNodeID; // type of NodeID
using value_type = int; // type of lat,lons
using value_type = std::int32_t; // type of lat,lons
explicit QueryNode(const util::FixedLongitude lon_,
const util::FixedLatitude lat_,
key_type node_id)
: lon(lon_), lat(lat_), node_id(std::move(node_id))
const key_type node_id_)
: lon(lon_), lat(lat_), node_id(node_id_)
{
}
QueryNode()
: lon(std::numeric_limits<int>::max()), lat(std::numeric_limits<int>::max()),
: lon{std::numeric_limits<value_type>::max()}, lat{std::numeric_limits<value_type>::max()},
node_id(SPECIAL_OSM_NODEID)
{
}
@@ -35,15 +36,15 @@ struct QueryNode
static QueryNode min_value()
{
return QueryNode(util::FixedLongitude(-180 * COORDINATE_PRECISION),
util::FixedLatitude(-90 * COORDINATE_PRECISION),
return QueryNode(util::FixedLongitude{static_cast<value_type>(-180 * COORDINATE_PRECISION)},
util::FixedLatitude{static_cast<value_type>(-90 * COORDINATE_PRECISION)},
MIN_OSM_NODEID);
}
static QueryNode max_value()
{
return QueryNode(util::FixedLongitude(180 * COORDINATE_PRECISION),
util::FixedLatitude(90 * COORDINATE_PRECISION),
return QueryNode(util::FixedLongitude{static_cast<value_type>(180 * COORDINATE_PRECISION)},
util::FixedLatitude{static_cast<value_type>(90 * COORDINATE_PRECISION)},
MAX_OSM_NODEID);
}
};
@@ -115,8 +115,8 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
(double_ > qi::lit(',') >
double_)[qi::_val = ph::bind(
[](double lon, double lat) {
return util::Coordinate(util::toFixed(util::FloatLongitude(lon)),
util::toFixed(util::FloatLatitude(lat)));
return util::Coordinate(util::toFixed(util::FloatLongitude{lon}),
util::toFixed(util::FloatLatitude{lat}));
},
qi::_1,
qi::_2)];
+6 -6
View File
@@ -61,7 +61,7 @@ inline FixedLatitude toFixed(const FloatLatitude floating)
{
const auto latitude = static_cast<double>(floating);
const auto fixed = boost::numeric_cast<std::int32_t>(latitude * COORDINATE_PRECISION);
return FixedLatitude(fixed);
return FixedLatitude{fixed};
}
/**
@@ -75,7 +75,7 @@ inline FixedLongitude toFixed(const FloatLongitude floating)
{
const auto longitude = static_cast<double>(floating);
const auto fixed = boost::numeric_cast<std::int32_t>(longitude * COORDINATE_PRECISION);
return FixedLongitude(fixed);
return FixedLongitude{fixed};
}
/**
@@ -89,7 +89,7 @@ inline FloatLatitude toFloating(const FixedLatitude fixed)
{
const auto latitude = static_cast<std::int32_t>(fixed);
const auto floating = boost::numeric_cast<double>(latitude / COORDINATE_PRECISION);
return FloatLatitude(floating);
return FloatLatitude{floating};
}
/**
@@ -103,7 +103,7 @@ inline FloatLongitude toFloating(const FixedLongitude fixed)
{
const auto longitude = static_cast<std::int32_t>(fixed);
const auto floating = boost::numeric_cast<double>(longitude / COORDINATE_PRECISION);
return FloatLongitude(floating);
return FloatLongitude{floating};
}
// fwd. decl.
@@ -127,7 +127,7 @@ struct Coordinate
FixedLongitude lon;
FixedLatitude lat;
Coordinate() : lon(std::numeric_limits<int>::min()), lat(std::numeric_limits<int>::min()) {}
Coordinate() : lon{std::numeric_limits<int>::min()}, lat{std::numeric_limits<int>::min()} {}
Coordinate(const FloatCoordinate &other);
@@ -173,7 +173,7 @@ struct FloatCoordinate
FloatLatitude lat;
FloatCoordinate()
: lon(std::numeric_limits<double>::min()), lat(std::numeric_limits<double>::min())
: lon{std::numeric_limits<double>::min()}, lat{std::numeric_limits<double>::min()}
{
}
+4 -4
View File
@@ -61,10 +61,10 @@ inline std::pair<double, FloatCoordinate> projectPointOnSegment(const FloatCoord
return {clamped_ratio,
{
FloatLongitude(1.0 - clamped_ratio) * source.lon +
target.lon * FloatLongitude(clamped_ratio),
FloatLatitude(1.0 - clamped_ratio) * source.lat +
target.lat * FloatLatitude(clamped_ratio),
FloatLongitude{1.0 - clamped_ratio} * source.lon +
target.lon * FloatLongitude{clamped_ratio},
FloatLatitude{1.0 - clamped_ratio} * source.lat +
target.lat * FloatLatitude{clamped_ratio},
}};
}
+3 -3
View File
@@ -95,14 +95,14 @@ template <typename T, bool UseSharedMemory = false> class PackedVector
if (left_index == 0)
{
// ID is at the far left side of this element
return static_cast<T>(elem >> (ELEMSIZE - BITSIZE));
return T{elem >> (ELEMSIZE - BITSIZE)};
}
else if (left_index >= BITSIZE)
{
// ID is entirely contained within this element
const std::uint64_t at_right = elem >> (left_index - BITSIZE);
const std::uint64_t left_mask = static_cast<std::uint64_t>(pow(2, BITSIZE)) - 1;
return static_cast<T>(at_right & left_mask);
return T{at_right & left_mask};
}
else
{
@@ -114,7 +114,7 @@ template <typename T, bool UseSharedMemory = false> class PackedVector
const std::uint64_t next_elem = static_cast<std::uint64_t>(vec.at(index + 1));
const std::uint64_t right_side = next_elem >> (ELEMSIZE - (BITSIZE - left_index));
return static_cast<T>(left_side | right_side);
return T{left_side | right_side};
}
}
+14 -14
View File
@@ -23,10 +23,10 @@ namespace util
struct RectangleInt2D
{
RectangleInt2D()
: min_lon(std::numeric_limits<std::int32_t>::max()),
max_lon(std::numeric_limits<std::int32_t>::min()),
min_lat(std::numeric_limits<std::int32_t>::max()),
max_lat(std::numeric_limits<std::int32_t>::min())
: min_lon{std::numeric_limits<std::int32_t>::max()},
max_lon{std::numeric_limits<std::int32_t>::min()},
min_lat{std::numeric_limits<std::int32_t>::max()},
max_lat{std::numeric_limits<std::int32_t>::min()}
{
}
@@ -56,10 +56,10 @@ struct RectangleInt2D
max_lon = std::max(max_lon, other.max_lon);
min_lat = std::min(min_lat, other.min_lat);
max_lat = std::max(max_lat, other.max_lat);
BOOST_ASSERT(min_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(min_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(max_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(max_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min()));
BOOST_ASSERT(min_lon != FixedLongitude{std::numeric_limits<std::int32_t>::min()});
BOOST_ASSERT(min_lat != FixedLatitude{std::numeric_limits<std::int32_t>::min()});
BOOST_ASSERT(max_lon != FixedLongitude{std::numeric_limits<std::int32_t>::min()});
BOOST_ASSERT(max_lat != FixedLatitude{std::numeric_limits<std::int32_t>::min()});
}
Coordinate Centroid() const
@@ -67,8 +67,8 @@ struct RectangleInt2D
Coordinate centroid;
// The coordinates of the midpoints are given by:
// x = (x1 + x2) /2 and y = (y1 + y2) /2.
centroid.lon = (min_lon + max_lon) / FixedLongitude(2);
centroid.lat = (min_lat + max_lat) / FixedLatitude(2);
centroid.lon = (min_lon + max_lon) / FixedLongitude{2};
centroid.lat = (min_lat + max_lat) / FixedLatitude{2};
return centroid;
}
@@ -169,10 +169,10 @@ struct RectangleInt2D
bool IsValid() const
{
return min_lon != FixedLongitude(std::numeric_limits<std::int32_t>::max()) &&
max_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()) &&
min_lat != FixedLatitude(std::numeric_limits<std::int32_t>::max()) &&
max_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min());
return min_lon != FixedLongitude{std::numeric_limits<std::int32_t>::max()} &&
max_lon != FixedLongitude{std::numeric_limits<std::int32_t>::min()} &&
min_lat != FixedLatitude{std::numeric_limits<std::int32_t>::max()} &&
max_lat != FixedLatitude{std::numeric_limits<std::int32_t>::min()};
}
friend std::ostream &operator<<(std::ostream &out, const RectangleInt2D &rect);
+2 -2
View File
@@ -193,8 +193,8 @@ class StaticRTree
Coordinate current_centroid = coordinate_calculation::centroid(
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)));
FixedLatitude{static_cast<std::int32_t>(COORDINATE_PRECISION *
web_mercator::latToY(toFloating(current_centroid.lat)))};
current_wrapper.m_hilbert_value = hilbertCode(current_centroid);
}
+26 -26
View File
@@ -40,32 +40,32 @@ namespace osrm
* etc. Also clarifies what this random "int" value is
* being used for.
*/
#define OSRM_STRONG_TYPEDEF(From, To) \
class To final \
{ \
static_assert(std::is_arithmetic<From>(), ""); \
From x; \
friend std::ostream &operator<<(std::ostream &stream, const To &inst); \
\
public: \
To() = default; \
explicit To(const From x_) : x(x_) {} \
explicit operator From &() { return x; } \
explicit operator From() const { return x; } \
To operator+(const To rhs_) const { return To(x + static_cast<const From>(rhs_)); } \
To operator-(const To rhs_) const { return To(x - static_cast<const From>(rhs_)); } \
To operator*(const To rhs_) const { return To(x * static_cast<const From>(rhs_)); } \
To operator/(const To rhs_) const { return To(x / static_cast<const From>(rhs_)); } \
bool operator<(const To z_) const { return x < static_cast<const From>(z_); } \
bool operator>(const To z_) const { return x > static_cast<const From>(z_); } \
bool operator<=(const To z_) const { return x <= static_cast<const From>(z_); } \
bool operator>=(const To z_) const { return x >= static_cast<const From>(z_); } \
bool operator==(const To z_) const { return x == static_cast<const From>(z_); } \
bool operator!=(const To z_) const { return x != static_cast<const From>(z_); } \
}; \
inline std::ostream &operator<<(std::ostream &stream, const To &inst) \
{ \
return stream << inst.x; \
#define OSRM_STRONG_TYPEDEF(From, To) \
struct To final \
{ \
static_assert(std::is_arithmetic<From>(), ""); \
From __value; \
friend std::ostream &operator<<(std::ostream &stream, const To &inst); \
\
explicit operator From &() { return __value; } \
explicit operator From() const { return __value; } \
To operator+(const To rhs_) const { return To{__value + static_cast<const From>(rhs_)}; } \
To operator-(const To rhs_) const { return To{__value - static_cast<const From>(rhs_)}; } \
To operator*(const To rhs_) const { return To{__value * static_cast<const From>(rhs_)}; } \
To operator/(const To rhs_) const { return To{__value / static_cast<const From>(rhs_)}; } \
bool operator<(const To z_) const { return __value < static_cast<const From>(z_); } \
bool operator>(const To z_) const { return __value > static_cast<const From>(z_); } \
bool operator<=(const To z_) const { return __value <= static_cast<const From>(z_); } \
bool operator>=(const To z_) const { return __value >= static_cast<const From>(z_); } \
bool operator==(const To z_) const { return __value == static_cast<const From>(z_); } \
bool operator!=(const To z_) const { return __value != static_cast<const From>(z_); } \
}; \
static_assert(std::is_trivial<To>(), #To " is not a trivial type"); \
static_assert(std::is_standard_layout<To>(), #To " is not a standart layout"); \
static_assert(std::is_pod<To>(), #To " is not a POD layout"); \
inline std::ostream &operator<<(std::ostream &stream, const To &inst) \
{ \
return stream << inst.__value; \
}
#define OSRM_STRONG_TYPEDEF_HASHABLE(From, To) \
+6 -6
View File
@@ -43,13 +43,13 @@ OSRM_STRONG_TYPEDEF_HASHABLE(std::uint64_t, OSMNodeID)
OSRM_STRONG_TYPEDEF(std::uint32_t, OSMWayID)
OSRM_STRONG_TYPEDEF_HASHABLE(std::uint32_t, OSMWayID)
static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_t>::max());
static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID(std::numeric_limits<std::uint32_t>::max());
static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID{std::numeric_limits<std::uint64_t>::max()};
static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID{std::numeric_limits<std::uint32_t>::max()};
static const OSMNodeID MAX_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_t>::max());
static const OSMNodeID MIN_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_t>::min());
static const OSMWayID MAX_OSM_WAYID = OSMWayID(std::numeric_limits<std::uint32_t>::max());
static const OSMWayID MIN_OSM_WAYID = OSMWayID(std::numeric_limits<std::uint32_t>::min());
static const OSMNodeID MAX_OSM_NODEID = OSMNodeID{std::numeric_limits<std::uint64_t>::max()};
static const OSMNodeID MIN_OSM_NODEID = OSMNodeID{std::numeric_limits<std::uint64_t>::min()};
static const OSMWayID MAX_OSM_WAYID = OSMWayID{std::numeric_limits<std::uint32_t>::max()};
static const OSMWayID MIN_OSM_WAYID = OSMWayID{std::numeric_limits<std::uint32_t>::min()};
using OSMNodeID_weak = std::uint64_t;
using OSMEdgeID_weak = std::uint64_t;
+10 -10
View File
@@ -35,7 +35,7 @@ inline FloatLatitude yToLat(const double y)
const double normalized_lat =
detail::RAD_TO_DEGREE * 2. * std::atan(std::exp(clamped_y * detail::DEGREE_TO_RAD));
return FloatLatitude(normalized_lat - 90.);
return FloatLatitude{normalized_lat - 90.};
}
inline double latToY(const FloatLatitude latitude)
@@ -56,7 +56,7 @@ template <typename T, typename... U> constexpr double horner(double x, T an, U..
inline double latToYapprox(const FloatLatitude latitude)
{
if (latitude < FloatLatitude(-70.) || latitude > FloatLatitude(70.))
if (latitude < FloatLatitude{-70.} || latitude > FloatLatitude{70.})
return latToY(latitude);
// Approximate the inverse Gudermannian function with the Padé approximant [11/11]: deg → deg
@@ -93,14 +93,14 @@ inline double latToYapprox(const FloatLatitude latitude)
inline FloatLatitude clamp(const FloatLatitude lat)
{
return std::max(std::min(lat, FloatLatitude(detail::MAX_LATITUDE)),
FloatLatitude(-detail::MAX_LATITUDE));
return std::max(std::min(lat, FloatLatitude{detail::MAX_LATITUDE}),
FloatLatitude{-detail::MAX_LATITUDE});
}
inline FloatLongitude clamp(const FloatLongitude lon)
{
return std::max(std::min(lon, FloatLongitude(detail::MAX_LONGITUDE)),
FloatLongitude(-detail::MAX_LONGITUDE));
return std::max(std::min(lon, FloatLongitude{detail::MAX_LONGITUDE}),
FloatLongitude{-detail::MAX_LONGITUDE});
}
inline void pixelToDegree(const double shift, double &x, double &y)
@@ -159,10 +159,10 @@ inline void xyzToMercator(
{
xyzToWGS84(x, y, z, minx, miny, maxx, maxy);
minx = static_cast<double>(clamp(util::FloatLongitude(minx))) * DEGREE_TO_PX;
miny = latToY(clamp(util::FloatLatitude(miny))) * DEGREE_TO_PX;
maxx = static_cast<double>(clamp(util::FloatLongitude(maxx))) * DEGREE_TO_PX;
maxy = latToY(clamp(util::FloatLatitude(maxy))) * DEGREE_TO_PX;
minx = static_cast<double>(clamp(util::FloatLongitude{minx})) * DEGREE_TO_PX;
miny = latToY(clamp(util::FloatLatitude{miny})) * DEGREE_TO_PX;
maxx = static_cast<double>(clamp(util::FloatLongitude{maxx})) * DEGREE_TO_PX;
maxy = latToY(clamp(util::FloatLatitude{maxy})) * DEGREE_TO_PX;
}
}
}