FlatCityBuf C++ reader 0.8.0
Native C++17 reader for FlatCityBuf, the cloud-optimized CityJSON format
Loading...
Searching...
No Matches
packed_rtree.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fcb/error.hpp>
5#include <fcb/span.hpp>
6
7#include <cstdint>
8#include <vector>
9
10namespace fcb {
11
12struct SearchResultItem;
13
16struct BBox {
17 double min_x;
18 double min_y;
19 double max_x;
20 double max_y;
21};
22
29struct NodeItem {
30 double min_x;
31 double min_y;
32 double max_x;
33 double max_y;
34 std::uint64_t offset;
35
36 static constexpr std::size_t kSize = 40;
37
38 static NodeItem decode(bytes_view b);
39
44 static NodeItem empty(std::uint64_t offset);
45
48 void expand(const NodeItem& r);
49
53 void encode(std::uint8_t* out) const;
54
57 bool intersects(const BBox& q) const;
58};
59
63std::uint64_t rtree_num_nodes(std::uint64_t num_items, std::uint16_t node_size);
64
68struct LevelBound {
69 std::uint64_t start;
70 std::uint64_t end;
71};
72
77std::vector<LevelBound> rtree_level_bounds(std::uint64_t num_items, std::uint16_t node_size);
78
82std::vector<SearchResultItem> rtree_search_bbox(RangeReader& reader, std::uint64_t index_begin,
83 std::uint64_t num_items, std::uint16_t node_size,
84 const BBox& query);
85
86} // namespace fcb
Synchronous byte-range source.
Minimal C++17 stand-in for std::span: a non-owning view over contiguous memory.
Definition span.hpp:13
std::uint64_t rtree_num_nodes(std::uint64_t num_items, std::uint16_t node_size)
Total node count in the tree, per the Rust level-bounds loop (packed_rtree/mod.rs:342-375).
std::vector< SearchResultItem > rtree_search_bbox(RangeReader &reader, std::uint64_t index_begin, std::uint64_t num_items, std::uint16_t node_size, const BBox &query)
Breadth-first bbox search over the packed R-tree, reading nodes through the supplied reader.
std::vector< LevelBound > rtree_level_bounds(std::uint64_t num_items, std::uint16_t node_size)
Mirrors generate_level_bounds (packed_rtree/mod.rs:342-375).
std::uint64_t node_size
Definition stree.cpp:167
std::uint64_t index_begin
Definition stree.cpp:163
RangeReader & reader
Definition stree.cpp:162
A 2D query rectangle.
Half-open [start, end) node index range for one tree level, in the flat node array shared by every le...
std::uint64_t start
std::uint64_t end
One R-tree node entry: 4 doubles then a u64, all little-endian, 40 bytes with no padding (packed_rtre...
static NodeItem decode(bytes_view b)
static NodeItem empty(std::uint64_t offset)
The "empty" node used as the fold/aggregation identity: any real bbox's expand widens it.
void expand(const NodeItem &r)
Widens this node's bbox to also cover r, leaving offset untouched.
static constexpr std::size_t kSize
std::uint64_t offset
bool intersects(const BBox &q) const
Mirrors NodeItem::intersects (packed_rtree/mod.rs:122-134), which uses strict < and >: touching edges...
void encode(std::uint8_t *out) const
Writes this node's 40 bytes (4 LE f64 then a LE u64), matching decode's layout exactly.