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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Code must be written in the
always be used for code blocks, even one-liners.

Names should use underscores, not camel case, with class/struct names ending in
`_t`. Template parameters must use all upper case.
`_t`. Constants and template parameters must use all upper case.

Header files should be included in the following order, each group in their own
block:
Expand Down
2 changes: 1 addition & 1 deletion src/db-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void db_copy_thread_t::send_command(db_cmd_t &&buffer)

std::unique_lock<std::mutex> lock{m_shared.queue_mutex};
m_shared.queue_full_cond.wait(lock, [&] {
return m_shared.worker_queue.size() < db_cmd_copy_t::Max_buffers;
return m_shared.worker_queue.size() < db_cmd_copy_t::MAX_BUFFERS;
});

m_shared.worker_queue.push_back(std::move(buffer));
Expand Down
16 changes: 8 additions & 8 deletions src/db-copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class db_deleter_by_id_t
* There is a trade-off here between sending as few DELETE SQL as
* possible and keeping the size of the deletable vector managable.
*/
static constexpr std::size_t Max_entries = 1000000;
static constexpr std::size_t MAX_ENTRIES = 1000000;

public:
bool has_data() const noexcept { return !m_deletables.empty(); }
Expand All @@ -89,7 +89,7 @@ class db_deleter_by_id_t
void delete_rows(std::string const &table, std::string const &column,
pg_conn_t const &db_connection);

bool is_full() const noexcept { return m_deletables.size() > Max_entries; }
bool is_full() const noexcept { return m_deletables.size() > MAX_ENTRIES; }

private:
/// Vector with object to delete before copying
Expand All @@ -105,7 +105,7 @@ class db_deleter_by_type_and_id_t
* There is a trade-off here between sending as few DELETE SQL as
* possible and keeping the size of the deletable vector managable.
*/
static constexpr std::size_t Max_entries = 1000000;
static constexpr std::size_t MAX_ENTRIES = 1000000;

