Skip to content

Commit d0fb57c

Browse files
authored
shapes storage: add option to keep shape data (#318)
1 parent ebf2a1d commit d0fb57c

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

include/nigiri/shapes_storage.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
namespace nigiri {
1616

1717
struct shapes_storage {
18-
shapes_storage(std::filesystem::path, cista::mmap::protection);
18+
shapes_storage(std::filesystem::path,
19+
cista::mmap::protection,
20+
bool keep_shape_data = false);
1921

20-
cista::mmap mm(char const* file);
22+
cista::mmap mm(char const* file, bool keep = false);
2123

2224
std::span<geo::latlng const> get_shape(shape_idx_t) const;
2325
std::span<geo::latlng const> get_shape(trip_idx_t) const;

src/shapes_storage.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,33 @@ namespace fs = std::filesystem;
1616
namespace nigiri {
1717

1818
shapes_storage::shapes_storage(std::filesystem::path path,
19-
cista::mmap::protection const mode)
19+
cista::mmap::protection const mode,
20+
bool keep_shape_data)
2021
: mode_{mode},
2122
p_{[&]() {
2223
fs::create_directories(path);
2324
return std::move(path);
2425
}()},
2526
data_{mm_paged_vecvec_helper<shape_idx_t, geo::latlng>::data_t{
26-
mm_vec<geo::latlng>{mm("shapes_data.bin")}},
27+
mm_vec<geo::latlng>{mm("shapes_data.bin", keep_shape_data)}},
2728
mm_vec<cista::page<std::uint64_t, std::uint32_t>>{
28-
mm("shapes_idx.bin")}},
29+
mm("shapes_idx.bin", keep_shape_data)}},
2930
offsets_{mm_vec<shape_offset_t>{mm("shape_offsets_data.bin")},
3031
mm_vec<std::uint64_t>{mm("shape_offsets_idx.bin")}},
3132
trip_offset_indices_{mm("shape_trip_offsets.bin")},
3233
route_bboxes_{mm("shape_route_bboxes.bin")},
3334
route_segment_bboxes_{
3435
mm_vec<geo::box>{mm("shape_route_segment_bboxes_data.bin")},
3536
mm_vec<std::uint64_t>{mm("shape_route_segment_bboxes_idx.bin")}},
36-
shape_sources_{mm("shape_sources.bin")} {}
37-
38-
cista::mmap shapes_storage::mm(char const* file) {
39-
return cista::mmap{(p_ / file).generic_string().c_str(), mode_};
37+
shape_sources_{mm("shape_sources.bin", keep_shape_data)} {}
38+
39+
cista::mmap shapes_storage::mm(char const* file, bool const keep) {
40+
auto const p = (p_ / file);
41+
return cista::mmap{
42+
p.generic_string().c_str(),
43+
keep && mode_ == cista::mmap::protection::WRITE && fs::exists(p)
44+
? cista::mmap::protection::MODIFY
45+
: mode_};
4046
}
4147

4248
std::tuple<std::span<geo::latlng const>, shape_idx_t, shape_offset_idx_t>

0 commit comments

Comments
 (0)