41volatile size_t sink = 0;
55 const auto t0 = std::chrono::steady_clock::now();
57 const auto t1 = std::chrono::steady_clock::now();
58 const double ms = std::chrono::duration<double, std::milli>(
t1 -
t0).count();
64void row(
const char *index,
const char *op,
const double ms)
66 std::printf(
" %-12s %-28s %10.2f ms\n", index, op,
ms);
72 std::uniform_int_distribution<int> coord(0, 20000);
73 std::uniform_int_distribution<int> extent(1, 80);
75 std::vector<Rectangle>
out;
77 for (
size_t i = 0; i < n; ++i)
79 const int x = coord(
rng);
80 const int y = coord(
rng);
89 for (
size_t i = 0; i <
rects.size(); ++i)
97 for (
size_t i = 0; i <
rects.size(); ++i)
106 for (
size_t i = 0; i <
rects.size(); ++i)
122 const std::string_view
sv{text};
123 if (
sv.empty()
or sv.front() ==
'+' or sv.front() ==
'-')
125 const auto [ptr,
ec] = std::from_chars(
sv.data(),
sv.data() +
sv.size(),
out, 10);
126 return ec == std::errc{}
and ptr ==
sv.data() +
sv.size();
130 const std::vector<Rectangle> &
queries)
135 total += b.intersects(q);
144 tree.for_each_intersecting(q,
158 const std::vector<Rectangle> &
queries,
170 "validation failed: brute=%zu rtree=%zu rstar=%zu aabb=%zu\n",
181 size_t entry_count = 10000;
186 std::fprintf(
stderr,
"invalid entry_count: '%s'\n",
argv[1]);
191 std::fprintf(
stderr,
"invalid query_count: '%s'\n",
argv[2]);
203 std::printf(
"Spatial index benchmark (best of 3 runs, %zu entries, %zu queries)\n",
205 row(
"RTree",
"incremental insert",
207 row(
"RStarTree",
"incremental insert",
209 row(
"AABBTree",
"static build",
212 row(
"brute",
"intersect queries",
214 row(
"RTree",
"intersect queries",
216 row(
"RStarTree",
"intersect queries",
218 row(
"AABBTree",
"intersect queries",
221 std::printf(
"\n(sink=%zu)\n",
static_cast<size_t>(sink));
size_t size_t int32_t * out
Axis-aligned bounding box tree for spatial queries.
size_t build(Array< size_t > &idx, const size_t lo, const size_t hi)
size_t size() const
Number of entries.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
void reserve(size_t cap)
Reserves cap cells into the array.
Dynamic R-tree indexing axis-aligned rectangles by payload.
void insert(const Rectangle &bbox, const Payload &value)
Insert a (bbox, value) entry, copying value.
size_t size() const noexcept
Return the number of stored entries.
An axis-aligned rectangle.
QuadTree - Hierarchical spatial index for 2D points.
Computational geometry algorithms.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
and
Check uniqueness with explicit hash + equality functors.
mpq_class Geom_Number
Numeric type used by the geometry module.
An entry in the tree, consisting of a bounding box and a user-defined index.
R*-tree: an R-tree tuned with the Beckmann-Kriegel-Schneider-Seeger heuristics.
Dynamic R-tree spatial index over axis-aligned rectangles.