Welcome to mirror list, hosted at ThFree Co, Russian Federation.

joint_index.hpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 035cc0f8bea2b7ebe3da14c1bacaba0c70038838 (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
#pragma once

#include "routing/joint.hpp"
#include "routing/road_index.hpp"
#include "routing/road_point.hpp"

#include "base/assert.hpp"

#include <cstdint>
#include <vector>

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
  {
    CHECK_GREATER(m_offsets.size(), 0, ());
    return static_cast<uint32_t>(m_offsets.size() - 1);
  }

  uint32_t GetNumPoints() const { return static_cast<uint32_t>(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]);
  }

  void Build(RoadIndex const & roadIndex, uint32_t numJoints);

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];
  }

  std::vector<uint32_t> m_offsets;
  std::vector<RoadPoint> m_points;
};
}  // namespace routing