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.

  • tkrzw::DBM – Database manager interface.
  • tkrzw::HashDBM – File database manager implementation based on hash table.
  • tkrzw::TreeDBM – File database manager implementation based on B+ tree.
  • tkrzw::SkipDBM – File database manager implementation based on skip list.
  • tkrzw::TinyDBM – On-memory database manager implementation based on hash table.
  • tkrzw::BabyDBM – On-memory database manager implementation based on B+ tree.
  • tkrzw::CacheDBM – On-memory database manager implementations with LRU deletion.
  • tkrzw::StdHashDBM – On-memory hash database manager implementation using std::unordered_map.
  • tkrzw::StdTreeDBM – On-memory tree database manager implementation using std::map.
  • tkrzw::PolyDBM – Polymorphic database manager adapter for all DBM classes.
  • tkrzw::ShardDBM – Sharding database manager adapter based on PolyDBM.
  • tkrzw::AsyncDBM – Asynchronous database manager adapter for any databases.
  • tkrzw::FileIndex – File secondary index implementation with TreeDBM.
  • tkrzw::MemIndex – On-memory secondary index implementation with BabyDBM.
  • tkrzw::StdIndex – On-memory secondary index implementation with std::map.
  • tkrzw::PolyIndex – Polymorphic index adapter for all FileIndex and MemIndex.
  • tkrzw_langc.h – The C interface of PolyDBM and ShardDBM.

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;
}
@ SUCCESS
Success.
Definition: tkrzw_lib_common.h:303
Common namespace of Tkrzw.
Definition: doxy-overview.h:77
File database manager implementation based on hash table.