Skip to content

Commit

Permalink
Fixed numerous MSVC warnings (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaeschke authored Aug 28, 2022
1 parent 3c6689d commit d89e32c
Show file tree
Hide file tree
Showing 45 changed files with 275 additions and 215 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
and function signatures than normal `PhTree` filters. [#26](https://github.com/tzaeschke/phtree-cpp/issues/26)

### Fixed
- Fixed compiler warnings when compiling with Visual Studio 2019.
[#74](https://github.com/tzaeschke/phtree-cpp/issues/74)
- Fixed cmake to work with Visual Studio 2019. Added tests and benchmarks to cmake.
(benchmarks still do not work with VS at the moment).
[#62](https://github.com/tzaeschke/phtree-cpp/issues/62)
- Fixed two compilation problems and a memory leak when compiling with Visual Studio 2019.
- Fixed compilation problems and a memory leak when compiling with Visual Studio 2019.
(also added `msan` support). [#64](https://github.com/tzaeschke/phtree-cpp/pull/64)

## [1.2.0] - 2022-04-14
Expand Down
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ project(phtree VERSION 1.2.0
DESCRIPTION "PH-Tree C++"
LANGUAGES CXX)


cmake_policy(SET CMP0077 NEW)

# ---------------------------------------------------------------------------------------
# Set default build to release
# ---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -33,13 +36,13 @@ option(PHTREE_BUILD_BENCHMARKS "Build benchmarks (Requires https://github.com/go
# Compiler config
# ---------------------------------------------------------------------------------------
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
if (CCACHE_FOUND)
message("CCACHE is found")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
else(CCACHE_FOUND)
else (CCACHE_FOUND)
message("CCACHE is NOT found")
endif(CCACHE_FOUND)
endif (CCACHE_FOUND)

# specify the C++ standard
if (NOT CMAKE_CXX_STANDARD)
Expand All @@ -48,16 +51,26 @@ if (NOT CMAKE_CXX_STANDARD)
endif ()

if (MSVC)
#set(CMAKE_CXX_FLAGS_RELEASE "/MT")
#set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")

# set(CMAKE_CXX_FLAGS "-DNOMINMAX ${CMAKE_CXX_FLAGS}") # exclude M$ min/max macros
# set(CMAKE_CXX_FLAGS "/wd4996 ${CMAKE_CXX_FLAGS}") # don't warn about use of plain C functions without (non-portable) "_s" suffix
# set(CMAKE_EXE_LINKER_FLAGS "/WX:NO ${CMAKE_EXE_LINKER_FLAGS}" ) # don't treat warnings as compile errors--gtest doesn't build
# #set(CMAKE_CXX_FLAGS_DEBUG "/analyze ${CMAKE_CXX_FLAGS_DEBUG}")
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
add_compile_options(/bigobj)
endif ()

# For google benchmark
if (PHTREE_BUILD_BENCHMARKS) # OR PHTREE_BUILD_ALL)
# This still doesn't work. This also breaks gtest
# See for example
# https://stackoverflow.com/questions/55376111/how-to-build-and-link-google-benchmark-using-cmake-in-windows
# https://github.com/google/benchmark/issues/1348
# https://github.com/google/benchmark/issues/639
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# set(BUILD_SHARED_LIBS TRUE) #=TRUE
# set(BENCHMARK_DOWNLOAD_DEPENDENCIES on)
# set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
endif ()
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror")
if (PHTREE_BUILD_BENCHMARKS)
Expand All @@ -77,7 +90,7 @@ if (PHTREE_BUILD_EXAMPLES OR PHTREE_BUILD_ALL)
add_subdirectory(examples)
endif ()

if (PHTREE_BUILD_BENCHMARKS OR PHTREE_BUILD_ALL)
if (!MSVC AND (PHTREE_BUILD_BENCHMARKS OR PHTREE_BUILD_ALL))
message(STATUS "Generating benchmarks")
add_subdirectory(benchmark)
endif ()
Expand Down
10 changes: 6 additions & 4 deletions benchmark/benchmark_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ auto CreateDataCLUSTER = [](auto& points,
};

auto CreateDuplicates =
[](auto& points, size_t num_unique_entries, size_t num_total_entities, std::uint32_t seed) {
[](auto& points, int num_unique_entries, size_t num_total_entities, std::uint32_t seed) {
std::default_random_engine random_engine{seed};
std::uniform_int_distribution<> distribution(0, num_unique_entries);
for (size_t i = num_unique_entries; i < num_total_entities; ++i) {
Expand All @@ -101,11 +101,13 @@ auto CreatePointDataMinMax = [](auto& points,
double world_minimum,
double world_maximum,
double fraction_of_duplicates) {
auto set_coordinate_lambda = [](auto& p, dimension_t dim, auto value) { p[dim] = value; };
auto set_coordinate_lambda = [](auto& p, dimension_t dim, auto value) {
p[dim] = static_cast < typename std::remove_reference_t<decltype(p[0])>>(value);
};
// Create at least 1 unique point
// Note that the following point generator is likely, but not guaranteed, to created unique
// points.
size_t num_unique_entries = 1 + (num_entities - 1) * (1. - fraction_of_duplicates);
int num_unique_entries = static_cast<int>(1 + (num_entities - 1) * (1. - fraction_of_duplicates));
points.reserve(num_entities);
switch (test_generator) {
case CUBE:
Expand Down Expand Up @@ -140,7 +142,7 @@ auto CreateBoxDataMinMax = [](auto& points,
// Create at least 1 unique point
// Note that the following point generator is likely, but not guaranteed, to created unique
// points.
int num_unique_entries = 1 + (num_entities - 1) * (1. - fraction_of_duplicates);
int num_unique_entries = static_cast<int>(1 + (num_entities - 1) * (1. - fraction_of_duplicates));
points.reserve(num_entities);
switch (test_generator) {
case CUBE:
Expand Down
21 changes: 11 additions & 10 deletions benchmark/erase_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace improbable::phtree::phbenchmark;
namespace {

const int GLOBAL_MAX = 10000;
using payload_t = std::uint32_t;

/*
* Benchmark for removing entries.
Expand All @@ -39,11 +40,11 @@ class IndexBenchmark {

private:
void SetupWorld(benchmark::State& state);
void Insert(benchmark::State& state, PhTree<DIM, int>& tree);
void Remove(benchmark::State& state, PhTree<DIM, int>& tree);
void Insert(benchmark::State& state, PhTree<DIM, payload_t>& tree);
void Remove(benchmark::State& state, PhTree<DIM, payload_t>& tree);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;

std::default_random_engine random_engine_;
std::uniform_int_distribution<> cube_distribution_;
Expand All @@ -66,7 +67,7 @@ template <dimension_t DIM>
void IndexBenchmark<DIM>::Benchmark(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
auto* tree = new PhTree<DIM, int>();
auto* tree = new PhTree<DIM, payload_t>();
Insert(state, *tree);
state.ResumeTiming();

Expand All @@ -91,16 +92,16 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
}

template <dimension_t DIM>
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTree<DIM, int>& tree) {
for (int i = 0; i < num_entities_; ++i) {
tree.emplace(points_[i], i);
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTree<DIM, payload_t>& tree) {
for (size_t i = 0; i < num_entities_; ++i) {
tree.emplace(points_[i], (int)i);
}
}

template <dimension_t DIM>
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTree<DIM, int>& tree) {
int n = 0;
for (int i = 0; i < num_entities_; ++i) {
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTree<DIM, payload_t>& tree) {
size_t n = 0;
for (size_t i = 0; i < num_entities_; ++i) {
n += tree.erase(points_[i]);
}

Expand Down
19 changes: 10 additions & 9 deletions benchmark/erase_d_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace improbable::phtree::phbenchmark;
namespace {

const int GLOBAL_MAX = 10000;
using payload_t = std::uint32_t;

/*
* Benchmark for removing entries.
Expand All @@ -39,11 +40,11 @@ class IndexBenchmark {

private:
void SetupWorld(benchmark::State& state);
void Insert(benchmark::State& state, PhTreeD<DIM, int>& tree);
void Remove(benchmark::State& state, PhTreeD<DIM, int>& tree);
void Insert(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);
void Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;

std::default_random_engine random_engine_;
std::uniform_real_distribution<> cube_distribution_;
Expand All @@ -66,7 +67,7 @@ template <dimension_t DIM>
void IndexBenchmark<DIM>::Benchmark(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
auto* tree = new PhTreeD<DIM, int>();
auto* tree = new PhTreeD<DIM, payload_t>();
Insert(state, *tree);
state.ResumeTiming();

Expand All @@ -91,16 +92,16 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
}

template <dimension_t DIM>
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, int>& tree) {
for (int i = 0; i < num_entities_; ++i) {
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, payload_t>& tree) {
for (payload_t i = 0; i < num_entities_; ++i) {
tree.emplace(points_[i], i);
}
}

template <dimension_t DIM>
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, int>& tree) {
int n = 0;
for (int i = 0; i < num_entities_; ++i) {
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree) {
size_t n = 0;
for (size_t i = 0; i < num_entities_; ++i) {
n += tree.erase(points_[i]);
}

Expand Down
6 changes: 3 additions & 3 deletions benchmark/extent_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IndexBenchmark {
void QueryWorld(benchmark::State& state);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;

PhTree<DIM, int> tree_;
std::default_random_engine random_engine_;
Expand Down Expand Up @@ -73,8 +73,8 @@ template <dimension_t DIM>
void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
logging::info("Setting up world with {} entities and {} dimensions.", num_entities_, DIM);
CreatePointData<DIM>(points_, data_type_, num_entities_, 0, GLOBAL_MAX);
for (int i = 0; i < num_entities_; ++i) {
tree_.emplace(points_[i], i);
for (size_t i = 0; i < num_entities_; ++i) {
tree_.emplace(points_[i], (int)i);
}

state.counters["total_result_count"] = benchmark::Counter(0);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/extent_benchmark_weird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IndexBenchmark {
void QueryWorld(benchmark::State& state);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;

PhTree<DIM, int> tree_;
std::default_random_engine random_engine_;
Expand Down Expand Up @@ -81,8 +81,8 @@ template <dimension_t DIM>
void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
logging::info("Setting up world with {} entities and {} dimensions.", num_entities_, DIM);
CreatePointData<DIM>(points_, data_type_, num_entities_, 0, GLOBAL_MAX);
for (int i = 0; i < num_entities_; ++i) {
tree_.emplace(points_[i], i);
for (size_t i = 0; i < num_entities_; ++i) {
tree_.emplace(points_[i], (int)i);
}

state.counters["total_result_count"] = benchmark::Counter(0);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/find_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class IndexBenchmark {
int QueryWorldFind(benchmark::State& state);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;
const QueryType query_type_;

PhTree<DIM, int> tree_;
Expand Down Expand Up @@ -102,8 +102,8 @@ template <dimension_t DIM>
void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
logging::info("Setting up world with {} entities and {} dimensions.", num_entities_, DIM);
CreatePointData<DIM>(points_, data_type_, num_entities_, 0, GLOBAL_MAX);
for (int i = 0; i < num_entities_; ++i) {
tree_.emplace(points_[i], i);
for (size_t i = 0; i < num_entities_; ++i) {
tree_.emplace(points_[i], (int)i);
}

state.counters["total_result_count"] = benchmark::Counter(0);
Expand Down
21 changes: 11 additions & 10 deletions benchmark/hd_erase_d_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using namespace improbable::phtree::phbenchmark;
namespace {

const int GLOBAL_MAX = 10000;
using payload_t = std::uint32_t;

/*
* Benchmark for removing entries.
Expand All @@ -38,11 +39,11 @@ class IndexBenchmark {

private:
void SetupWorld(benchmark::State& state);
void Insert(benchmark::State& state, PhTreeD<DIM, int>& tree);
void Remove(benchmark::State& state, PhTreeD<DIM, int>& tree);
void Insert(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);
void Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;

std::default_random_engine random_engine_;
std::uniform_real_distribution<> cube_distribution_;
Expand All @@ -64,7 +65,7 @@ template <dimension_t DIM>
void IndexBenchmark<DIM>::Benchmark(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
auto* tree = new PhTreeD<DIM, int>();
auto* tree = new PhTreeD<DIM, payload_t>();
Insert(state, *tree);
state.ResumeTiming();

Expand All @@ -89,16 +90,16 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
}

template <dimension_t DIM>
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, int>& tree) {
for (int i = 0; i < num_entities_; ++i) {
tree.emplace(points_[i], i);
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, payload_t>& tree) {
for (size_t i = 0; i < num_entities_; ++i) {
tree.emplace(points_[i], (int)i);
}
}

template <dimension_t DIM>
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, int>& tree) {
int n = 0;
for (int i = 0; i < num_entities_; ++i) {
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree) {
size_t n = 0;
for (size_t i = 0; i < num_entities_; ++i) {
n += tree.erase(points_[i]);
}

Expand Down
6 changes: 3 additions & 3 deletions benchmark/hd_insert_d_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IndexBenchmark {
void Insert(benchmark::State& state, Index& tree);

const TestGenerator data_type_;
const int num_entities_;
const size_t num_entities_;
std::vector<PhPointD<DIM>> points_;
};

Expand Down Expand Up @@ -84,9 +84,9 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {

template <dimension_t DIM>
void IndexBenchmark<DIM>::Insert(benchmark::State& state, Index& tree) {
for (int i = 0; i < num_entities_; ++i) {
for (size_t i = 0; i < num_entities_; ++i) {
PhPointD<DIM>& p = points_[i];
tree.emplace(p, i);
tree.emplace(p, (int)i);
}

state.counters["total_put_count"] += num_entities_;
Expand Down
Loading

0 comments on commit d89e32c

Please sign in to comment.