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: cef629ef37b67246db0a5f5fee05c29379c0319b (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
63
64
65
66
67
68
69
70
71
72
73
#pragma once

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

#include "base/assert.hpp"
#include "std/utility.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
  {
    CHECK_GREATER(m_offsets.size(), 0, ());
    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);

  /// \brief fills result with paths from |jointId0| to |jointId1|.
  void FindPointsWithCommonFeature(Joint::Id jointId0, Joint::Id jointId1,
                                   vector<pair<RoadPoint, RoadPoint>> & result) const;
  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