blob: 0bc95a6b3ba8bbfc22da9e134df24be323f32bec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#pragma once
#include "routing/joint.hpp"
#include "routing/road_index.hpp"
#include "routing/road_point.hpp"
#include "std/vector.hpp"
namespace routing
{
// JointIndex contains mapping from Joint::Id to RoadPoints.
//
// It is vector<Joint> conceptually.
// Technically Joint entries are joined into the single vector to reduce allocations overheads.
class JointIndex final
{
public:
// Read comments in Build method about -1.
uint32_t GetNumJoints() const { return m_offsets.size() - 1; }
uint32_t GetNumPoints() const { return m_points.size(); }
RoadPoint GetPoint(Joint::Id jointId) const { return m_points[Begin(jointId)]; }
template <typename F>
void ForEachPoint(Joint::Id jointId, F && f) const
{
for (uint32_t i = Begin(jointId); i < End(jointId); ++i)
f(m_points[i]);
auto const & it = m_dynamicJoints.find(jointId);
if (it != m_dynamicJoints.end())
{
Joint const & joint = it->second;
for (size_t i = 0; i < joint.GetSize(); ++i)
f(joint.GetEntry(i));
}
}
void Build(RoadIndex const & roadIndex, uint32_t numJoints);
Joint::Id InsertJoint(RoadPoint const & rp);
void AppendToJoint(Joint::Id jointId, RoadPoint rp);
private:
// Begin index for jointId entries.
uint32_t Begin(Joint::Id jointId) const
{
ASSERT_LESS(jointId, m_offsets.size(), ());
return m_offsets[jointId];
}
// End index (not inclusive) for jointId entries.
uint32_t End(Joint::Id jointId) const
{
Joint::Id const nextId = jointId + 1;
ASSERT_LESS(nextId, m_offsets.size(), ());
return m_offsets[nextId];
}
vector<uint32_t> m_offsets;
vector<RoadPoint> m_points;
unordered_map<Joint::Id, Joint> m_dynamicJoints;
};
} // namespace routing
|