Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,16 @@ void check_options_expire(options_t *options)
{
// Zoom level 31 is the technical limit because we use 32-bit integers for
// the x and y index of a tile ID.
if (options->expire_tiles_zoom_min > 31) {
options->expire_tiles_zoom_min = 31;
constexpr uint32_t ZOOM_MAX = 31;

if (options->expire_tiles_zoom_min > ZOOM_MAX) {
options->expire_tiles_zoom_min = ZOOM_MAX;
log_warn("Minimum zoom level for tile expiry is too "
"large and has been set to 31.");
}

if (options->expire_tiles_zoom > 31) {
options->expire_tiles_zoom = 31;
if (options->expire_tiles_zoom > ZOOM_MAX) {
options->expire_tiles_zoom = ZOOM_MAX;
log_warn("Maximum zoom level for tile expiry is too "
"large and has been set to 31.");
}
Expand Down
16 changes: 8 additions & 8 deletions src/middle-ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,29 @@ void middle_ram_t::stop()
{
assert(m_middle_state == middle_state::done);

auto const mbyte = 1024 * 1024;
constexpr auto MBYTE = 1024 * 1024;

if (m_persistent_cache) {
log_debug("Middle 'ram': Node locations on disk: size={} bytes={}M",
m_persistent_cache->size(),
m_persistent_cache->used_memory() / mbyte);
m_persistent_cache->used_memory() / MBYTE);
} else {
log_debug("Middle 'ram': Node locations in memory: size={} bytes={}M",
m_node_locations.size(),
m_node_locations.used_memory() / mbyte);
m_node_locations.used_memory() / MBYTE);
}

log_debug("Middle 'ram': Way nodes data: size={} capacity={} bytes={}M",
m_way_nodes_data.size(), m_way_nodes_data.capacity(),
m_way_nodes_data.capacity() / mbyte);
m_way_nodes_data.capacity() / MBYTE);

log_debug("Middle 'ram': Way nodes index: size={} capacity={} bytes={}M",
m_way_nodes_index.size(), m_way_nodes_index.capacity(),
m_way_nodes_index.used_memory() / mbyte);
m_way_nodes_index.used_memory() / MBYTE);

log_debug("Middle 'ram': Object data: size={} capacity={} bytes={}M",
m_object_buffer.committed(), m_object_buffer.capacity(),
m_object_buffer.capacity() / mbyte);
m_object_buffer.capacity() / MBYTE);

std::size_t index_size = 0;
std::size_t index_capacity = 0;
Expand All @@ -146,13 +146,13 @@ void middle_ram_t::stop()
index_mem += index.used_memory();
}
log_debug("Middle 'ram': Object indexes: size={} capacity={} bytes={}M",
index_size, index_capacity, index_mem / mbyte);
index_size, index_capacity, index_mem / MBYTE);

log_debug("Middle 'ram': Memory used overall: {}MBytes",
(m_node_locations.used_memory() + m_way_nodes_data.capacity() +
m_way_nodes_index.used_memory() + m_object_buffer.capacity() +
index_mem) /
mbyte);
MBYTE);

m_node_locations.clear();

