1 /* 2 3 Copyright (c) 2017, Project OSRM contributors 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without modification, 7 are permitted provided that the following conditions are met: 8 9 Redistributions of source code must retain the above copyright notice, this list 10 of conditions and the following disclaimer. 11 Redistributions in binary form must reproduce the above copyright notice, this 12 list of conditions and the following disclaimer in the documentation and/or 13 other materials provided with the distribution. 14 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 */ 27 28 #ifndef TYPEDEFS_H 29 #define TYPEDEFS_H 30 31 #include "util/alias.hpp" 32 33 #include <boost/assert.hpp> 34 35 #include <cstddef> 36 #include <cstdint> 37 #include <limits> 38 39 // OpenStreetMap node ids are higher than 2^32 40 namespace tag 41 { 42 struct osm_node_id 43 { 44 }; 45 struct osm_way_id 46 { 47 }; 48 struct duplicated_node 49 { 50 }; 51 } // namespace tag 52 using OSMNodeID = osrm::Alias<std::uint64_t, tag::osm_node_id>; 53 static_assert(std::is_pod<OSMNodeID>(), "OSMNodeID is not a valid alias"); 54 using OSMWayID = osrm::Alias<std::uint64_t, tag::osm_way_id>; 55 static_assert(std::is_pod<OSMWayID>(), "OSMWayID is not a valid alias"); 56 57 using DuplicatedNodeID = std::uint64_t; 58 using RestrictionID = std::uint64_t; 59 60 static const OSMNodeID SPECIAL_OSM_NODEID = 61 OSMNodeID{std::numeric_limits<OSMNodeID::value_type>::max()}; 62 static const OSMWayID SPECIAL_OSM_WAYID = 63 OSMWayID{std::numeric_limits<OSMWayID::value_type>::max()}; 64 65 static const OSMNodeID MAX_OSM_NODEID = 66 OSMNodeID{std::numeric_limits<OSMNodeID::value_type>::max()}; 67 static const OSMNodeID MIN_OSM_NODEID = 68 OSMNodeID{std::numeric_limits<OSMNodeID::value_type>::min()}; 69 static const OSMWayID MAX_OSM_WAYID = OSMWayID{std::numeric_limits<OSMWayID::value_type>::max()}; 70 static const OSMWayID MIN_OSM_WAYID = OSMWayID{std::numeric_limits<OSMWayID::value_type>::min()}; 71 72 using NodeID = std::uint32_t; 73 using EdgeID = std::uint32_t; 74 using NameID = std::uint32_t; 75 using AnnotationID = std::uint32_t; 76 using EdgeWeight = std::int32_t; 77 using EdgeDuration = std::int32_t; 78 using EdgeDistance = float; 79 using SegmentWeight = std::uint32_t; 80 using SegmentDuration = std::uint32_t; 81 using TurnPenalty = std::int16_t; // turn penalty in 100ms units 82 using DataTimestamp = std::string; 83 84 static const std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max(); 85 86 using LaneID = std::uint8_t; 87 static const LaneID INVALID_LANEID = std::numeric_limits<LaneID>::max(); 88 using LaneDataID = std::uint16_t; 89 static const LaneDataID INVALID_LANE_DATAID = std::numeric_limits<LaneDataID>::max(); 90 using LaneDescriptionID = std::uint16_t; 91 static const LaneDescriptionID INVALID_LANE_DESCRIPTIONID = 92 std::numeric_limits<LaneDescriptionID>::max(); 93 94 using BearingClassID = std::uint32_t; 95 static const BearingClassID INVALID_BEARING_CLASSID = std::numeric_limits<BearingClassID>::max(); 96 97 using DiscreteBearing = std::uint16_t; 98 99 using EntryClassID = std::uint16_t; 100 static const EntryClassID INVALID_ENTRY_CLASSID = std::numeric_limits<EntryClassID>::max(); 101 102 static const NodeID SPECIAL_NODEID = std::numeric_limits<NodeID>::max(); 103 static const NodeID SPECIAL_SEGMENTID = std::numeric_limits<NodeID>::max() >> 1; 104 static const NodeID SPECIAL_GEOMETRYID = std::numeric_limits<NodeID>::max() >> 1; 105 static const EdgeID SPECIAL_EDGEID = std::numeric_limits<EdgeID>::max(); 106 static const RestrictionID SPECIAL_RESTRICTIONID = std::numeric_limits<RestrictionID>::max(); 107 static const NameID INVALID_NAMEID = std::numeric_limits<NameID>::max(); 108 static const NameID EMPTY_NAMEID = 0; 109 static const unsigned INVALID_COMPONENTID = 0; 110 static const std::size_t SEGMENT_WEIGHT_BITS = 22; 111 static const std::size_t SEGMENT_DURATION_BITS = 22; 112 static const SegmentWeight INVALID_SEGMENT_WEIGHT = (1u << SEGMENT_WEIGHT_BITS) - 1; 113 static const SegmentDuration INVALID_SEGMENT_DURATION = (1u << SEGMENT_DURATION_BITS) - 1; 114 static const SegmentWeight MAX_SEGMENT_WEIGHT = INVALID_SEGMENT_WEIGHT - 1; 115 static const SegmentDuration MAX_SEGMENT_DURATION = INVALID_SEGMENT_DURATION - 1; 116 static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max(); 117 static const EdgeDuration MAXIMAL_EDGE_DURATION = std::numeric_limits<EdgeDuration>::max(); 118 static const EdgeDistance MAXIMAL_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max(); 119 static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>::max(); 120 static const EdgeDistance INVALID_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max(); 121 static const EdgeDistance INVALID_FALLBACK_SPEED = std::numeric_limits<double>::max(); 122 123 // FIXME the bitfields we use require a reduced maximal duration, this should be kept consistent 124 // within the code base. For now we have to ensure that we don't case 30 bit to -1 and break any 125 // min() / operator< checks due to the invalid truncation. In addition, using signed and unsigned 126 // weights produces problems. As a result we can only store 1 << 29 since the MSB is still reserved 127 // for the sign bit. See https://github.com/Project-OSRM/osrm-backend/issues/3677 128 static const EdgeWeight MAXIMAL_EDGE_DURATION_INT_30 = (1 << 29) - 1; 129 130 using DatasourceID = std::uint8_t; 131 132 using BisectionID = std::uint32_t; 133 using LevelID = std::uint8_t; 134 using CellID = std::uint32_t; 135 using PartitionID = std::uint64_t; 136 137 static constexpr auto INVALID_LEVEL_ID = std::numeric_limits<LevelID>::max(); 138 static constexpr auto INVALID_CELL_ID = std::numeric_limits<CellID>::max(); 139 140 struct SegmentID 141 { SegmentIDSegmentID142 SegmentID(const NodeID id_, const bool enabled_) : id{id_}, enabled{enabled_} 143 { 144 BOOST_ASSERT(!enabled || id != SPECIAL_SEGMENTID); 145 } 146 147 NodeID id : 31; 148 std::uint32_t enabled : 1; 149 }; 150 151 /* We need to bit pack here because the index for the via_node 152 * is given to us without knowing whether the geometry should 153 * be read forward or in reverse. The extra field `forward` 154 * indicates that to the routing engine 155 */ 156 struct GeometryID 157 { GeometryIDGeometryID158 GeometryID(const NodeID id_, const bool forward_) : id{id_}, forward{forward_} {} 159 GeometryIDGeometryID160 GeometryID() : id(std::numeric_limits<unsigned>::max() >> 1), forward(false) {} 161 162 NodeID id : 31; 163 std::uint32_t forward : 1; 164 }; 165 166 static_assert(sizeof(SegmentID) == 4, "SegmentID needs to be 4 bytes big"); 167 168 // Strongly connected component ID of an edge-based node 169 struct ComponentID 170 { 171 std::uint32_t id : 31; 172 std::uint32_t is_tiny : 1; 173 }; 174 175 #endif /* TYPEDEFS_H */ 176