5
5
6
6
#include " cista/cista_member_offset.h"
7
7
#include " cista/containers/array.h"
8
+ #include " cista/containers/mmap_vec.h"
8
9
#include " cista/containers/vector.h"
9
10
#include " cista/endian/conversion.h"
10
11
#include " cista/io.h"
@@ -30,7 +31,10 @@ struct rtree {
30
31
31
32
enum class kind : std::uint8_t { kLeaf , kBranch , kEndFreeList };
32
33
34
+ struct node ;
35
+
33
36
using node_idx_t = strong<SizeType, struct node_idx_ >;
37
+ using vector_t = VectorType<node_idx_t , node>;
34
38
using coord_t = array<NumType, Dims>;
35
39
36
40
struct rect {
@@ -399,6 +403,9 @@ struct rtree {
399
403
}
400
404
401
405
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
+ }
402
409
403
410
node_idx_t node_new (kind const node_kind) {
404
411
if (m_.free_list_ == node_idx_t::invalid ()) {
@@ -420,7 +427,8 @@ struct rtree {
420
427
}
421
428
422
429
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 {
424
432
if (current_node.kind_ == kind::kLeaf ) {
425
433
for (auto i = 0U ; i != current_node.count_ ; ++i) {
426
434
if (current_node.rects_ [i].intersects (search_rect)) {
@@ -444,7 +452,7 @@ struct rtree {
444
452
}
445
453
446
454
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 {
448
456
auto const r = rect{min, max};
449
457
if (m_.root_ != node_idx_t::invalid ()) {
450
458
node_search (get_node (m_.root_ ), r, std::forward<Fn>(fn));
@@ -623,4 +631,9 @@ struct rtree {
623
631
VectorType<node_idx_t , node> nodes_;
624
632
};
625
633
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
+
626
639
} // namespace cista
0 commit comments