Skip to content

Commit ce092d1

Browse files
committed
Store index of the edge label in the map. This removes the need for
a separate map of adj. list entries and simplifies code.
1 parent c8dfcce commit ce092d1

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

src/thor/edgestatus.cc

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ void EdgeStatus::Init() {
1616

1717
// Set the edge status of a GraphId
1818
void EdgeStatus::Set(const baldr::GraphId& edgeid,
19-
const EdgeStatusType status) {
20-
edgestatus_[edgeid] = status;
19+
const EdgeSet set, const uint32_t index) {
20+
edgestatus_[edgeid] = { set, index };
2121
}
2222

2323
// Get the edge status of a GraphId. If not found in the map the
2424
// edge is considered unreached.
25-
EdgeStatusType EdgeStatus::Get(const baldr::GraphId& edgeid) const {
25+
EdgeStatusInfo EdgeStatus::Get(const baldr::GraphId& edgeid) const {
2626
auto p = edgestatus_.find(edgeid);
27-
return (p == edgestatus_.end()) ? kUnreached : p->second;
27+
return (p == edgestatus_.end()) ? EdgeStatusInfo() : p->second;
28+
/* if (p == edgestatus_.end()) {
29+
return EdgeStatusInfo();
30+
} else {
31+
return p->second;
32+
}*/
2833
}
2934

3035
}

test/edgestatus.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ using namespace valhalla::thor;
1010
namespace {
1111

1212
void TryGet(const EdgeStatus& edgestatus, const GraphId& edgeid,
13-
const EdgeStatusType expected) {
14-
EdgeStatusType r = edgestatus.Get(edgeid);
15-
if (r != expected)
13+
const EdgeSet expected) {
14+
EdgeStatusInfo r = edgestatus.Get(edgeid);
15+
if (r.status.set != expected)
1616
throw runtime_error("EdgeStatus get test failed");
1717
}
1818

1919
void TestStatus() {
2020
EdgeStatus edgestatus;
2121

2222
// Add some edges
23-
edgestatus.Set(GraphId(555, 1, 100100), kPermanent);
24-
edgestatus.Set(GraphId(555, 2, 100100), kPermanent);
25-
edgestatus.Set(GraphId(555, 3, 100100), kPermanent);
26-
edgestatus.Set(GraphId(555, 1, 55555), kTemporary);
27-
edgestatus.Set(GraphId(555, 2, 55555), kTemporary);
28-
edgestatus.Set(GraphId(555, 3, 55555), kTemporary);
29-
edgestatus.Set(GraphId(555, 1, 1), kPermanent);
30-
edgestatus.Set(GraphId(555, 2, 1), kPermanent);
31-
edgestatus.Set(GraphId(555, 3, 1), kPermanent);
23+
edgestatus.Set(GraphId(555, 1, 100100), kPermanent, 1);
24+
edgestatus.Set(GraphId(555, 2, 100100), kPermanent, 2);
25+
edgestatus.Set(GraphId(555, 3, 100100), kPermanent, 3);
26+
edgestatus.Set(GraphId(555, 1, 55555), kTemporary, 4);
27+
edgestatus.Set(GraphId(555, 2, 55555), kTemporary, 5);
28+
edgestatus.Set(GraphId(555, 3, 55555), kTemporary, 6);
29+
edgestatus.Set(GraphId(555, 1, 1), kPermanent, 7);
30+
edgestatus.Set(GraphId(555, 2, 1), kPermanent, 8);
31+
edgestatus.Set(GraphId(555, 3, 1), kPermanent, 9);
3232

3333
// Test various get
3434
TryGet(edgestatus, GraphId(555, 1, 100100), kPermanent);

valhalla/thor/edgestatus.h

+33-9
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,37 @@
77
namespace valhalla {
88
namespace thor {
99

10-
enum EdgeStatusType {
10+
// Edge label status
11+
enum EdgeSet {
1112
kUnreached = 0, // Unreached - not yet encountered in search
1213
kPermanent = 1, // Permanent - shortest path to this edge has been found
1314
kTemporary = 2 // Temporary - edge has been encountered but there could
1415
// still be a shorter path to this edge. This edge will
1516
// be "adjacent" to an edge that is permanently labeled.
1617
};
1718

19+
// Store the edge label status and its index in the EdgeLabels list
20+
struct EdgeStatusInfo {
21+
struct SetAndIndex {
22+
uint32_t index : 28;
23+
uint32_t set : 4;
24+
};
25+
SetAndIndex status;
26+
27+
EdgeStatusInfo() {
28+
status.set = static_cast<uint32_t>(kUnreached);
29+
status.index = 0;
30+
}
31+
32+
EdgeStatusInfo(const EdgeSet set, const uint32_t index) {
33+
status.set = static_cast<uint32_t>(set);
34+
status.index = index;
35+
}
36+
};
37+
1838
/**
19-
* Class to define / lookup the status of an edge during the shortest path
20-
* algorithm.
39+
* Class to define / lookup the status and index of an edge in the edge label
40+
* list during the shortest path algorithm.
2141
*/
2242
class EdgeStatus {
2343
public:
@@ -34,19 +54,23 @@ class EdgeStatus {
3454
/**
3555
* Set the status of a directed edge given its GraphId.
3656
* @param edgeid GraphId of the directed edge to set.
37-
* @param status Label status for this directed edge.
57+
* @param set Label set for this directed edge.
58+
* @param index Index of the edge label.
3859
*/
39-
void Set(const baldr::GraphId& edgeid, const EdgeStatusType status);
60+
void Set(const baldr::GraphId& edgeid, const EdgeSet set,
61+
const uint32_t index);
4062

4163
/**
42-
* Get the status of a directed edge given its GraphId.
64+
* Get the status info of a directed edge given its GraphId.
65+
* @param edgeid GraphId of the directed edge.
66+
* @return Returns edge status info.
4367
*/
44-
EdgeStatusType Get(const baldr::GraphId& edgeid) const;
68+
EdgeStatusInfo Get(const baldr::GraphId& edgeid) const;
4569

4670
private:
47-
// Map to store the status of GraphIds that have been encountered.
71+
// Map to store the status and index of GraphIds that have been encountered.
4872
// Any unreached edges are not added to the map.
49-
std::unordered_map<baldr::GraphId, EdgeStatusType> edgestatus_;
73+
std::unordered_map<baldr::GraphId, EdgeStatusInfo> edgestatus_;
5074
};
5175

5276
}

0 commit comments

Comments
 (0)