Skip to content

Commit 52577de

Browse files
rtree: add conveniance helpers
1 parent 14ff45a commit 52577de

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

include/cista/containers/rtree.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "cista/cista_member_offset.h"
77
#include "cista/containers/array.h"
8+
#include "cista/containers/mmap_vec.h"
89
#include "cista/containers/vector.h"
910
#include "cista/endian/conversion.h"
1011
#include "cista/io.h"
@@ -30,7 +31,10 @@ struct rtree {
3031

3132
enum class kind : std::uint8_t { kLeaf, kBranch, kEndFreeList };
3233

34+
struct node;
35+
3336
using node_idx_t = strong<SizeType, struct node_idx_>;
37+
using vector_t = VectorType<node_idx_t, node>;
3438
using coord_t = array<NumType, Dims>;
3539

3640
struct rect {
@@ -399,6 +403,9 @@ struct rtree {
399403
}
400404

401405
node& get_node(node_idx_t const node_id) { return nodes_[node_id]; }
406+
node const& get_node(node_idx_t const node_id) const {
407+
return nodes_[node_id];
408+
}
402409

403410
node_idx_t node_new(kind const node_kind) {
404411
if (m_.free_list_ == node_idx_t::invalid()) {
@@ -420,7 +427,8 @@ struct rtree {
420427
}
421428

422429
template <typename Fn>
423-
bool node_search(node const& current_node, rect const& search_rect, Fn&& fn) {
430+
bool node_search(node const& current_node, rect const& search_rect,
431+
Fn&& fn) const {
424432
if (current_node.kind_ == kind::kLeaf) {
425433
for (auto i = 0U; i != current_node.count_; ++i) {
426434
if (current_node.rects_[i].intersects(search_rect)) {
@@ -444,7 +452,7 @@ struct rtree {
444452
}
445453

446454
template <typename Fn>
447-
void search(coord_t const& min, coord_t const& max, Fn&& fn) {
455+
void search(coord_t const& min, coord_t const& max, Fn&& fn) const {
448456
auto const r = rect{min, max};
449457
if (m_.root_ != node_idx_t::invalid()) {
450458
node_search(get_node(m_.root_), r, std::forward<Fn>(fn));
@@ -623,4 +631,9 @@ struct rtree {
623631
VectorType<node_idx_t, node> nodes_;
624632
};
625633

634+
template <typename DataType, std::uint32_t Dims = 2U, typename NumType = float,
635+
std::uint32_t MaxItems = 64U, typename SizeType = std::uint32_t>
636+
using mm_rtree = cista::rtree<DataType, Dims, NumType, MaxItems, SizeType,
637+
cista::mmap_vec_map>;
638+
626639
} // namespace cista

include/cista/io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <filesystem>
44

55
#include "cista/memory_holder.h"
6+
#include "cista/mode.h"
67

78
namespace cista {
89

test/rtree_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// HELPER FUNCTIONS
1212
void fill_rand_rect(std::vector<cista::rtree<size_t>::rect>& rand_vector) {
13-
1413
float min_x = (float(rand()) / float((RAND_MAX)) * 360) - 180;
1514
float min_y = (float(rand()) / float((RAND_MAX)) * 180) - 90;
1615
cista::rtree<size_t>::rect rand_rect = {

0 commit comments

Comments
 (0)