diff --git a/.gitignore b/.gitignore index 55098c94..f54c79a9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ compile_commands.json perf.data* build +/cmake-build-debug/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd2a904..190d228e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] -Nothing yet. +### Changed +- Fixed issue #2: for_each(callback, filter) was traversing too many nodes. +- Build improvements for bazel/cmake ## [1.1.1] - 2022-01-30 ### Changed diff --git a/README.md b/README.md index fad24140..17ab0a47 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**Note: for updates please also check the [fork](https://github.com/tzaeschke/phtree-cpp) by the original PH-Tree developer.** +**This is a fork of [Improbable's PH-tree](https://github.com/improbable-eng/phtree-cpp)**. # PH-Tree C++ @@ -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()));` diff --git a/WORKSPACE b/WORKSPACE index 0bd3d32b..be61fc70 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -11,7 +11,7 @@ http_archive( load("@bazel_skylib//lib:versions.bzl", "versions") versions.check( - minimum_bazel_version = "4.2.2", + minimum_bazel_version = "3.0.0", maximum_bazel_version = "4.2.2", ) diff --git a/phtree/phtree_test.cc b/phtree/phtree_test.cc index fe323c39..8bf4b423 100644 --- a/phtree/phtree_test.cc +++ b/phtree/phtree_test.cc @@ -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 tree; + std::vector> points; + populate(tree, points, N); + + struct Counter { + void operator()(TestPoint, Id& t) { + ++n_; + id_ = t; + } + Id id_{}; + size_t n_ = 0; + }; + + for (size_t i = 0; i < N; i++) { + TestPoint& 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 min{-100, -100, -100}; diff --git a/phtree/v16/for_each.h b/phtree/v16/for_each.h index aee3d157..d624f099 100644 --- a/phtree/v16/for_each.h +++ b/phtree/v16/for_each.h @@ -41,11 +41,11 @@ 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) { @@ -53,12 +53,12 @@ class ForEach { 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); } }