9#include <gtest/gtest.h>
26 namespace fs = std::filesystem;
30 static std::atomic<unsigned long long>
counter{0};
33 static std::mt19937_64
rng{[] {
34 std::random_device rd;
36 static_cast<unsigned long long>
37 (std::chrono::steady_clock::now().time_since_epoch().count());
39 (
static_cast<unsigned long long>(rd()) << 1u)};
42 const auto now = std::chrono::steady_clock::now().time_since_epoch().count();
43 std::uniform_int_distribution<unsigned long long> dist;
46 const auto id = std::to_string(
now) +
"_" +
50 const fs::path dir = fs::temp_directory_path() /
"aleph_file_bplusmap_tests";
51 fs::create_directories(dir);
52 return dir / (
id +
".idx");
59 explicit TempFile(fs::path p) : path(
std::move(p)) {}
65 fs::remove(path.string() +
".wal",
ec);
66 fs::remove(path.string() +
".wal.tmp",
ec);
67 fs::remove(path.string() +
".journal",
ec);
68 fs::remove(path.string() +
".journal.tmp",
ec);
69 fs::remove(path.string() +
".lock",
ec);
78 for (
size_t i = 0; i < arr.
size(); ++i)
79 out.push_back(arr[i]);
96 (std::vector<std::pair<int, int>>{{20, 200}, {30, 300}, {40, 400}}));
106 (std::vector<std::pair<int, int>>{{10, 100}, {20, 200}, {30, 300}}));
122 EXPECT_EQ(map.upper_bound(25), (std::optional<std::pair<int, long>>{{35, 350}}));
124 (std::vector<std::pair<int, long>>{{5, 50}, {15, 150}, {25, 255}, {35, 350}}));
137 for (
const auto & [key, value] : std::vector<std::pair<int, int>>{
138 {101, 750}, {105, 920}, {110, 875}, {120, 990}, {130, 1010}})
141 std::vector<std::pair<int, int>>
all_items;
145 (std::vector<std::pair<int, int>>{
146 {101, 750}, {105, 920}, {110, 875}, {120, 990}, {130, 1010}}));
148 std::vector<std::pair<int, int>>
band;
153 for (; it.has_curr(); it.next())
154 band.push_back(it.get_curr());
157 (std::vector<std::pair<int, int>>{
158 {105, 920}, {110, 875}, {120, 990}}));
169 key_codec, value_codec> map(
tmp.path.string(),
false);
176 (std::vector<std::pair<std::string, std::string>>{
177 {
"banana",
"ripe yellow"}, {
"kiwi",
"brown fuzz"}}));
189 (std::vector<std::pair<std::string, std::string>>{
191 {
"banana",
"ripe yellow"},
192 {
"kiwi",
"brown fuzz"}}));
194 std::vector<std::pair<std::string, std::string>>
lazy_items;
195 for (
auto it =
reopened.get_it(); it.has_curr(); it.next())
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
bool has_curr() const noexcept
Return whether the iterator still points to an item.
Persistent ordered map backed by a paged File_BPlus_Tree.
Iterator get_range_it(const Key &first, const Key &last) const
Return a lazy iterator over an inclusive key range.
std::optional< value_type > lower_bound(const Key &key) const
Return the first key/value pair whose key is not less than key.
Array< value_type > range(const Key &first, const Key &last) const
Collect all key/value pairs in the inclusive key range.
Iterator get_it() const noexcept
Return a lazy iterator over all items in key order.
Value at(const Key &key) const
Return the mapped value associated with a key.
bool insert_or_assign(const Key &key, const Value &value)
Insert or overwrite a key/value pair.
bool insert(const Key &key, const Value &value)
Insert a new key/value pair if the key is not present.
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::vector< typename C::Item_Type > to_vector(const C &c)
Convert a container to a std::vector.
Persistent key/value map built on top of Aleph::File_BPlus_Tree.