Tkrzw
Tkrzw: a set of implementations of DBM


Introduction

DBM (Database Manager) is a concept of libraries to store an associative array on a permanent storage. In other words, DBM allows an application program to store key-value pairs in a file and reuse them later. Each of keys and values is a string or a sequence of bytes. The key of each record must be unique within the database and a value is associated to it. You can retrieve a stored record with its key very quickly. Thanks to simple structure of DBM, its performance can be extremely high.

Tkrzw is a C++ library implementing DBM with various algorithms. It features high degrees of performance, concurrency, scalability and durability. The following classes are the most important.

All database classes share the same interface so that applications can use any of them with the common API. All classes are thread-safe so that multiple threads can access the same database simultaneously. Basically, you can store records with the "Set" method, retrieve records with the "Get" method, and remove records with the "Remove" method. Iterator is also supported to retrieve each and every record in the database. See the homepage for details.

#include "tkrzw_dbm_hash.h"
// Main routine.
int main(int argc, char** argv) {
// All symbols of Tkrzw are under the namespace "tkrzw".
using namespace tkrzw;
// Creates the database manager.
HashDBM dbm;
// Opens a new database.
dbm.Open("casket.tkh", true);
// Stores records.
dbm.Set("foo", "hop");
dbm.Set("bar", "step");
dbm.Set("baz", "jump");
// Retrieves records.
std::cout << dbm.GetSimple("foo", "*") << std::endl;
std::cout << dbm.GetSimple("bar", "*") << std::endl;
std::cout << dbm.GetSimple("baz", "*") << std::endl;
std::cout << dbm.GetSimple("outlier", "*") << std::endl;
// Traverses records.
std::unique_ptr<DBM::Iterator> iter = dbm.MakeIterator();
iter->First();
std::string key, value;
while (iter->Get(&key, &value) == Status::SUCCESS) {
std::cout << key << ":" << value << std::endl;
iter->Next();
}
// Closes the database.
dbm.Close();
return 0;
}