39#include <system_error>
48 namespace fs = std::filesystem;
53 std::cout << label <<
" [";
54 for (
size_t i = 0; i < values.
size(); ++i)
58 std::cout << values[i];
63 template <
typename Tree>
69 std::cout << label <<
" [";
71 for (
auto it = tree.get_range_it(first, last); it.has_curr(); it.next_ne())
75 std::cout << it.get_curr();
84 const fs::path file_path =
85 fs::temp_directory_path() /
"aleph_file_bplus_tree_example.idx";
90 fs::remove(file_path,
ec);
91 fs::remove(file_path.string() +
".wal",
ec);
92 fs::remove(file_path.string() +
".wal.tmp",
ec);
93 fs::remove(file_path.string() +
".journal",
ec);
94 fs::remove(file_path.string() +
".journal.tmp",
ec);
95 fs::remove(file_path.string() +
".lock",
ec);
97 std::cout <<
"Persistent B+ Tree example\n";
98 std::cout <<
"==========================\n";
99 std::cout <<
"file path : " << file_path.string() <<
"\n";
100 std::cout <<
"sidecars : " << file_path.string() <<
".lock, "
101 << file_path.string() <<
".wal, "
102 << file_path.string() <<
".wal.tmp, "
103 << file_path.string() <<
".journal, "
104 << file_path.string() <<
".journal.tmp\n\n";
109 for (
int value : {105, 110, 115, 120, 125, 130, 135, 140, 145, 150})
117 <<
"File_BPlus_Tree example produced an invalid in-memory tree";
119 std::cout <<
"first session\n";
120 std::cout <<
"-------------\n";
124 std::cout <<
"page size : " <<
ledger.page_size_bytes() <<
"\n";
125 std::cout <<
"page count : " <<
ledger.page_count() <<
"\n";
126 std::cout <<
"auto sync : " << std::boolalpha
127 <<
ledger.auto_sync_enabled() <<
"\n\n";
133 std::cout <<
"after reopen\n";
134 std::cout <<
"------------\n";
138 std::cout <<
"page count : " <<
reopened.page_count() <<
"\n";
140 if (
const auto ub =
reopened.upper_bound(145);
ub.has_value())
141 std::cout <<
"upper_bound(145) -> " << *
ub <<
"\n";
144 fs::remove(file_path,
ec);
145 fs::remove(file_path.string() +
".wal",
ec);
146 fs::remove(file_path.string() +
".wal.tmp",
ec);
147 fs::remove(file_path.string() +
".journal",
ec);
148 fs::remove(file_path.string() +
".journal.tmp",
ec);
149 fs::remove(file_path.string() +
".lock",
ec);
151 catch (
const std::exception &
ex)
153 std::cerr <<
"file_bplus_tree_example failed: " <<
ex.what() <<
'\n';
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Persistent page-managed B+ Tree stored in a single binary file.
QuadTree - Hierarchical spatial index for 2D points.
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.
void print_array(const char *label, const Container &a)
Page-managed persistent B+ Tree with file-backed storage.