TCADB(3)
β¨ NAME β¨
okay so this is TCADB(3) from Tokyo Cabinet, and it's all about tcadb β the abstract database API. π
π DESCRIPTION π
bestie, the abstract database is literally a set of interfaces that lets you use on-memory hash database, on-memory tree database, hash database, B+ tree database, fixed-length database, and table database with the same API. No cap. One API, whole squad of databases. β¨
To use the abstract database API, include tcutil.h, tcadb.h, and related standard header files. Usually, write the following description near the front of a source file.
#include <tcutil.h>
#include <tcadb.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
Objects whose type is pointer to TCADB are used to handle abstract databases. An abstract database object is created with the function tcadbnew and is deleted with the function tcadbdel. To avoid memory leak, it is important to delete every object when it is no longer in use. π«Ά
Before operations to store or retrieve records, it is necessary to connect the abstract database object to the concrete one. The function tcadbopen is used to open a concrete database and the function tcadbclose is used to close the database. To avoid data missing or corruption, it is important to close every database instance when it is no longer in use. It is forbidden for multiple database objects in a process to open the same database at the same time. π
π API π
here we go, function by function, no skips, periodt. π
tcadbnew
The function tcadbnew is used in order to create an abstract database object.
TCADB *tcadbnew(void);
The return value is the new abstract database object. π
tcadbdel
The function tcadbdel is used in order to delete an abstract database object.
void tcadbdel(TCADB *adb);
adbβ specifies the abstract database object.
tcadbopen
The function tcadbopen is used in order to open an abstract database.
bool tcadbopen(TCADB *adb, const char *name);
adbβ specifies the abstract database object.nameβ specifies the name of the database. Here's the tea:- If it is
"*", the database will be an on-memory hash database. - If it is
"+", the database will be an on-memory tree database. - If its suffix is
".tch", the database will be a hash database. - If its suffix is
".tcb", the database will be a B+ tree database. - If its suffix is
".tcf", the database will be a fixed-length database. - If its suffix is
".tct", the database will be a table database. - Otherwise, this function fails. π
- If it is
Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=".
- On-memory hash database supports
"bnum","capnum", and"capsiz". - On-memory tree database supports
"capnum"and"capsiz". - Hash database supports
"mode","bnum","apow","fpow","opts","rcnum","xmsiz", and"dfunit". - B+ tree database supports
"mode","lmemb","nmemb","bnum","apow","fpow","opts","lcnum","ncnum","xmsiz", and"dfunit". - Fixed-length database supports
"mode","width", and"limsiz". - Table database supports
"mode","bnum","apow","fpow","opts","rcnum","lcnum","ncnum","xmsiz","dfunit", and"idx".
If successful, the return value is true, else, it is false.
- The tuning parameter
"capnum"specifies the capacity number of records. "capsiz"specifies the capacity size of using memory.- Records spilled the capacity are removed by the storing order.
"mode"can contain"w"of writer,"r"of reader,"c"of creating,"t"of truncating,"e"of no locking, and"f"of non-blocking lock. The default mode is relevant to"wc"."opts"can contain"l"of large option,"d"of Deflate option,"b"of BZIP2 option, and"t"of TCBS option."idx"specifies the column name of an index and its type separated by":". For example,"casket.tch#bnum=1000000#opts=ld"means that the name of the database file is"casket.tch", and the bucket number is1000000, and the options are large and Deflate.
tcadbclose
The function tcadbclose is used in order to close an abstract database object.
bool tcadbclose(TCADB *adb);
adbβ specifies the abstract database object.
If successful, the return value is true, else, it is false.
Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken. π
tcadbput
The function tcadbput is used in order to store a record into an abstract database object.
bool tcadbput(TCADB *adb, const void *kbuf, int ksiz, const void
*vbuf, int vsiz);
adbβ specifies the abstract database object.kbufβ specifies the pointer to the region of the key.ksizβ specifies the size of the region of the key.vbufβ specifies the pointer to the region of the value.vsizβ specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.
tcadbput2
The function tcadbput2 is used in order to store a string record into an abstract object.
bool tcadbput2(TCADB *adb, const char *kstr, const char *vstr);
adbβ specifies the abstract database object.kstrβ specifies the string of the key.vstrβ specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, it is overwritten.
tcadbputkeep
The function tcadbputkeep is used in order to store a new record into an abstract database object.
bool tcadbputkeep(TCADB *adb, const void *kbuf, int ksiz, const
void *vbuf, int vsiz);
adbβ specifies the abstract database object.kbufβ specifies the pointer to the region of the key.ksizβ specifies the size of the region of the key.vbufβ specifies the pointer to the region of the value.vsizβ specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect.
tcadbputkeep2
The function tcadbputkeep2 is used in order to store a new string record into an abstract database object.
bool tcadbputkeep2(TCADB *adb, const char *kstr, const char
*vstr);
adbβ specifies the abstract database object.kstrβ specifies the string of the key.vstrβ specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect.
tcadbputcat
The function tcadbputcat is used in order to concatenate a value at the end of the existing record in an abstract database object.
bool tcadbputcat(TCADB *adb, const void *kbuf, int ksiz, const
void *vbuf, int vsiz);
adbβ specifies the abstract database object.kbufβ specifies the pointer to the region of the key.ksizβ specifies the size of the region of the key.vbufβ specifies the pointer to the region of the value.vsizβ specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.
tcadbputcat2
The function tcadbputcat2 is used in order to concatenate a string value at the end of the existing record in an abstract database object.
bool tcadbputcat2(TCADB *adb, const char *kstr, const char
*vstr);
adbβ specifies the abstract database object.kstrβ specifies the string of the key.vstrβ specifies the string of the value.
If successful, the return value is true, else, it is false.
If there is no corresponding record, a new record is created.
tcadbout
The function tcadbout is used in order to remove a record of an abstract database object.
bool tcadbout(TCADB *adb, const void *kbuf, int ksiz);
adbβ specifies the abstract database object.kbufβ specifies the pointer to the region of the key.ksizβ specifies the size of the region of the key.
If successful, the return value is true, else, it is false.
tcadbout2
The function tcadbout2 is used in order to remove a string record of an abstract database object.
bool tcadbout2(TCADB *adb, const char *kstr);
adbβ specifies the abstract database object.kstrβ specifies the string of the key.
If successful, the return value is true, else, it is false.
tcadbget
The function tcadbget is used in order to retrieve a record in an abstract database object.
void *tcadbget(TCADB *adb, const void *kbuf, int ksiz, int *sp);
adbβ specifies the abstract database object.kbufβ specifies the pointer to the region of the key.ksizβ specifies the size of the region of the key.spβ specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the value of the corresponding record. NULL is returned if no record corresponds.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the malloc call, it should be released with the free call when it is no longer in use.
tcadbget2
The function tcadbget2 is used in order to retrieve a string record in an abstract database object.
π tcadbget2
char *tcadbget2(TCADB *adb, const char *kstr);
adbβ the abstract database object, bestie.kstrβ the string of the key.
If it works, you get back the string of the value of the corresponding record. If literally no record matches, you get NULL. π
Heads up: that returned region was allocated with themalloccall, so you gotta release it with thefreecall once you're done with it. No leaks, we're not doing that. π
πΈ tcadbvsiz
This one's for finding out the size of the value of a record in an abstract database object.
int tcadbvsiz(TCADB *adb, const void *kbuf, int ksiz);
adbβ the abstract database object.kbufβ pointer to the region of the key.ksizβ size of the region of the key.
If successful, the return value is the size of the value of the corresponding record. Otherwise? -1. π
π¦ tcadbvsiz2
Same energy, but for the size of the value of a string record.
int tcadbvsiz2(TCADB *adb, const char *kstr);
adbβ the abstract database object.kstrβ the string of the key.
If successful, the return value is the size of the value of the corresponding record, else it's -1.
β¨ tcadbiterinit
Kicks off the iterator of an abstract database object.
bool tcadbiterinit(TCADB *adb);
adbβ the abstract database object.
If successful, the return value is true, else it's false.
The iterator is what you use to access the key of every single record stored in a database. Main character access method, honestly. π
π tcadbiternext
Gets the next key out of the iterator.
void *tcadbiternext(TCADB *adb, int *sp);
adbβ the abstract database object.spβ pointer to the variable that the size of the region of the return value gets assigned into.
If successful, the return value is the pointer to the region of the next key, else it's NULL. And NULL is also what you get when there's no record left to get out of the iterator.
Because an additional zero code is appended at the end of the region of the return value, you can treat the return value as a character string. Also, that region was allocated with themalloccall, so please release it with thefreecall when you're done. π«Ά
You can access every record by just iterating calls to this function. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. And besides β the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access. So don't come for me about order, okay? π
π tcadbiternext2
Grabs the next key string of the iterator.
char *tcadbiternext2(TCADB *adb);
adbβ the abstract database object.
If successful, the return value is the string of the next key, else it's NULL. NULL shows up when no record is to be get out of the iterator.
That region was allocated with themalloccall, so release it with thefreecall when it is no longer in use. π§
You can access every record by iterating calls to this function. However, it is not assured if updating the database is occurred while the iteration. And again β the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
π₯ tcadbfwmkeys
Gets forward matching keys in an abstract database object.
TCLIST *tcadbfwmkeys(TCADB *adb, const void *pbuf, int psiz, int max);
adbβ the abstract database object.pbufβ pointer to the region of the prefix.psizβ size of the region of the prefix.maxβ the maximum number of keys to be fetched. If it's negative, no limit is specified. β¨
The return value is a list object of the corresponding keys. This function does never fail β it returns an empty list even if no key corresponds. Iconic reliability, honestly. π
Because the object of the return value is created with the functiontclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use.
Note that this function may be very slow because every key in the database is scanned. Like, it's doing the most. Be aware.
π tcadbfwmkeys2
Forward matching string keys, same vibe.
TCLIST *tcadbfwmkeys2(TCADB *adb, const char *pstr, int max);
adbβ the abstract database object.pstrβ the string of the prefix.maxβ the maximum number of keys to be fetched. If it's negative, no limit is specified.
Return value is a list object of the corresponding keys. This function does never fail, and it returns an empty list even if no key corresponds.
Created withtclistnew, so delete it withtclistdelwhen it is no longer in use.
Note that this function may be very slow because every key in the database is scanned. Fr fr.
β tcadbaddint
Adds an integer to a record.
int tcadbaddint(TCADB *adb, const void *kbuf, int ksiz, int num);
adbβ the abstract database object.kbufβ pointer to the region of the key.ksizβ size of the region of the key.numβ the additional value.
If successful, the return value is the summation value, else it's INT_MIN. π
If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Simple as that. π
π tcadbadddouble
Adds a real number to a record.
double tcadbadddouble(TCADB *adb, const void *kbuf, int ksiz, double num);
adbβ the abstract database object.kbufβ pointer to the region of the key.ksizβ size of the region of the key.numβ the additional value.
If successful, the return value is the summation value, else it's Not-a-Number. π
If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored.
π tcadbsync
Syncs up the updated contents of an abstract database object with the file and the device. Glow up for your data. β¨
bool tcadbsync(TCADB *adb);
adbβ the abstract database object.
If successful, the return value is true, else it's false.
π tcadboptimize
Optimizes the storage of an abstract database object.
bool tcadboptimize(TCADB *adb, const char *params);
adbβ the abstract database object.paramsβ the string of the tuning parameters, which works as with the tuning of parameters the functiontcadbopen. If it'sNULL, it is not used.
If successful, the return value is true, else it's false.
This function is useful to reduce the size of the database storage with data fragmentation by successive updating. Basically a deep-clean for your db. π§Ή
π¦ tcadbvanish
Removes all records of an abstract database object. Poof. Gone. β¨
bool tcadbvanish(TCADB *adb);
adbβ the abstract database object.
If successful, the return value is true, else it's false.
πΈ tcadbcopy
Copies the database file of an abstract database object.
bool tcadbcopy(TCADB *adb, const char *path);
adbβ the abstract database object.pathβ the path of the destination file. If it begins with@, the trailing substring is executed as a command line. π
If successful, the return value is true, else it's false. false is returned if the executed command returns non-zero code.
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So this function is useful to create a backup file of the database file. Backup bestie behavior. π«Ά
π tcadbtranbegin
Begins the transaction of an abstract database object.
bool tcadbtranbegin(TCADB *adb);
adbβ the abstract database object.
If successful, the return value is true, else it's false.
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction.
If the database is closed during transaction, the transaction is aborted implicitly. So, like, don't do that. π
πΈ tcadbtrancommit β the "we're keeping this" button
The function tcadbtrancommit is used in order to commit the transaction of an abstract database object.
bool tcadbtrancommit(TCADB *adb);
adbspecifies the abstract database object.- If successful, the return value is
true, else, it isfalse. - Update in the transaction is fixed when it is committed successfully.
no takebacks after this one bestie π once it commits, it's fixed.
π«Ά tcadbtranabort β the "jk nvm" button
The function tcadbtranabort is used in order to abort the transaction of an abstract database object.
bool tcadbtranabort(TCADB *adb);
adbspecifies the abstract database object.- If successful, the return value is
true, else, it isfalse. - Update in the transaction is discarded when it is aborted.
- The state of the database is rollbacked to before transaction.
it's giving time travel ⨠everything you did in the transaction just⦠poof. gone. back to before, periodt.
π¦ tcadbpath β where does this thing even live
The function tcadbpath is used in order to get the file path of an abstract database object.
const char *tcadbpath(TCADB *adb);
adbspecifies the abstract database object.- The return value is the path of the database file or
NULLif the object does not connect to any database. "*"stands for on-memory hash database."+"stands for on-memory tree database.
so if you get"*"or"+"back, that's not a real file path bestie, that's the on-memory vibe β hash and tree respectively π
π tcadbrnum β how many records we got
The function tcadbrnum is used in order to get the number of records of an abstract database object.
uint64_t tcadbrnum(TCADB *adb);
adbspecifies the abstract database object.- The return value is the number of records or
0if the object does not connect to any database instance.
β tcadbsize β how thicc is this database
The function tcadbsize is used in order to get the size of the database of an abstract database object.
uint64_t tcadbsize(TCADB *adb);
adbspecifies the abstract database object.- The return value is the size of the database or
0if the object does not connect to any database instance.
π tcadbmisc β the everything bagel function
The function tcadbmisc is used in order to call a versatile function for miscellaneous operations of an abstract database object.
TCLIST *tcadbmisc(TCADB *adb, const char *name, const TCLIST *args);
adbspecifies the abstract database object.namespecifies the name of the function. All databases support"put","out","get","putlist","outlist","getlist", and"getpart".
Okay so here's the whole menu, and yes we're going through every single one because they all matter π:
"put"is to store a record. It receives a key and a value, and returns an empty list."out"is to remove a record. It receives a key, and returns an empty list."get"is to retrieve a record. It receives a key, and returns a list of the values."putlist"is to store records. It receives keys and values one after the other, and returns an empty list."outlist"is to remove records. It receives keys, and returns an empty list."getlist"is to retrieve records. It receives keys, and returns keys and values of corresponding records one after the other."getpart"is to retrieve the partial value of a record. It receives a key, the offset of the region, and the length of the region.argsspecifies a list object containing arguments.- If successful, the return value is a list object of the result.
NULLis returned on failure. - Because the object of the return value is created with the function
tclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use.
THE MEMORY LEAK JUMPSCARE π fr fr, you calledtclistnewso you owe it atclistdel. don't leave it hanging, that's not main character energy.
β¨ SEE ALSO β¨
and that's a wrap on TCADB(3) bestie π this one came from the Man Page collection, dated 2012-08-18, and yeah she's been iconic since day one π go forth and commit (responsibly) πβ¨
π¦ where this page comes from
- debian bookworm: libtokyocabinet-dev 1.4.48-15 Β· LGPL-2.1-or-later
- debian trixie: libtokyocabinet-dev 1.4.48-15.1+b1 Β· LGPL-2.1-or-later
- ubuntu jammy: libtokyocabinet-dev 1.4.48-14build1 Β· LGPL-2.1-or-later
- ubuntu noble: libtokyocabinet-dev 1.4.48-15.1build1 Β· LGPL-2.1-or-later
- ubuntu questing: libtokyocabinet-dev 1.4.48-15.1build2
- ubuntu resolute: libtokyocabinet-dev 1.4.48-15.1build3 Β· LGPL-2.1-or-later
- ubuntu stonking: libtokyocabinet-dev 1.4.48-15.1build3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms