@@ -17,24 +17,28 @@ namespace nigiri {
1717
1818shapes_storage::shapes_storage (std::filesystem::path path,
1919 cista::mmap::protection const mode,
20- bool keep_shape_data )
20+ bool const keep_routed_shape_data )
2121 : mode_{mode},
2222 p_{[&]() {
2323 fs::create_directories (path);
2424 return std::move (path);
2525 }()},
2626 data_{mm_paged_vecvec_helper<shape_idx_t , geo::latlng>::data_t {
27- mm_vec<geo::latlng>{mm (" shapes_data.bin" , keep_shape_data )}},
27+ mm_vec<geo::latlng>{mm (" shapes_data.bin" )}},
2828 mm_vec<cista::page<std::uint64_t , std::uint32_t >>{
29- mm (" shapes_idx.bin" , keep_shape_data)}},
29+ mm (" shapes_idx.bin" )}},
30+ routed_data_{mm_paged_vecvec_helper<shape_idx_t , geo::latlng>::data_t {
31+ mm_vec<geo::latlng>{mm (" routed_shapes_data.bin" ,
32+ keep_routed_shape_data)}},
33+ mm_vec<cista::page<std::uint64_t , std::uint32_t >>{
34+ mm (" routed_shapes_idx.bin" , keep_routed_shape_data)}},
3035 offsets_{mm_vec<shape_offset_t >{mm (" shape_offsets_data.bin" )},
3136 mm_vec<std::uint64_t >{mm (" shape_offsets_idx.bin" )}},
3237 trip_offset_indices_{mm (" shape_trip_offsets.bin" )},
3338 route_bboxes_{mm (" shape_route_bboxes.bin" )},
3439 route_segment_bboxes_{
3540 mm_vec<geo::box>{mm (" shape_route_segment_bboxes_data.bin" )},
36- mm_vec<std::uint64_t >{mm (" shape_route_segment_bboxes_idx.bin" )}},
37- shape_sources_{mm (" shape_sources.bin" , keep_shape_data)} {}
41+ mm_vec<std::uint64_t >{mm (" shape_route_segment_bboxes_idx.bin" )}} {}
3842
3943cista::mmap shapes_storage::mm (char const * file, bool const keep) {
4044 auto const p = (p_ / file);
@@ -45,31 +49,50 @@ cista::mmap shapes_storage::mm(char const* file, bool const keep) {
4549 : mode_};
4650}
4751
48- std::tuple<std::span<geo::latlng const >, shape_idx_t , shape_offset_idx_t >
52+ std::tuple<std::span<geo::latlng const >, scoped_shape_idx_t , shape_offset_idx_t >
4953get_shape (shapes_storage const & storage, trip_idx_t const trip_idx) {
5054 if (trip_idx == trip_idx_t::invalid () ||
5155 trip_idx >= storage.trip_offset_indices_ .size ()) {
5256 return {};
5357 }
5458 auto const [shape_idx, offset_idx] = storage.trip_offset_indices_ [trip_idx];
55- assert ((shape_idx == shape_idx_t ::invalid ()) ==
59+ assert ((shape_idx == scoped_shape_idx_t ::invalid ()) ==
5660 (offset_idx == shape_offset_idx_t::invalid ()));
5761 if (offset_idx == shape_offset_idx_t::invalid ()) {
5862 return {};
5963 }
6064 return std::tuple{storage.get_shape (shape_idx), shape_idx, offset_idx};
6165}
6266
63- std::span<geo::latlng const > shapes_storage::get_shape (
64- shape_idx_t const shape_idx) const {
67+ std::span<geo::latlng const > get_shape_from_data (
68+ mm_paged_vecvec<shape_idx_t , geo::latlng> const & data,
69+ shape_idx_t const shape_idx) {
6570 if (shape_idx == shape_idx_t::invalid () ||
66- static_cast <std::size_t >(to_idx (shape_idx)) > data_ .size ()) {
71+ static_cast <std::size_t >(to_idx (shape_idx)) >= data .size ()) {
6772 return {};
6873 }
69- auto const shape = data_ [shape_idx];
74+ auto const shape = data [shape_idx];
7075 return {begin (shape), end (shape)};
7176}
7277
78+ std::span<geo::latlng const > shapes_storage::get_shape (
79+ scoped_shape_idx_t const shape_idx) const {
80+ if (shape_idx == scoped_shape_idx_t::invalid ()) {
81+ return {};
82+ }
83+
84+ auto const local_shape_idx = get_local_shape_idx (shape_idx);
85+ switch (get_shape_source (shape_idx)) {
86+ case shape_source::kTimetable :
87+ return get_shape_from_data (data_, local_shape_idx);
88+ case shape_source::kRouted :
89+ return get_shape_from_data (routed_data_, local_shape_idx);
90+ case shape_source::kNone : return {};
91+ }
92+
93+ return {};
94+ }
95+
7396std::span<geo::latlng const > shapes_storage::get_shape (
7497 trip_idx_t const trip_idx) const {
7598 auto const [shape, _shape_idx, _offset_idx] =
@@ -98,24 +121,25 @@ std::span<geo::latlng const> shapes_storage::get_shape(
98121 return get_subshape (*this , shape, offset_idx, range);
99122}
100123
101- std::pair<std::span<geo::latlng const >, shape_idx_t >
124+ std::pair<std::span<geo::latlng const >, scoped_shape_idx_t >
102125shapes_storage::get_shape_with_idx (trip_idx_t const trip_idx) const {
103126 auto const [shape, shape_idx, _] = nigiri::get_shape (*this , trip_idx);
104127 return std::pair{shape, shape_idx};
105128}
106129
107- std::pair<std::span<geo::latlng const >, shape_idx_t >
130+ std::pair<std::span<geo::latlng const >, scoped_shape_idx_t >
108131shapes_storage::get_shape_with_idx (trip_idx_t const trip_idx,
109132 interval<stop_idx_t > const & range) const {
110133 auto const [shape, shape_idx, offset_idx] =
111134 nigiri::get_shape (*this , trip_idx);
112135 if (shape.empty ()) {
113- return std::pair{shape, shape_idx_t ::invalid ()};
136+ return std::pair{shape, scoped_shape_idx_t ::invalid ()};
114137 }
115138 return std::pair{get_subshape (*this , shape, offset_idx, range), shape_idx};
116139}
117140
118- shape_idx_t shapes_storage::get_shape_idx (trip_idx_t const trip_idx) const {
141+ scoped_shape_idx_t shapes_storage::get_shape_idx (
142+ trip_idx_t const trip_idx) const {
119143 if (trip_idx == trip_idx_t::invalid () ||
120144 trip_idx >= trip_offset_indices_.size ()) {
121145 return {};
@@ -133,7 +157,7 @@ shape_offset_idx_t shapes_storage::add_offsets(
133157
134158void shapes_storage::add_trip_shape_offsets (
135159 [[maybe_unused]] trip_idx_t const trip_idx,
136- cista::pair<shape_idx_t , shape_offset_idx_t > const & offset_idx) {
160+ cista::pair<scoped_shape_idx_t , shape_offset_idx_t > const & offset_idx) {
137161 assert (trip_idx == trip_offset_indices_.size ());
138162 trip_offset_indices_.emplace_back (offset_idx);
139163}
@@ -155,13 +179,4 @@ std::optional<geo::box> shapes_storage::get_bounding_box(
155179 : std::optional<geo::box>{std::nullopt };
156180}
157181
158- shape_source shapes_storage::get_shape_source (
159- shape_idx_t const shape_idx) const {
160- if (shape_idx == shape_idx_t::invalid () ||
161- static_cast <std::size_t >(to_idx (shape_idx)) >= shape_sources_.size ()) {
162- return shape_source::kNone ;
163- }
164- return shape_sources_[shape_idx];
165- }
166-
167182} // namespace nigiri
0 commit comments