Skip to content

Commit 0d7d141

Browse files
Issue #10 - Fix non-standard c++ and some cleanup (#11)
1 parent c6c25fe commit 0d7d141

File tree

15 files changed

+136
-124
lines changed

15 files changed

+136
-124
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
- Nothing yet.
99

10+
## [1.0.1] - 2021-05-06
11+
### Changed
12+
- replaced compilation flag `-fpermissive` with `-Werror`, and fixed all warnings/errors, see issue #10
1013

1114
## [1.0.0] - 2021-03-23
1215
### Added
@@ -47,6 +50,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4750
- Nothing.
4851

4952

50-
[Unreleased]: https://github.com/improbable-eng/phtree-cpp/compare/v1.0.0...HEAD
53+
[Unreleased]: https://github.com/improbable-eng/phtree-cpp/compare/v1.0.1...HEAD
54+
[1.0.1]: https://github.com/improbable-eng/phtree-cpp/compare/v1.0.0...v1.0.1
5155
[1.0.0]: https://github.com/improbable-eng/phtree-cpp/compare/v0.1.0...v1.0.0
5256
[0.2.0]: https://github.com/improbable-eng/phtree-cpp/compare/v0.1.0...v0.2.0

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.14)
22

33
# set the project name
4-
project(PH_Tree_Main VERSION 1.0.0
4+
project(PH_Tree_Main VERSION 1.0.1
55
DESCRIPTION "PH-Tree C++"
66
LANGUAGES CXX)
77

@@ -12,7 +12,7 @@ endif()
1212
# specify the C++ standard
1313
set(CMAKE_CXX_STANDARD 17)
1414
set(CMAKE_CXX_STANDARD_REQUIRED True)
15-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fpermissive")
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror")
1616
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
1717

1818
add_subdirectory(phtree)

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ cmake --build .
547547

548548
The PH-Tree is discussed in the follwoing publications and reports:
549549

550-
*
551550
- T. Zaeschke, C. Zimmerli, M.C. Norrie:
552551
"The PH-Tree -- A Space-Efficient Storage Structure and Multi-Dimensional Index", (SIGMOD 2014)
553552
- T. Zaeschke: "The PH-Tree Revisited", (2015)

phtree/common/converter.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define PHTREE_COMMON_CONVERTER_H
1919

2020
#include "base_types.h"
21+
#include <cstring>
2122

2223
/*
2324
* PLEASE do not include this file directly, it is included via common.h.
@@ -37,13 +38,18 @@ class ScalarConverterIEEE {
3738
// This result is properly ordered longs for all positive doubles. Negative values have
3839
// inverse ordering. For negative doubles, we therefore simply invert them to make them
3940
// sortable, however the sign must be inverted again to stay negative.
40-
scalar_64_t r = reinterpret_cast<scalar_64_t&>(value);
41+
// Also, we could use reinterpret_cast, but that fails on GCC. Using memcpy results in the
42+
// same asm instructions as reinterpret_cast().
43+
scalar_64_t r;
44+
memcpy(&r, &value, sizeof(r));
4145
return r >= 0 ? r : r ^ 0x7FFFFFFFFFFFFFFFL;
4246
}
4347

4448
static double post(scalar_64_t value) {
4549
auto v = value >= 0 ? value : value ^ 0x7FFFFFFFFFFFFFFFL;
46-
return reinterpret_cast<double&>(v);
50+
double r;
51+
memcpy(&r, &v, sizeof(r));
52+
return r;
4753
}
4854

4955
static scalar_32_t pre(float value) {
@@ -52,13 +58,16 @@ class ScalarConverterIEEE {
5258
// This result is properly ordered longs for all positive doubles. Negative values have
5359
// inverse ordering. For negative doubles, we therefore simply invert them to make them
5460
// sortable, however the sign must be inverted again to stay negative.
55-
scalar_32_t r = reinterpret_cast<scalar_32_t&>(value);
61+
scalar_32_t r;
62+
memcpy(&r, &value, sizeof(r));
5663
return r >= 0 ? r : r ^ 0x7FFFFFFFL;
5764
}
5865

5966
static float post(scalar_32_t value) {
6067
auto v = value >= 0 ? value : value ^ 0x7FFFFFFFL;
61-
return reinterpret_cast<float&>(v);
68+
float r;
69+
memcpy(&r, &v, sizeof(r));
70+
return r;
6271
}
6372
};
6473

phtree/v16/debug_helper_v16.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#ifndef PHTREE_V16_DEBUG_HELPER_H
1818
#define PHTREE_V16_DEBUG_HELPER_H
1919

20-
#include "node.h"
2120
#include "../common/common.h"
2221
#include "../common/debug_helper.h"
22+
#include "node.h"
2323
#include "phtree_v16.h"
2424
#include <string>
2525

@@ -30,12 +30,11 @@ class PhTreeV16;
3030

3131
template <dimension_t DIM, typename T, typename SCALAR>
3232
class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
33-
using Key = PhPoint<DIM, SCALAR>;
34-
using Node = Node<DIM, T, SCALAR>;
35-
using Entry = Entry<DIM, T, SCALAR>;
33+
using KeyT = PhPoint<DIM, SCALAR>;
34+
using NodeT = Node<DIM, T, SCALAR>;
3635

3736
public:
38-
DebugHelperV16(const Node& root, size_t size) : root_{root}, size_{size} {}
37+
DebugHelperV16(const NodeT& root, size_t size) : root_{root}, size_{size} {}
3938

4039
/*
4140
* Depending on the detail parameter this returns:
@@ -58,7 +57,7 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
5857
ToStringPlain(os, root_);
5958
break;
6059
case Enum::tree:
61-
ToStringTree(os, 0, root_, Key(), true);
60+
ToStringTree(os, 0, root_, KeyT{}, true);
6261
break;
6362
}
6463
return os.str();
@@ -83,9 +82,9 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
8382
}
8483

8584
private:
86-
void ToStringPlain(std::ostringstream& os, const Node& node) const {
85+
void ToStringPlain(std::ostringstream& os, const NodeT& node) const {
8786
for (auto& it : node.Entries()) {
88-
const Entry& o = it.second;
87+
const auto& o = it.second;
8988
// inner node?
9089
if (o.IsNode()) {
9190
ToStringPlain(os, o.GetNode());
@@ -99,8 +98,8 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
9998
void ToStringTree(
10099
std::ostringstream& sb,
101100
bit_width_t current_depth,
102-
const Node& node,
103-
const Key& prefix,
101+
const NodeT& node,
102+
const KeyT& prefix,
104103
bool printValue) const {
105104
std::string ind = "*";
106105
for (bit_width_t i = 0; i < current_depth; ++i) {
@@ -142,7 +141,7 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
142141
}
143142
}
144143

145-
const Node& root_;
144+
const NodeT& root_;
146145
const size_t size_;
147146
};
148147
} // namespace improbable::phtree::v16

phtree/v16/entry.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#ifndef PHTREE_V16_ENTRY_H
1818
#define PHTREE_V16_ENTRY_H
1919

20-
#include "node.h"
2120
#include "../../phtree/common/common.h"
21+
#include "node.h"
2222
#include <cassert>
2323
#include <cstdint>
2424
#include <memory>
@@ -39,56 +39,57 @@ class Node;
3939
*/
4040
template <dimension_t DIM, typename T, typename SCALAR>
4141
class Entry {
42-
using Key = PhPoint<DIM, SCALAR>;
43-
using Value = std::remove_const_t<T>;
44-
using Node = Node<DIM, T, SCALAR>;
42+
using KeyT = PhPoint<DIM, SCALAR>;
43+
using ValueT = std::remove_const_t<T>;
44+
using NodeT = Node<DIM, T, SCALAR>;
4545

4646
public:
47-
Entry() : kd_key_(), value_{std::in_place_type<Value>, T{}} {}
47+
Entry() : kd_key_(), value_{std::in_place_type<ValueT>, T{}} {}
4848

4949
/*
5050
* Construct entry with existing node.
5151
*/
52-
Entry(const Key& k, std::unique_ptr<Node>&& node)
52+
Entry(const KeyT& k, std::unique_ptr<NodeT>&& node)
5353
: kd_key_{k}
54-
, value_{std::in_place_type<std::unique_ptr<Node>>, std::forward<std::unique_ptr<Node>>(node)} {
55-
}
54+
, value_{
55+
std::in_place_type<std::unique_ptr<NodeT>>, std::forward<std::unique_ptr<NodeT>>(node)} {}
5656

5757
/*
5858
* Construct entry with a new node.
5959
*/
6060
Entry(bit_width_t infix_len, bit_width_t postfix_len)
6161
: kd_key_()
62-
, value_{std::in_place_type<std::unique_ptr<Node>>,
63-
std::make_unique<Node>(infix_len, postfix_len)} {}
62+
, value_{
63+
std::in_place_type<std::unique_ptr<NodeT>>,
64+
std::make_unique<NodeT>(infix_len, postfix_len)} {}
6465

6566
/*
6667
* Construct entry with new T or moved T.
6768
*/
6869
template <typename... _Args>
69-
explicit Entry(const Key& k, _Args&&... __args)
70-
: kd_key_{k}, value_{std::in_place_type<Value>, std::forward<_Args>(__args)...} {}
70+
explicit Entry(const KeyT& k, _Args&&... __args)
71+
: kd_key_{k}, value_{std::in_place_type<ValueT>, std::forward<_Args>(__args)...} {}
7172

72-
[[nodiscard]] const Key& GetKey() const {
73+
[[nodiscard]] const KeyT& GetKey() const {
7374
return kd_key_;
7475
}
7576

7677
[[nodiscard]] bool IsValue() const {
77-
return std::holds_alternative<Value>(value_);
78+
return std::holds_alternative<ValueT>(value_);
7879
}
7980

8081
[[nodiscard]] bool IsNode() const {
81-
return std::holds_alternative<std::unique_ptr<Node>>(value_);
82+
return std::holds_alternative<std::unique_ptr<NodeT>>(value_);
8283
}
8384

8485
[[nodiscard]] T& GetValue() const {
8586
assert(IsValue());
86-
return const_cast<T&>(std::get<Value>(value_));
87+
return const_cast<T&>(std::get<ValueT>(value_));
8788
}
8889

89-
[[nodiscard]] Node& GetNode() const {
90+
[[nodiscard]] NodeT& GetNode() const {
9091
assert(IsNode());
91-
return *std::get<std::unique_ptr<Node>>(value_);
92+
return *std::get<std::unique_ptr<NodeT>>(value_);
9293
}
9394

9495
void ReplaceNodeWithDataFromEntry(Entry&& other) {
@@ -98,14 +99,14 @@ class Entry {
9899
// 'value_' points indirectly to 'entry' so we have to remove `entity's` content before
99100
// assigning anything to `value_` here. Otherwise the assignment would destruct the previous
100101
// content and, by reachability, `entity's` content.
101-
auto old_node = std::get<std::unique_ptr<Node>>(value_).release();
102+
auto old_node = std::get<std::unique_ptr<NodeT>>(value_).release();
102103
value_ = std::move(other.value_);
103104
delete old_node;
104105
}
105106

106107
private:
107-
Key kd_key_;
108-
std::variant<Value, std::unique_ptr<Node>> value_;
108+
KeyT kd_key_;
109+
std::variant<ValueT, std::unique_ptr<NodeT>> value_;
109110
};
110111
} // namespace improbable::phtree::v16
111112

phtree/v16/for_each.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#ifndef PHTREE_V16_FOR_EACH_H
1818
#define PHTREE_V16_FOR_EACH_H
1919

20-
#include "iterator_simple.h"
2120
#include "../common/common.h"
21+
#include "iterator_simple.h"
2222

2323
namespace improbable::phtree::v16 {
2424

@@ -32,20 +32,20 @@ class ForEach {
3232
using KeyExternal = typename CONVERT::KeyExternal;
3333
using KeyInternal = typename CONVERT::KeyInternal;
3434
using SCALAR = typename CONVERT::ScalarInternal;
35-
using Entry = Entry<DIM, T, SCALAR>;
36-
using Node = Node<DIM, T, SCALAR>;
35+
using EntryT = Entry<DIM, T, SCALAR>;
36+
using NodeT = Node<DIM, T, SCALAR>;
3737

3838
public:
3939
ForEach(const CONVERT& converter, CALLBACK_FN& callback, FILTER filter)
4040
: converter_{converter}, callback_{callback}, filter_(std::move(filter)) {}
4141

42-
void run(const Entry& root) {
42+
void run(const EntryT& root) {
4343
assert(root.IsNode());
4444
TraverseNode(root.GetKey(), root.GetNode());
4545
}
4646

4747
private:
48-
void TraverseNode(const KeyInternal& key, const Node& node) {
48+
void TraverseNode(const KeyInternal& key, const NodeT& node) {
4949
auto iter = node.Entries().begin();
5050
auto end = node.Entries().end();
5151
for (; iter != end; ++iter) {

phtree/v16/for_each_hc.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#ifndef PHTREE_V16_FOR_EACH_HC_H
1818
#define PHTREE_V16_FOR_EACH_HC_H
1919

20-
#include "iterator_simple.h"
2120
#include "../common/common.h"
21+
#include "iterator_simple.h"
2222

2323
namespace improbable::phtree::v16 {
2424

@@ -39,8 +39,8 @@ class ForEachHC {
3939
using KeyExternal = typename CONVERT::KeyExternal;
4040
using KeyInternal = typename CONVERT::KeyInternal;
4141
using SCALAR = typename CONVERT::ScalarInternal;
42-
using Entry = Entry<DIM, T, SCALAR>;
43-
using Node = Node<DIM, T, SCALAR>;
42+
using EntryT = Entry<DIM, T, SCALAR>;
43+
using NodeT = Node<DIM, T, SCALAR>;
4444

4545
public:
4646
ForEachHC(
@@ -55,13 +55,13 @@ class ForEachHC {
5555
, callback_{callback}
5656
, filter_(std::move(filter)) {}
5757

58-
void run(const Entry& root) {
58+
void run(const EntryT& root) {
5959
assert(root.IsNode());
6060
TraverseNode(root.GetKey(), root.GetNode());
6161
}
6262

6363
private:
64-
void TraverseNode(const KeyInternal& key, const Node& node) {
64+
void TraverseNode(const KeyInternal& key, const NodeT& node) {
6565
hc_pos_t mask_lower = 0;
6666
hc_pos_t mask_upper = 0;
6767
CalcLimits(node.GetPostfixLen(), key, mask_lower, mask_upper);
@@ -90,7 +90,7 @@ class ForEachHC {
9090
}
9191
}
9292

93-
bool CheckNode(const KeyInternal& key, const Node& node) const {
93+
bool CheckNode(const KeyInternal& key, const NodeT& node) const {
9494
// Check if the node overlaps with the query box.
9595
// An infix with len=0 implies that at least part of the child node overlaps with the query,
9696
// otherwise the bit mask checking would have returned 'false'.
@@ -108,7 +108,7 @@ class ForEachHC {
108108
return ApplyFilter(key, node);
109109
}
110110

111-
[[nodiscard]] bool ApplyFilter(const KeyInternal& key, const Node& node) const {
111+
[[nodiscard]] bool ApplyFilter(const KeyInternal& key, const NodeT& node) const {
112112
return filter_.IsNodeValid(key, node.GetPostfixLen() + 1);
113113
}
114114

0 commit comments

Comments
 (0)