20 table.insert_or_assign(1,
"one");
21 table.insert_or_assign(2,
"two");
24 bool inserted = table.insert(3,
"three");
25 std::cout <<
"Inserted key 3: " << inserted << std::endl;
27 inserted = table.insert(2,
"TWO");
28 std::cout <<
"Inserted key 2 again: " << inserted <<
" (should be false)" << std::endl;
31 std::cout <<
"Contains key 1: " << table.contains(1) << std::endl;
32 std::cout <<
"Contains key 4: " << table.contains(4) << std::endl;
36 std::cout <<
"table[4]: " <<
static_cast<std::string
>(table[4]) << std::endl;
39 std::map<int, std::string> snapshot = table();
40 std::cout <<
"Snapshot:\n";
41 for (std::map<int, std::string>::const_iterator it = snapshot.begin(); it != snapshot.end(); ++it)
42 std::cout << it->first <<
": " << it->second << std::endl;
45 std::unordered_map<int, std::string> temp_data = {
52 std::map<int, std::string> snapshot_2 = table.retrieve_all();
54# if __cplusplus >= 201703L
56 auto result = table.find(100);
58 std::cout <<
"Found key 100: " << *result << std::endl;
60 std::cout <<
"Key 100 not found\n";
62 auto result = table.find_compat(100);
64 std::cout <<
"Found key 100: " << result.second << std::endl;
66 std::cout <<
"Key 100 not found\n";
70 bool erased = table.erase(200);
71 std::cout <<
"Erased key 200: " << erased << std::endl;
74 std::cout <<
"All key-value pairs:\n";
75 std::vector<std::pair<int, std::string>> all;
77 for (
size_t i = 0; i < all.size(); ++i)
78 std::cout << all[i].first <<
": " << all[i].second << std::endl;
82 std::cout <<
"After clear, size = " << table.count() << std::endl;
84 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
Declaration of the KeyValueTable class for managing key-value pairs in an MDBX database.
int main()
Entry point demonstrating AnyValueTable.
Parameters used by Connection to create the MDBX environment.
std::string pathname
Path to the database file or directory containing the database.
int64_t max_dbs
Maximum number of named databases (DBI) in the environment.
static std::shared_ptr< Connection > create(const Config &config)
Creates and connects a new shared Connection instance.
Template class for managing key-value pairs in an MDBX database.