Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 1.2.0 from fork #36

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix for each postlen / #2 (#3)
  • Loading branch information
tzaeschke authored Feb 22, 2022
commit 291d96023d654c0aa0a8c1b223cb1e8d51e7ce79
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Changed
- Fixed issue #2: for_each(callback, filter) was traversing too many nodes.
- Build improvements for bazel/cmake

## [1.1.1] - 2022-01-30
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ tree.estimate_count(query);

#### Queries

* For-each over all elements: `tree.fore_each(callback);`
* For-each over all elements: `tree.for_each(callback);`
* Iterator over all elements: `auto iterator = tree.begin();`
* For-each with box shaped window queries: `tree.fore_each(PhBoxD(min, max), callback);`
* For-each with box shaped window queries: `tree.for_each(PhBoxD(min, max), callback);`
* Iterator for box shaped window queries: `auto q = tree.begin_query(PhBoxD(min, max));`
* Iterator for _k_ nearest neighbor queries: `auto q = tree.begin_knn_query(k, center_point, distance_function);`
* Custom query shapes, such as spheres: `tree.for_each(callback, FilterSphere(center, radius, tree.converter()));`
Expand Down
26 changes: 26 additions & 0 deletions phtree/phtree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,32 @@ TEST(PhTreeTest, TestWindowQuery1) {
ASSERT_EQ(N, n);
}

TEST(PhTreeTest, TestWindowQuery1_WithFilter) {
size_t N = 1000;
const dimension_t dim = 3;
TestTree<dim, Id> tree;
std::vector<TestPoint<dim>> points;
populate(tree, points, N);

struct Counter {
void operator()(TestPoint<dim>, Id& t) {
++n_;
id_ = t;
}
Id id_{};
size_t n_ = 0;
};

for (size_t i = 0; i < N; i++) {
TestPoint<dim>& p = points.at(i);
Counter callback{};
FilterAABB filter(p, p, tree.converter());
tree.for_each(callback, filter);
ASSERT_EQ(i, callback.id_._i);
ASSERT_EQ(1, callback.n_);
}
}

TEST(PhTreeTest, TestWindowQueryMany) {
const dimension_t dim = 3;
TestPoint<dim> min{-100, -100, -100};
Expand Down
10 changes: 5 additions & 5 deletions phtree/v16/for_each.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ class ForEach {

void run(const EntryT& root) {
assert(root.IsNode());
TraverseNode(root.GetKey(), root.GetNode());
TraverseNode(root.GetNode());
}

private:
void TraverseNode(const KeyInternal& key, const NodeT& node) {
void TraverseNode(const NodeT& node) {
auto iter = node.Entries().begin();
auto end = node.Entries().end();
for (; iter != end; ++iter) {
const auto& child = iter->second;
const auto& child_key = child.GetKey();
if (child.IsNode()) {
const auto& child_node = child.GetNode();
if (filter_.IsNodeValid(key, node.GetPostfixLen() + 1)) {
TraverseNode(child_key, child_node);
if (filter_.IsNodeValid(child_key, child_node.GetPostfixLen() + 1)) {
TraverseNode(child_node);
}
} else {
T& value = child.GetValue();
if (filter_.IsEntryValid(key, value)) {
if (filter_.IsEntryValid(child_key, value)) {
callback_(converter_.post(child_key), value);
}
}
Expand Down