MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / Compress

Method Compress

src/extractor/turn_path_compressor.cpp:37–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void TurnPathCompressor::Compress(const NodeID from, const NodeID via, const NodeID to)
38{
39 // handle turn restrictions
40 // extract all start ptrs and move them from via to from.
41 auto all_starts_range = starts.equal_range(via);
42 std::vector<TurnPath *> start_ptrs;
43 std::transform(all_starts_range.first,
44 all_starts_range.second,
45 std::back_inserter(start_ptrs),
46 [](const auto pair) { return pair.second; });
47
48 const auto update_start = [&](auto ptr)
49 {
50 if (ptr->Type() == TurnPathType::VIA_NODE_TURN_PATH)
51 {
52
53 // ____ | from - p.from | via - p.via | to - p.to | ____
54 auto &node_ptr = ptr->AsViaNodePath();
55 BOOST_ASSERT(node_ptr.from == via);
56 if (node_ptr.via == to)
57 {
58 node_ptr.from = from;
59 }
60 // ____ | to - p.from | via - p.via | from - p.to | ____
61 else
62 {
63 BOOST_ASSERT(node_ptr.via == from);
64 node_ptr.from = to;
65 }
66 }
67 else
68 {
69 BOOST_ASSERT(ptr->Type() == TurnPathType::VIA_WAY_TURN_PATH);
70 auto &way_ptr = ptr->AsViaWayPath();
71 // ____ | from - p.from | via - p.via[0] | to - p[1..],p.to | ____
72 BOOST_ASSERT(way_ptr.from == via);
73 if (way_ptr.via.front() == to)
74 {
75 way_ptr.from = from;
76 }
77 // ____ | to - p.from | via - p.via[0] | from - p[1,..],p.to | ____
78 else
79 {
80 BOOST_ASSERT(way_ptr.via.front() == from);
81 way_ptr.from = to;
82 }
83 }
84 };
85
86 std::for_each(start_ptrs.begin(), start_ptrs.end(), update_start);
87
88 // update the ptrs in our mapping
89 starts.erase(via);
90
91 const auto reinsert_start = [&](auto ptr) { starts.insert({ptr->From(), ptr}); };
92 std::for_each(start_ptrs.begin(), start_ptrs.end(), reinsert_start);
93
94 // extract all end ptrs and move them from via to to

Callers

nothing calls this directly

Calls 8

insertMethod · 0.80
TypeMethod · 0.45
frontMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
FromMethod · 0.45
backMethod · 0.45
ToMethod · 0.45

Tested by

no test coverage detected