diff options
| author | Douglas Rumbaugh <dbr4@psu.edu> | 2023-07-13 15:34:49 -0400 |
|---|---|---|
| committer | Douglas Rumbaugh <dbr4@psu.edu> | 2023-07-13 15:34:49 -0400 |
| commit | 12915304570507e00848aba700f0ed3a26dbb9b6 (patch) | |
| tree | ed69ab1bf95df0fa7924f677b4bad82f325fd96e /include/framework | |
| parent | 369dc4c8b3331aa318f2a98eb973d0840541297d (diff) | |
| download | dynamic-extension-12915304570507e00848aba700f0ed3a26dbb9b6.tar.gz | |
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.
Diffstat (limited to 'include/framework')
| -rw-r--r-- | include/framework/RecordInterface.h | 47 |
1 files changed, 36 insertions, 11 deletions
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 <cstring> #include <concepts> +#include <cmath> #include "util/base.h" @@ -18,13 +19,26 @@ namespace de { template<typename R> concept RecordInterface = requires(R r, R s) { - r.key; - r.value; - { r < s } ->std::convertible_to<bool>; { r == s } ->std::convertible_to<bool>; }; +template<typename R> +concept WeightedRecordInterface = requires(R r) { + {r.weight} -> std::convertible_to<double>; +}; + +template<typename R> +concept NDRecordInterface = RecordInterface<R> && requires(R r, R s) { + {r.calc_distance(s)} -> std::convertible_to<double>; +}; + +template <typename R> +concept KVPInterface = RecordInterface<R> && requires(R r) { + r.key; + r.value; +}; + template<RecordInterface R> 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 <typename R> -concept WeightedRecordInterface = RecordInterface<R> && requires(R r) { - {r.weight} -> std::convertible_to<double>; -}; - template <typename K, typename V> struct Record { K key; @@ -92,4 +99,22 @@ struct WeightedRecord { } }; +template <typename V> +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)); + } +}; } |