Clarify identifier types used in data facade

The data facade interface contains numerous methods for looking up
datapoints by identifiers.
Many of the parameters use the NodeID or EdgeID types. However, these two
identifier types are used for representing three different contexts:

1. Node-based graph edges and nodes
2. Edge-based graph edges and nodes
3. Packed geometries

Consider the use of identifier parameters in these examples:

---

GetWeightPenaltyForEdgeID(const EdgeID id)  <- edge-based edge

GetUncompressedForwardWeights(const EdgeID id) <- packed geometry

IsLeftHandDriving(const NodeID id) <- edge-based node

GetBearingClass(const NodeID node) <- node-based node

---

This mixing of contexts within the same interface makes it
difficult to understand the relationships and dependencies between
the OSRM datasets.

For 1. and 2. we continue to use the NodeID and EdgeID types, but
change the interface parameter names to identify them as
edge-based or node-based graph properties.

For 3. we define a new type definition, PackedGeometryID.

These changes are to aid with readability. A next step would be
to strongly type these definitions, leveraging the Alias template
already used for OSM identifiers.
This commit is contained in:
Michael Bell
2021-06-01 20:48:12 +01:00
committed by Siarhei Fedartsou
parent e872f1d6c3
commit 7f014bd616
5 changed files with 175 additions and 154 deletions
+5 -15
View File
@@ -76,13 +76,13 @@ using NodeID = std::uint32_t;
using EdgeID = std::uint32_t;
using NameID = std::uint32_t;
using AnnotationID = std::uint32_t;
using PackedGeometryID = std::uint32_t;
using EdgeWeight = std::int32_t;
using EdgeDuration = std::int32_t;
using EdgeDistance = float;
using SegmentWeight = std::uint32_t;
using SegmentDuration = std::uint32_t;
using TurnPenalty = std::int16_t; // turn penalty in 100ms units
using DataTimestamp = std::string;
static const std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();
@@ -95,16 +95,13 @@ static const LaneDescriptionID INVALID_LANE_DESCRIPTIONID =
std::numeric_limits<LaneDescriptionID>::max();
using BearingClassID = std::uint32_t;
static const BearingClassID INVALID_BEARING_CLASSID = std::numeric_limits<BearingClassID>::max();
using DiscreteBearing = std::uint16_t;
using EntryClassID = std::uint16_t;
static const EntryClassID INVALID_ENTRY_CLASSID = std::numeric_limits<EntryClassID>::max();
static const NodeID SPECIAL_NODEID = std::numeric_limits<NodeID>::max();
static const NodeID SPECIAL_SEGMENTID = std::numeric_limits<NodeID>::max() >> 1;
static const NodeID SPECIAL_GEOMETRYID = std::numeric_limits<NodeID>::max() >> 1;
static const PackedGeometryID SPECIAL_GEOMETRYID =
std::numeric_limits<PackedGeometryID>::max() >> 1;
static const EdgeID SPECIAL_EDGEID = std::numeric_limits<EdgeID>::max();
static const RestrictionID SPECIAL_RESTRICTIONID = std::numeric_limits<RestrictionID>::max();
static const NameID INVALID_NAMEID = std::numeric_limits<NameID>::max();
@@ -123,13 +120,6 @@ static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>
static const EdgeDistance INVALID_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max();
static const EdgeDistance INVALID_FALLBACK_SPEED = std::numeric_limits<double>::max();
// FIXME the bitfields we use require a reduced maximal duration, this should be kept consistent
// within the code base. For now we have to ensure that we don't case 30 bit to -1 and break any
// min() / operator< checks due to the invalid truncation. In addition, using signed and unsigned
// weights produces problems. As a result we can only store 1 << 29 since the MSB is still reserved
// for the sign bit. See https://github.com/Project-OSRM/osrm-backend/issues/3677
static const EdgeWeight MAXIMAL_EDGE_DURATION_INT_30 = (1 << 29) - 1;
using DatasourceID = std::uint8_t;
using BisectionID = std::uint32_t;
@@ -158,11 +148,11 @@ struct SegmentID
*/
struct GeometryID
{
GeometryID(const NodeID id_, const bool forward_) : id{id_}, forward{forward_} {}
GeometryID(const PackedGeometryID id_, const bool forward_) : id{id_}, forward{forward_} {}
GeometryID() : id(std::numeric_limits<unsigned>::max() >> 1), forward(false) {}
NodeID id : 31;
PackedGeometryID id : 31;
std::uint32_t forward : 1;
};