summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2023-07-17 13:50:42 -0400
committerDouglas Rumbaugh <dbr4@psu.edu>2023-07-17 13:50:42 -0400
commit99d957ea185c3641e407b73a757bc9e2b5673686 (patch)
treebb33917884aba70f628f1544cc3302cd20b9f4af
parentc4a1b596483b494ead45755dca1805cae6b5615c (diff)
downloaddynamic-extension-99d957ea185c3641e407b73a757bc9e2b5673686.tar.gz
VPTree: changed Point format to a D-dimensional point.
-rw-r--r--include/framework/RecordInterface.h30
-rw-r--r--tests/vptree_tests.cpp12
2 files changed, 30 insertions, 12 deletions
diff --git a/include/framework/RecordInterface.h b/include/framework/RecordInterface.h
index ab4c6f9..a3f6814 100644
--- a/include/framework/RecordInterface.h
+++ b/include/framework/RecordInterface.h
@@ -100,22 +100,40 @@ struct WeightedRecord {
}
};
-template <typename V>
+template <typename V, size_t D=2>
struct Point{
- V x;
- V y;
+ V data[D];
inline bool operator==(const Point& other) const {
- return x == other.x && y == other.y;
+ for (size_t i=0; i<D; i++) {
+ if (data[i] != other.data[i]) {
+ return false;
+ }
+ }
+
+ return true;
}
// lexicographic order
inline bool operator<(const Point& other) const {
- return x < other.x || (x == other.x && y < other.y);
+ for (size_t i=0; i<D; i++) {
+ if (data[i] < other.data[i]) {
+ return true;
+ } else if (data[i] > other.data[i]) {
+ return false;
+ }
+ }
+
+ return false;
}
inline double calc_distance(const Point& other) const {
- return sqrt(pow(x - other.x, 2) + pow(y - other.y, 2));
+ double dist = 0;
+ for (size_t i=0; i<D; i++) {
+ dist += pow(data[i] - other.data[i], 2);
+ }
+
+ return sqrt(dist);
}
};
diff --git a/tests/vptree_tests.cpp b/tests/vptree_tests.cpp
index 7c35a58..b86e1e9 100644
--- a/tests/vptree_tests.cpp
+++ b/tests/vptree_tests.cpp
@@ -74,13 +74,13 @@ START_TEST(t_point_lookup)
for (size_t i=0; i<n; i++) {
PRec r;
auto rec = (buffer->get_data() + i);
- r.x = rec->rec.x;
- r.y = rec->rec.y;
+ r.data[0] = rec->rec.data[0];
+ r.data[1] = rec->rec.data[1];
auto result = wss.point_lookup(r);
ck_assert_ptr_nonnull(result);
- ck_assert_int_eq(result->rec.x, r.x);
- ck_assert_int_eq(result->rec.y, r.y);
+ ck_assert_int_eq(result->rec.data[0], r.data[0]);
+ ck_assert_int_eq(result->rec.data[1], r.data[1]);
}
delete buffer;
@@ -97,8 +97,8 @@ START_TEST(t_point_lookup_miss)
for (size_t i=n + 100; i<2*n; i++) {
PRec r;
- r.x = i;
- r.y = i;
+ r.data[0] = i;
+ r.data[1] = i;
auto result = wss.point_lookup(r);
ck_assert_ptr_null(result);