-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathsegment_data_container.hpp
230 lines (181 loc) · 7.71 KB
/
segment_data_container.hpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#ifndef OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
#define OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
#include "util/packed_vector.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "storage/tar_fwd.hpp"
#include <boost/filesystem/path.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/iterator_range.hpp>
#include <unordered_map>
#include <string>
#include <vector>
namespace osrm
{
namespace extractor
{
class CompressedEdgeContainer;
namespace detail
{
template <storage::Ownership Ownership> class SegmentDataContainerImpl;
}
namespace serialization
{
template <storage::Ownership Ownership>
inline void read(storage::tar::FileReader &reader,
const std::string &name,
detail::SegmentDataContainerImpl<Ownership> &segment_data);
template <storage::Ownership Ownership>
inline void write(storage::tar::FileWriter &writer,
const std::string &name,
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
}
namespace detail
{
template <storage::Ownership Ownership> class SegmentDataContainerImpl
{
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
template <typename T, std::size_t Bits>
using PackedVector = util::detail::PackedVector<T, Bits, Ownership>;
friend CompressedEdgeContainer;
public:
// FIXME We should change the indexing to Edge-Based-Node id
using DirectionalGeometryID = std::uint32_t;
using SegmentOffset = std::uint32_t;
using SegmentWeightVector = PackedVector<SegmentWeight, SEGMENT_WEIGHT_BITS>;
using SegmentDurationVector = PackedVector<SegmentDuration, SEGMENT_DURAITON_BITS>;
using SegmentDatasourceVector = Vector<DatasourceID>;
SegmentDataContainerImpl() = default;
SegmentDataContainerImpl(Vector<std::uint32_t> index_,
Vector<NodeID> nodes_,
SegmentWeightVector fwd_weights_,
SegmentWeightVector rev_weights_,
SegmentDurationVector fwd_durations_,
SegmentDurationVector rev_durations_,
SegmentDatasourceVector fwd_datasources_,
SegmentDatasourceVector rev_datasources_)
: index(std::move(index_)), nodes(std::move(nodes_)), fwd_weights(std::move(fwd_weights_)),
rev_weights(std::move(rev_weights_)), fwd_durations(std::move(fwd_durations_)),
rev_durations(std::move(rev_durations_)), fwd_datasources(std::move(fwd_datasources_)),
rev_datasources(std::move(rev_datasources_))
{
}
auto GetForwardGeometry(const DirectionalGeometryID id)
{
const auto begin = nodes.begin() + index[id];
const auto end = nodes.begin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseGeometry(const DirectionalGeometryID id)
{
return boost::adaptors::reverse(GetForwardGeometry(id));
}
auto GetForwardDurations(const DirectionalGeometryID id)
{
const auto begin = fwd_durations.begin() + index[id] + 1;
const auto end = fwd_durations.begin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseDurations(const DirectionalGeometryID id)
{
const auto begin = rev_durations.begin() + index[id];
const auto end = rev_durations.begin() + index[id + 1] - 1;
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
}
auto GetForwardWeights(const DirectionalGeometryID id)
{
const auto begin = fwd_weights.begin() + index[id] + 1;
const auto end = fwd_weights.begin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseWeights(const DirectionalGeometryID id)
{
const auto begin = rev_weights.begin() + index[id];
const auto end = rev_weights.begin() + index[id + 1] - 1;
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
}
auto GetForwardDatasources(const DirectionalGeometryID id)
{
const auto begin = fwd_datasources.begin() + index[id] + 1;
const auto end = fwd_datasources.begin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseDatasources(const DirectionalGeometryID id)
{
const auto begin = rev_datasources.begin() + index[id];
const auto end = rev_datasources.begin() + index[id + 1] - 1;
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
}
auto GetForwardGeometry(const DirectionalGeometryID id) const
{
const auto begin = nodes.cbegin() + index[id];
const auto end = nodes.cbegin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseGeometry(const DirectionalGeometryID id) const
{
return boost::adaptors::reverse(GetForwardGeometry(id));
}
auto GetForwardDurations(const DirectionalGeometryID id) const
{
const auto begin = fwd_durations.cbegin() + index[id] + 1;
const auto end = fwd_durations.cbegin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseDurations(const DirectionalGeometryID id) const
{
const auto begin = rev_durations.cbegin() + index[id];
const auto end = rev_durations.cbegin() + index[id + 1] - 1;
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
}
auto GetForwardWeights(const DirectionalGeometryID id) const
{
const auto begin = fwd_weights.cbegin() + index[id] + 1;
const auto end = fwd_weights.cbegin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseWeights(const DirectionalGeometryID id) const
{
const auto begin = rev_weights.cbegin() + index[id];
const auto end = rev_weights.cbegin() + index[id + 1] - 1;
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
}
auto GetForwardDatasources(const DirectionalGeometryID id) const
{
const auto begin = fwd_datasources.cbegin() + index[id] + 1;
const auto end = fwd_datasources.cbegin() + index[id + 1];
return boost::make_iterator_range(begin, end);
}
auto GetReverseDatasources(const DirectionalGeometryID id) const
{
const auto begin = rev_datasources.cbegin() + index[id];
const auto end = rev_datasources.cbegin() + index[id + 1] - 1;
return boost::adaptors::reverse(boost::make_iterator_range(begin, end));
}
auto GetNumberOfGeometries() const { return index.size() - 1; }
auto GetNumberOfSegments() const { return fwd_weights.size(); }
friend void
serialization::read<Ownership>(storage::tar::FileReader &reader,
const std::string &name,
detail::SegmentDataContainerImpl<Ownership> &segment_data);
friend void serialization::write<Ownership>(
storage::tar::FileWriter &writer,
const std::string &name,
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
private:
Vector<std::uint32_t> index;
Vector<NodeID> nodes;
SegmentWeightVector fwd_weights;
SegmentWeightVector rev_weights;
SegmentDurationVector fwd_durations;
SegmentDurationVector rev_durations;
SegmentDatasourceVector fwd_datasources;
SegmentDatasourceVector rev_datasources;
};
}
using SegmentDataView = detail::SegmentDataContainerImpl<storage::Ownership::View>;
using SegmentDataContainer = detail::SegmentDataContainerImpl<storage::Ownership::Container>;
}
}
#endif