From 64959d4ff45b81d94155f44b4ae9b010f05089fe Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Tue, 25 Jul 2023 11:12:46 -0400 Subject: VPTree: Added template configuration to use/not use a hash table --- include/shard/VPTree.h | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'include/shard/VPTree.h') diff --git a/include/shard/VPTree.h b/include/shard/VPTree.h index 66b67e5..03645db 100644 --- a/include/shard/VPTree.h +++ b/include/shard/VPTree.h @@ -86,7 +86,7 @@ private: -template +template class VPTree { private: struct vpnode { @@ -186,13 +186,33 @@ public: } Wrapped *point_lookup(const R &rec, bool filter=false) { - auto idx = m_lookup_map.find(rec); + if constexpr (HMAP) { + auto idx = m_lookup_map.find(rec); + + if (idx == m_lookup_map.end()) { + return nullptr; + } + + return m_data + idx->second; + } else { + vpnode *node = m_root; + + while (!node->leaf && m_ptrs[node->start]->rec != rec) { + if (rec.calc_distance((m_ptrs[node->start]->rec)) >= node->radius) { + node = node->outside; + } else { + node = node->inside; + } + } + + for (size_t i=node->start; i<=node->stop; i++) { + if (m_ptrs[i]->rec == rec) { + return m_ptrs[i]; + } + } - if (idx == m_lookup_map.end()) { return nullptr; } - - return m_data + idx->second; } Wrapped* get_data() const { @@ -234,6 +254,12 @@ private: } void build_map() { + // Skip constructing the hashmap if disabled in the + // template parameters. + if constexpr (!HMAP) { + return; + } + for (size_t i=0; i> pq(k, &rec); for (size_t i=0; i