From 12915304570507e00848aba700f0ed3a26dbb9b6 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Thu, 13 Jul 2023 15:34:49 -0400 Subject: Initial commit of VPTree-related code Point lookups are currently broken; I suspect that there is something wrong with tree construction, although the quickselect implementation seems to be fine. --- include/framework/RecordInterface.h | 47 ++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'include/framework') diff --git a/include/framework/RecordInterface.h b/include/framework/RecordInterface.h index 70c8e01..6936a8b 100644 --- a/include/framework/RecordInterface.h +++ b/include/framework/RecordInterface.h @@ -11,6 +11,7 @@ #include #include +#include #include "util/base.h" @@ -18,13 +19,26 @@ namespace de { template concept RecordInterface = requires(R r, R s) { - r.key; - r.value; - { r < s } ->std::convertible_to; { r == s } ->std::convertible_to; }; +template +concept WeightedRecordInterface = requires(R r) { + {r.weight} -> std::convertible_to; +}; + +template +concept NDRecordInterface = RecordInterface && requires(R r, R s) { + {r.calc_distance(s)} -> std::convertible_to; +}; + +template +concept KVPInterface = RecordInterface && requires(R r) { + r.key; + r.value; +}; + template struct Wrapped { uint32_t header; @@ -51,17 +65,10 @@ struct Wrapped { } inline bool operator<(const Wrapped& other) const { - return (rec.key < other.rec.key) || (rec.key == other.rec.key && rec.value < other.rec.value) - || (rec.key == other.rec.key && rec.value == other.rec.value && header < other.header); + return rec < other.rec || (rec == other.rec && header < other.header); } }; - -template -concept WeightedRecordInterface = RecordInterface && requires(R r) { - {r.weight} -> std::convertible_to; -}; - template struct Record { K key; @@ -92,4 +99,22 @@ struct WeightedRecord { } }; +template +struct Point{ + V x; + V y; + + inline bool operator==(const Point& other) const { + return x == other.x && y == other.y; + } + + // lexicographic order + inline bool operator<(const Point& other) const { + return x < other.x || (x == other.x && y < other.y); + } + + inline double calc_distance(const Point& other) const { + return sqrt(pow(x - other.x, 2) + pow(y - other.y, 2)); + } +}; } -- cgit v1.2.3