Expand Down
7 changes: 6 additions & 1 deletion src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ geom::point_t tile_t::to_world_coords(geom::point_t p,

geom::point_t tile_t::center() const noexcept
{
return to_world_coords({0.5, 0.5}, 1);
constexpr double MIDDLE = 0.5;
return to_world_coords({MIDDLE, MIDDLE}, 1);
}

namespace {

// Quadkey implementation uses bit interleaving code from
// https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2018/01/08/interleave.c

// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)

uint64_t interleave_uint32_with_zeros(uint32_t input) noexcept
{
uint64_t word = input;
Expand All @@ -66,6 +69,8 @@ uint32_t deinterleave_lowuint32(uint64_t word) noexcept
return static_cast<uint32_t>(word);
}

// NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)

uint32_t parse_num_with_max(std::string const &str, uint32_t max)
{
std::size_t pos = 0;
Expand Down
19 changes: 11 additions & 8 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ namespace util {

std::string human_readable_duration(uint64_t seconds)
{
if (seconds < 60UL) {
constexpr uint64_t SECONDS_IN_MINUTE = 60UL;
constexpr uint64_t MINUTES_IN_HOUR = 60UL;

if (seconds < SECONDS_IN_MINUTE) {
return fmt::format("{}s", seconds);
}

if (seconds < (60UL * 60UL)) {
return fmt::format("{}s ({}m {}s)", seconds, seconds / 60,
seconds % 60);
uint64_t const mins = seconds / SECONDS_IN_MINUTE;
uint64_t const secs = seconds % SECONDS_IN_MINUTE;

if (seconds < (SECONDS_IN_MINUTE * MINUTES_IN_HOUR)) {
return fmt::format("{}s ({}m {}s)", seconds, mins, secs);
}

auto const secs = seconds % 60;
auto const mins = seconds / 60;
return fmt::format("{}s ({}h {}m {}s)", seconds, mins / 60, mins % 60,
secs);
return fmt::format("{}s ({}h {}m {}s)", seconds, mins / MINUTES_IN_HOUR,
mins % MINUTES_IN_HOUR, secs);
}

std::string human_readable_duration(std::chrono::microseconds duration)
Expand Down
29 changes: 21 additions & 8 deletions src/wkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,37 +209,48 @@ class make_ewkb_visitor_t

std::string operator()(geom::point_t const &geom) const
{
constexpr std::size_t SIZE_POINT_HEADER_WITH_SRID = 1UL + 4UL + 4UL;
constexpr std::size_t SIZE_POINT =
SIZE_POINT_HEADER_WITH_SRID + SIZE_COORDINATE_PAIR;

std::string data;

if (m_ensure_multi) {
write_header(&data, wkb_multi_point, m_srid);
write_length(&data, 1);
write_point(&data, geom);
} else {
// 9 byte header plus one set of coordinates
constexpr std::size_t SIZE = 9 + 2 * 8;
data.reserve(SIZE);
data.reserve(SIZE_POINT);
write_point(&data, geom, m_srid);
assert(data.size() == SIZE);
assert(data.size() == SIZE_POINT);
}

return data;
}

std::string operator()(geom::linestring_t const &geom) const
{
constexpr std::size_t SIZE_HEADER_WITH_COUNT = 1UL + 4UL + 4UL;
constexpr std::size_t SIZE_HEADER_WITH_COUNT_AND_SRID =
SIZE_HEADER_WITH_COUNT + 4UL;

std::string data;

std::size_t const coords_size = geom.size() * SIZE_COORDINATE_PAIR;

if (m_ensure_multi) {
// Two 13 bytes headers plus n sets of coordinates
data.reserve(2UL * 13UL + geom.size() * (2UL * 8UL));
data.reserve(SIZE_HEADER_WITH_COUNT_AND_SRID +
SIZE_HEADER_WITH_COUNT + coords_size);
write_header(&data, wkb_multi_line, m_srid);
write_length(&data, 1);
write_linestring(&data, geom);
assert(data.size() == SIZE_HEADER_WITH_COUNT_AND_SRID +
SIZE_HEADER_WITH_COUNT + coords_size);
} else {
// 13 byte header plus n sets of coordinates
data.reserve(13UL + geom.size() * (2UL * 8UL));
data.reserve(SIZE_HEADER_WITH_COUNT_AND_SRID + coords_size);
write_linestring(&data, geom, m_srid);
assert(data.size() ==
SIZE_HEADER_WITH_COUNT_AND_SRID + coords_size);
}

return data;
Expand Down Expand Up @@ -289,6 +300,8 @@ class make_ewkb_visitor_t
}

private:
static constexpr std::size_t SIZE_COORDINATE_PAIR = 2UL * sizeof(double);

uint32_t m_srid;
bool m_ensure_multi;

Expand Down
Loading