struct item_t
{
Expand All @@ -129,7 +129,7 @@ class db_deleter_by_type_and_id_t
void delete_rows(std::string const &table, std::string const &column,
pg_conn_t const &db_connection);

bool is_full() const noexcept { return m_deletables.size() > Max_entries; }
bool is_full() const noexcept { return m_deletables.size() > MAX_ENTRIES; }

private:
/// Vector with object to delete before copying
Expand All @@ -145,7 +145,7 @@ struct db_cmd_copy_t
* to speed up processing. Currently a one-size fits all value.
* Needs more testing and individual values per queue.
*/
static constexpr std::size_t Max_buf_size = 10 * 1024 * 1024;
static constexpr std::size_t MAX_BUF_SIZE = 10UL * 1024UL * 1024UL;

/**
* Maximum length of the queue with COPY data.
Expand All @@ -155,7 +155,7 @@ struct db_cmd_copy_t
* be full and it is better to keep the queue smaller to reduce memory
* usage. Current value is just assumed to be a reasonable trade off.
*/
static constexpr std::size_t Max_buffers = 10;
static constexpr std::size_t MAX_BUFFERS = 10;

/// Name of the target table for the copy operation
std::shared_ptr<db_target_descr_t> target;
Expand All @@ -167,7 +167,7 @@ struct db_cmd_copy_t
explicit db_cmd_copy_t(std::shared_ptr<db_target_descr_t> t)
: target(std::move(t))
{
buffer.reserve(Max_buf_size);
buffer.reserve(MAX_BUF_SIZE);
}

explicit operator bool() const noexcept { return target != nullptr; }
Expand All @@ -182,7 +182,7 @@ class db_cmd_copy_delete_t : public db_cmd_copy_t
/// Return true if the buffer is filled up.
bool is_full() const noexcept
{
return (buffer.size() > Max_buf_size - 100) || m_deleter.is_full();
return (buffer.size() > MAX_BUF_SIZE - 100) || m_deleter.is_full();
}

bool has_deletables() const noexcept { return m_deleter.has_data(); }
Expand Down
10 changes: 5 additions & 5 deletions src/expire-tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ geom::point_t expire_tiles::coords_to_tile(geom::point_t const &point)
{
auto const c = m_projection->target_to_tile(point);

return {m_map_width * (0.5 + c.x() / tile_t::earth_circumference),
m_map_width * (0.5 - c.y() / tile_t::earth_circumference)};
return {m_map_width * (0.5 + c.x() / tile_t::EARTH_CIRCUMFERENCE),
m_map_width * (0.5 - c.y() / tile_t::EARTH_CIRCUMFERENCE)};
}

void expire_tiles::from_point_list(geom::point_list_t const &list,
Expand Down Expand Up @@ -224,14 +224,14 @@ int expire_tiles::from_bbox(geom::box_t const &box,

double const width = box.width();
double const height = box.height();
if (width > tile_t::half_earth_circumference + 1) {
if (width > tile_t::HALF_EARTH_CIRCUMFERENCE + 1) {
/* Over half the planet's width within the bounding box - assume the
box crosses the international date line and split it into two boxes */
int ret = from_bbox({-tile_t::half_earth_circumference, box.min_y(),
int ret = from_bbox({-tile_t::HALF_EARTH_CIRCUMFERENCE, box.min_y(),
box.min_x(), box.max_y()},
expire_config);
ret += from_bbox({box.max_x(), box.min_y(),
tile_t::half_earth_circumference, box.max_y()},
tile_t::HALF_EARTH_CIRCUMFERENCE, box.max_y()},
expire_config);
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/gen/osm2pgsql-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

namespace {

constexpr std::size_t const max_force_single_thread = 4;
constexpr std::size_t const MAX_FORCE_SINGLE_THREAD = 4;

struct tile_extent
{
Expand Down Expand Up @@ -496,7 +496,7 @@ class genproc_t
}
}
log_debug("Need to process {} tiles.", tile_list.size());
if (m_jobs == 1 || tile_list.size() < max_force_single_thread) {
if (m_jobs == 1 || tile_list.size() < MAX_FORCE_SINGLE_THREAD) {
log_debug("Running in single-threaded mode.");
tile_processor_t tp{generalizer, tile_list.size()};
while (!tile_list.empty()) {
Expand Down
6 changes: 3 additions & 3 deletions src/gen/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tracer_t::trace(canvas_t const &canvas, tile_t const &tile, double min_area)
prepare(canvas);

potrace_bitmap_t const bitmap{int(canvas.size()), int(canvas.size()),
int(canvas.size() / bits_per_word),
int(canvas.size() / BITS_PER_WORD),
m_bits.data()};

std::unique_ptr<potrace_state_t, potrace_state_deleter> state{
Expand All @@ -64,9 +64,9 @@ void tracer_t::reset()
void tracer_t::prepare(canvas_t const &canvas) noexcept
{
std::size_t const size = canvas.size();
assert(size % bits_per_word == 0);
assert(size % BITS_PER_WORD == 0);

m_bits.reserve((size * size) / bits_per_word);
m_bits.reserve((size * size) / BITS_PER_WORD);

for (unsigned char const *d = canvas.begin(); d != canvas.end(); d += 8) {
auto w = bit_squeeze(0, d);
Expand Down
2 changes: 1 addition & 1 deletion src/gen/tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class tracer_t
std::size_t num_points() const noexcept { return m_num_points; }

private:
static constexpr auto const bits_per_word = sizeof(potrace_word) * 8;
static constexpr auto const BITS_PER_WORD = sizeof(potrace_word) * 8;

geom::point_t make_point(potrace_dpoint_t const &p) const noexcept;

Expand Down
4 changes: 2 additions & 2 deletions src/geom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ class multigeometry_t
using iterator = typename std::vector<GEOM>::iterator;
using value_type = GEOM;

static constexpr bool const for_point = std::is_same_v<GEOM, point_t>;
static constexpr bool const FOR_POINT = std::is_same_v<GEOM, point_t>;

[[nodiscard]] std::size_t num_geometries() const noexcept
{
return m_geometry.size();
}

GEOM &
add_geometry(typename std::conditional_t<for_point, point_t, GEOM &&> geom)
add_geometry(typename std::conditional_t<FOR_POINT, point_t, GEOM &&> geom)
{
m_geometry.push_back(std::forward<GEOM>(geom));
return m_geometry.back();
Expand Down
6 changes: 3 additions & 3 deletions src/lua-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ void *luaX_get_context(lua_State *lua_state) noexcept
namespace {

// Unique key for lua registry
constexpr char const *const osm2pgsql_output_flex = "osm2pgsql_output_flex";
constexpr char const *const OSM2PGSQL_OUTPUT_FLEX = "osm2pgsql_output_flex";

} // anonymous namespace

void luaX_set_context(lua_State *lua_state, void *ptr) noexcept
{
assert(lua_state);
assert(ptr);
lua_pushlightuserdata(lua_state, (void *)osm2pgsql_output_flex);
lua_pushlightuserdata(lua_state, (void *)OSM2PGSQL_OUTPUT_FLEX);
lua_pushlightuserdata(lua_state, ptr);
lua_settable(lua_state, LUA_REGISTRYINDEX);
}

void *luaX_get_context(lua_State *lua_state) noexcept
{
assert(lua_state);
lua_pushlightuserdata(lua_state, (void *)osm2pgsql_output_flex);
lua_pushlightuserdata(lua_state, (void *)OSM2PGSQL_OUTPUT_FLEX);
lua_gettable(lua_state, LUA_REGISTRYINDEX);
auto *const ptr = lua_touserdata(lua_state, -1);
assert(ptr);
Expand Down
12 changes: 6 additions & 6 deletions src/node-locations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ osmium::Location node_locations_t::get(osmid_t id) const
osmium::DeltaDecode<int64_t> dx;
osmium::DeltaDecode<int64_t> dy;

for (std::size_t n = 0; n < block_size && begin != end; ++n) {
for (std::size_t n = 0; n < BLOCK_SIZE && begin != end; ++n) {
auto const bid = did.update(
static_cast<int64_t>(protozero::decode_varint(&begin, end)));
auto const x = static_cast<int32_t>(dx.update(
Expand All @@ -83,13 +83,13 @@ osmium::Location node_locations_t::get(osmid_t id) const

void node_locations_t::log_stats()
{
constexpr auto const mbyte = 1024 * 1024;
constexpr auto const MBYTE = 1024 * 1024;
log_debug("Node locations cache:");
log_debug(" num locations stored: {}", m_count);
log_debug(" bytes overall: {}MB", used_memory() / mbyte);
log_debug(" data capacity: {}MB", m_data.capacity() / mbyte);
log_debug(" data size: {}MB", m_data.size() / mbyte);
log_debug(" index used memory: {}MB", m_index.used_memory() / mbyte);
log_debug(" bytes overall: {}MB", used_memory() / MBYTE);
log_debug(" data capacity: {}MB", m_data.capacity() / MBYTE);
log_debug(" data size: {}MB", m_data.size() / MBYTE);
log_debug(" index used memory: {}MB", m_index.used_memory() / MBYTE);
}

void node_locations_t::clear()
Expand Down
14 changes: 7 additions & 7 deletions src/node-locations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ class node_locations_t
void clear();

private:
/**
* The block size used for internal blocks. The larger the block size
* the less memory is consumed but the more expensive the access is.
*/
static constexpr const std::size_t BLOCK_SIZE = 32;

bool first_entry_in_block() const noexcept
{
return m_count % block_size == 0;
return m_count % BLOCK_SIZE == 0;
}

/// The maximum number of bytes an entry will need in storage.
Expand All @@ -97,12 +103,6 @@ class node_locations_t
(m_data.size() + max_bytes_per_entry() >= m_data.capacity());
}

/**
* The block size used for internal blocks. The larger the block size
* the less memory is consumed but the more expensive the access is.
*/
static constexpr const std::size_t block_size = 32;

ordered_index_t m_index;
std::string m_data;

Expand Down
2 changes: 1 addition & 1 deletion src/ordered-index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ordered_index_t::add(osmid_t id, std::size_t offset)
}
m_ranges.emplace_back(id, offset, m_block_size);
m_capacity += m_block_size;
if (m_block_size < max_block_size) {
if (m_block_size < MAX_BLOCK_SIZE) {
m_block_size <<= 1U;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ordered-index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class ordered_index_t

std::pair<osmid_t, std::size_t> get_internal(osmid_t id) const noexcept;

static constexpr std::size_t const max_block_size = 16UL * 1024UL * 1024UL;
static constexpr std::size_t const MAX_BLOCK_SIZE = 16UL * 1024UL * 1024UL;

std::vector<range_entry> m_ranges;
std::size_t m_block_size;
Expand Down
12 changes: 6 additions & 6 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ void push_osm_object_to_lua_stack(lua_State *lua_state,
* timestamp, changeset, uid, user). For ways there are 2 more (is_closed,
* nodes), for relations 1 more (members).
*/
constexpr int const max_table_size = 10;
constexpr int const MAX_TABLE_SIZE = 10;

lua_createtable(lua_state, 0, max_table_size);
lua_createtable(lua_state, 0, MAX_TABLE_SIZE);

luaX_add_table_int(lua_state, "id", object.id());

Expand Down Expand Up @@ -240,12 +240,12 @@ typename CONTAINER::value_type &get_from_idx_param(lua_State *lua_state,

std::size_t get_nodes(middle_query_t const &middle, osmium::Way *way)
{
constexpr std::size_t const max_missing_nodes = 100;
constexpr std::size_t const MAX_MISSING_NODES = 100;
static std::size_t count_missing_nodes = 0;

auto const count = middle.nodes_get_list(&way->nodes());

if (count_missing_nodes <= max_missing_nodes &&
if (count_missing_nodes <= MAX_MISSING_NODES &&
count != way->nodes().size()) {
util::string_joiner_t id_list{','};
for (auto const &nr : way->nodes()) {
Expand All @@ -257,10 +257,10 @@ std::size_t get_nodes(middle_query_t const &middle, osmium::Way *way)

log_debug("Missing nodes in way {}: {}", way->id(), id_list());

if (count_missing_nodes > max_missing_nodes) {
if (count_missing_nodes > MAX_MISSING_NODES) {
log_debug("Reported more than {} missing nodes, no further missing "
"nodes will be reported!",
max_missing_nodes);
MAX_MISSING_NODES);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/pgsql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,11 @@ class pg_conn_t
// It needs to be large enough to hold all parameters without resizing
// so that pointers into the strings in that vector remain valid
// after new parameters have been added.
constexpr auto const total_buffers_needed =
constexpr auto const TOTAL_BUFFERS_NEEDED =
(0 + ... + buffers_needed<std::decay_t<TArgs>>());

std::vector<std::string> exec_params;
exec_params.reserve(total_buffers_needed);
exec_params.reserve(TOTAL_BUFFERS_NEEDED);

std::array<int, sizeof...(params)> lengths = {0};
std::array<int, sizeof...(params)> bins = {0};
Expand Down
8 changes: 4 additions & 4 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

namespace {

constexpr char const *const properties_table = "osm2pgsql_properties";
constexpr char const *const PROPERTIES_TABLE = "osm2pgsql_properties";

} // anonymous namespace

properties_t::properties_t(connection_params_t connection_params,
std::string schema)
: m_connection_params(std::move(connection_params)),
m_schema(std::move(schema)),
m_has_properties_table(has_table(m_schema, properties_table))
m_has_properties_table(has_table(m_schema, PROPERTIES_TABLE))
{
assert(!m_schema.empty());
log_debug("Found properties table '{}': {}.", properties_table,
log_debug("Found properties table '{}': {}.", PROPERTIES_TABLE,
m_has_properties_table);
}

Expand Down Expand Up @@ -159,5 +159,5 @@ bool properties_t::load()

std::string properties_t::table_name() const
{
return qualified_name(m_schema, properties_table);
return qualified_name(m_schema, PROPERTIES_TABLE);
}
4 changes: 2 additions & 2 deletions src/tagtransform-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct layers_type
bool roads;
};

constexpr std::array<layers_type, 25> const layers = {
constexpr std::array<layers_type, 25> const LAYERS = {
{{"proposed", 1, false}, {"construction", 2, false},
{"steps", 10, false}, {"cycleway", 10, false},
{"bridleway", 10, false}, {"footway", 10, false},
Expand Down Expand Up @@ -60,7 +60,7 @@ void add_z_order(taglist_t *tags, bool *roads)
*roads = false;

if (highway) {
for (auto const &layer : layers) {
for (auto const &layer : LAYERS) {
if (*highway == layer.highway) {
z_order += layer.offset;
*roads = layer.roads;
Expand Down
Loading