From 52577def055e4bdf90eaa461872fc1f7b5b1131d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20G=C3=BCndling?= Date: Sun, 3 Nov 2024 23:36:55 +0100 Subject: [PATCH] rtree: add conveniance helpers --- include/cista/containers/rtree.h | 17 +++++++++++++++-- include/cista/io.h | 1 + test/rtree_test.cc | 1 - 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/cista/containers/rtree.h b/include/cista/containers/rtree.h index 44cbc830..28b88d37 100644 --- a/include/cista/containers/rtree.h +++ b/include/cista/containers/rtree.h @@ -5,6 +5,7 @@ #include "cista/cista_member_offset.h" #include "cista/containers/array.h" +#include "cista/containers/mmap_vec.h" #include "cista/containers/vector.h" #include "cista/endian/conversion.h" #include "cista/io.h" @@ -30,7 +31,10 @@ struct rtree { enum class kind : std::uint8_t { kLeaf, kBranch, kEndFreeList }; + struct node; + using node_idx_t = strong; + using vector_t = VectorType; using coord_t = array; struct rect { @@ -399,6 +403,9 @@ struct rtree { } node& get_node(node_idx_t const node_id) { return nodes_[node_id]; } + node const& get_node(node_idx_t const node_id) const { + return nodes_[node_id]; + } node_idx_t node_new(kind const node_kind) { if (m_.free_list_ == node_idx_t::invalid()) { @@ -420,7 +427,8 @@ struct rtree { } template - bool node_search(node const& current_node, rect const& search_rect, Fn&& fn) { + bool node_search(node const& current_node, rect const& search_rect, + Fn&& fn) const { if (current_node.kind_ == kind::kLeaf) { for (auto i = 0U; i != current_node.count_; ++i) { if (current_node.rects_[i].intersects(search_rect)) { @@ -444,7 +452,7 @@ struct rtree { } template - void search(coord_t const& min, coord_t const& max, Fn&& fn) { + void search(coord_t const& min, coord_t const& max, Fn&& fn) const { auto const r = rect{min, max}; if (m_.root_ != node_idx_t::invalid()) { node_search(get_node(m_.root_), r, std::forward(fn)); @@ -623,4 +631,9 @@ struct rtree { VectorType nodes_; }; +template +using mm_rtree = cista::rtree; + } // namespace cista \ No newline at end of file diff --git a/include/cista/io.h b/include/cista/io.h index 9940559a..a1983009 100644 --- a/include/cista/io.h +++ b/include/cista/io.h @@ -3,6 +3,7 @@ #include #include "cista/memory_holder.h" +#include "cista/mode.h" namespace cista { diff --git a/test/rtree_test.cc b/test/rtree_test.cc index cadc9d02..26aa21de 100644 --- a/test/rtree_test.cc +++ b/test/rtree_test.cc @@ -10,7 +10,6 @@ // HELPER FUNCTIONS void fill_rand_rect(std::vector::rect>& rand_vector) { - float min_x = (float(rand()) / float((RAND_MAX)) * 360) - 180; float min_y = (float(rand()) / float((RAND_MAX)) * 180) - 90; cista::rtree::rect rand_rect = {