44#include <gtest/gtest.h>
61 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
67 template <
typename Key> Key key_of(
long i);
69 template <>
int key_of<int>(
const long i)
71 return static_cast<int>((i * 7919) % 100003);
75 template <> std::string key_of<std::string>(
const long i)
77 return "a key long enough to allocate " + std::to_string((i * 7919) % 100003);
82 template <
typename Key,
size_t Degree>
83 size_t fail_each_allocation_of_an_insert(
const long n_keys)
87 for (
size_t n = 1;; ++n)
90 for (
long i = 0; i < n_keys; ++i)
91 EXPECT_TRUE(tree.
insert(key_of<Key>(i)));
98 (void) tree.
insert(key_of<Key>(n_keys));
100 catch (
const std::bad_alloc &)
109 EXPECT_TRUE(tree.verify()) << n_keys <<
" keys, allocation " << n;
110 EXPECT_EQ(tree.size(),
static_cast<size_t>(n_keys)) <<
"allocation " << n;
111 EXPECT_EQ(tree.keys().size(),
static_cast<size_t>(n_keys)) <<
"allocation " << n;
112 for (
long i = 0; i < n_keys; ++i)
113 EXPECT_TRUE(tree.
contains(key_of<Key>(i))) <<
"key " << i <<
", allocation " << n;
114 EXPECT_TRUE(tree.
insert(key_of<Key>(n_keys))) <<
"allocation " << n;
115 EXPECT_TRUE(tree.verify()) <<
"allocation " << n;
123 EXPECT_GT((fail_each_allocation_of_an_insert<int, 16>(31)), 0u);
124 EXPECT_GT((fail_each_allocation_of_an_insert<int, 2>(3)), 0u);
130 for (
const long n : {7L, 100L, 500L})
131 (
void) fail_each_allocation_of_an_insert<int, 2>(n);
137 for (
const long n : {31L, 300L})
138 (
void) fail_each_allocation_of_an_insert<std::string, 16>(n);
139 for (
const long n : {3L, 20L, 200L})
140 (
void) fail_each_allocation_of_an_insert<std::string, 2>(n);
A global operator new that a test can make fail.
#define ALEPH_ALLOCATION_FAILURE_UNDER_TSAN
TEST_F(BPlusTreeWithoutMemory, SplitOfAFullRoot)
Generic B+ Tree with configurable minimum degree.
QuadTree - Hierarchical spatial index for 2D points.
bool contains(const Point &p) const noexcept
Check if a point is within the tree's region.
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
Main namespace for Aleph-w library functions.
B+ Tree implementation with linked leaves and configurable degree.