21 template <
typename K,
typename V>
22 void print_items(
const Array<std::pair<K, V>> & items)
25 for (
size_t i = 0; i < items.size(); ++i)
29 std::cout <<
"(" << items[i].first <<
" -> " << items[i].second <<
")";
36 std::filesystem::path path;
41 std::filesystem::remove(path, ec);
42 std::filesystem::remove(path.string() +
".lock", ec);
43 std::filesystem::remove(path.string() +
".wal", ec);
44 std::filesystem::remove(path.string() +
".wal.tmp", ec);
45 std::filesystem::remove(path.string() +
".journal", ec);
46 std::filesystem::remove(path.string() +
".journal.tmp", ec);
53 const auto file_path =
54 std::filesystem::temp_directory_path() /
"aleph_file_b_map_example.idx";
55 Cleanup cleanup{file_path};
57 std::cout <<
"Persistent B-Tree map example\n";
58 std::cout <<
"=============================\n";
59 std::cout <<
"file path : " << file_path.string() <<
"\n";
69 std::cout <<
"first session\n";
70 std::cout <<
"-------------\n";
71 std::cout <<
"inventory : ";
72 print_items(inventory.
items());
74 std::cout <<
"page count : " << inventory.
page_count() <<
"\n";
78 std::cout <<
"\nafter reopen\n";
79 std::cout <<
"------------\n";
80 std::cout <<
"read only : " << std::boolalpha << reopened.
is_read_only() <<
"\n";
81 std::cout <<
"inventory : ";
82 print_items(reopened.
items());
84 std::cout <<
"lower_bound(15): ";
87 std::cout <<
"(" << lb->first <<
" -> " << lb->second <<
")";
89 std::cout <<
"(none)";
Simple dynamic array with automatic resizing and functional operations.
Persistent ordered map backed by a paged File_B_Tree.
std::optional< value_type > lower_bound(const Key &key) const
Return the first key/value pair whose key is not less than key.
bool is_read_only() const noexcept
Return whether the map handle is read-only.
size_t page_count() const noexcept
Return the number of allocated pages.
void sync() const
Flush pending changes to the backing file.
bool insert(const Key &key, const Value &value)
Insert a new key/value pair if the key is not present.
Array< value_type > items() const
Materialize all key/value pairs in sorted order.
bool insert_or_assign(const Key &key, const Value &value)
Insert or overwrite a key/value pair.
Persistent key/value map built on top of Aleph::File_B_Tree.