TCBDB(3)
πΈ NAME πΈ
tcbdb β the B+ tree database API π
okay so real talk, this is the TCBDB(3) page from Tokyo Cabinet, and it's literally the whole entire manual for the B+ tree database API. bestie, we're going in, no cap. π¦
β¨ DESCRIPTION β¨
A B+ tree database is a file containing a B+ tree, and you handle it with the B+ tree database API. that's the whole vibe. π³
To use the B+ tree database API, include tcutil.h, tcbdb.h, and related standard header files. Usually, write the following description near the front of a source file:
#include <tcutil.h>
#include <tcbdb.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
Objects whose type is pointer to TCBDB are used to handle B+ tree databases. A B+ tree database object is created with the function tcbdbnew and is deleted with the function tcbdbdel. To avoid memory leak, it is important to delete every object when it is no longer in use. like, every single one. don't leave them hanging, that's so not slay. π
Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree database object to it. The function tcbdbopen is used to open a database file and the function tcbdbclose is used to close the database file. To avoid data missing or corruption, it is important to close every database file 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. like, forbidden forbidden. π«
π API π
π tcbdberrmsg β the error-code-to-message translator π
The function tcbdberrmsg is used in order to get the message string corresponding to an error code.
const char *tcbdberrmsg(int ecode);
ecodespecifies the error code.- The return value is the message string of the error code.
π tcbdbnew β birth of a database object π
The function tcbdbnew is used in order to create a B+ tree database object.
TCBDB *tcbdbnew(void);
- The return value is the new B+ tree database object.
π tcbdbdel β delete the whole thing π
The function tcbdbdel is used in order to delete a B+ tree database object.
void tcbdbdel(TCBDB *bdb);
bdbspecifies the B+ tree database object.- If the database is not closed, it is closed implicitly.
- Note that the deleted object and its derivatives can not be used anymore. π it's gone gone.
π tcbdbecode β what went wrong, bestie? π
The function tcbdbecode is used in order to get the last happened error code of a B+ tree database object.
int tcbdbecode(TCBDB *bdb);
bdbspecifies the B+ tree database object.- The return value is the last happened error code.
The following error codes are defined:
TCESUCCESSfor successTCETHREADfor threading errorTCEINVALIDfor invalid operationTCENOFILEfor file not foundTCENOPERMfor no permissionTCEMETAfor invalid meta dataTCERHEADfor invalid record headerTCEOPENfor open errorTCECLOSEfor close errorTCETRUNCfor trunc errorTCESYNCfor sync errorTCESTATfor stat errorTCESEEKfor seek errorTCEREADfor read errorTCEWRITEfor write errorTCEMMAPfor mmap errorTCELOCKfor lock errorTCEUNLINKfor unlink errorTCERENAMEfor rename errorTCEMKDIRfor mkdir errorTCERMDIRfor rmdir errorTCEKEEPfor existing recordTCENORECfor no record foundTCEMISCfor miscellaneous error
π tcbdbsetmutex β threading protection, iconic π
The function tcbdbsetmutex is used in order to set mutual exclusion control of a B+ tree database object for threading.
bool tcbdbsetmutex(TCBDB *bdb);
bdbspecifies the B+ tree database object which is not opened.- If successful, the return value is true, else, it is false.
- Note that the mutual exclusion control of the database should be set before the database is opened. π₯
π tcbdbsetcmpfunc β pick your own comparison energy π
The function tcbdbsetcmpfunc is used in order to set the custom comparison function of a B+ tree database object.
bool tcbdbsetcmpfunc(TCBDB *bdb, TCCMP cmp, void *cmpop);
bdbspecifies the B+ tree database object which is not opened.cmpspecifies the pointer to the custom comparison function. It receives five parameters. The first parameter is the pointer to the region of one key. The second parameter is the size of the region of one key. The third parameter is the pointer to the region of the other key. The fourth parameter is the size of the region of the other key. The fifth parameter is the pointer to the optional opaque object. It returns positive if the former is big, negative if the latter is big, 0 if both are equivalent.cmpopspecifies an arbitrary pointer to be given as a parameter of the comparison function. If it is not needed,NULLcan be specified.- If successful, the return value is true, else, it is false.
The default comparison function compares keys of two records by lexical order. The functions tccmplexical (default), tccmpdecimal, tccmpint32, and tccmpint64 are built-in. π
Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened. like, every single time, no shortcuts. π
π tcbdbtune β the tuning parameters, main character energy π
The function tcbdbtune is used in order to set the tuning parameters of a B+ tree database object.
bool tcbdbtune(TCBDB *bdb, int32_t lmemb, int32_t nmemb, int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);
bdbspecifies the B+ tree database object which is not opened.lmembspecifies the number of members in each leaf page. If it is not more than 0, the default value is specified. The default value is 128.nmembspecifies the number of members in each non-leaf page. If it is not more than 0, the default value is specified. The default value is 256.bnumspecifies the number of elements of the bucket array. If it is not more than 0, the default value is specified. The default value is 16381. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored.apowspecifies the size of record alignment by power of 2. If it is negative, the default value is specified. The default value is 8 standing for 2^8=256.fpowspecifies the maximum number of elements of the free block pool by power of 2. If it is negative, the default value is specified. The default value is 10 standing for 2^10=1024.optsspecifies options by bitwise-or:BDBTLARGEspecifies that the size of the database can be larger than 2GB by using 64-bit bucket array,BDBTDEFLATEspecifies that each page is compressed with Deflate encoding,BDBTBZIPspecifies that each page is compressed with BZIP2 encoding,BDBTTCBSspecifies that each page is compressed with TCBS encoding.- If successful, the return value is true, else, it is false.
Note that the tuning parameters should be set before the database is opened. β
π tcbdbsetcache β cache it, queen π
The function tcbdbsetcache is used in order to set the caching parameters of a B+ tree database object.
bool tcbdbsetcache(TCBDB *bdb, int32_t lcnum, int32_t ncnum);
bdbspecifies the B+ tree database object which is not opened.lcnumspecifies the maximum number of leaf nodes to be cached. If it is not more than 0, the default value is specified. The default value is 1024.ncnumspecifies the maximum number of non-leaf nodes to be cached. If it is not more than 0, the default value is specified. The default value is 512.- If successful, the return value is true, else, it is false.
Note that the caching parameters should be set before the database is opened. π
π tcbdbsetxmsiz β extra mapped memory, the bonus level π
The function tcbdbsetxmsiz is used in order to set the size of the extra mapped memory of a B+ tree database object.
bool tcbdbsetxmsiz(TCBDB *bdb, int64_t xmsiz);
bdbspecifies the B+ tree database object which is not opened.xmsizspecifies the size of the extra mapped memory. If it is not more than 0, the extra mapped memory is disabled. It is disabled by default.- If successful, the return value is true, else, it is false.
Note that the mapping parameters should be set before the database is opened. β¨
π tcbdbsetdfunit β auto defrag, glow-up mode π
The function tcbdbsetdfunit is used in order to set the unit step number of auto defragmentation of a B+ tree database object.
bool tcbdbsetdfunit(TCBDB *bdb, int32_t dfunit);
bdbspecifies the B+ tree database object which is not opened.dfunitspecifies the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.- If successful, the return value is true, else, it is false.
Note that the defragmentation parameter should be set before the database is opened. π§
π tcbdbopen β open the file, connect the object π
The function tcbdbopen is used in order to open a database file and connect a B+ tree database object.
bool tcbdbopen(TCBDB *bdb, const char *path, int omode);
bdbβ the B+ tree database object, and it's gotta be one that is not opened yet, bestie. Fresh. Unopened. No cap.pathβ the path of the database file. That's where the data lives, that's its home πomodeβ the connection mode. Pick your fighter:BDBOWRITERβ you're a writer, you get to change stuff βοΈBDBOREADERβ you're a reader, look but don't touch π- If the mode is
BDBOWRITER, you can bitwise-or these in too:BDBOCREATβ creates a brand new database if it doesn't already exist β¨BDBOTRUNCβ creates a brand new database regardless if one exists (yep, it wipes it, periodt)BDBOTSYNCβ every transaction synchronizes updated contents with the device πΎ
- And both
BDBOREADERandBDBOWRITERcan be added to by bitwise-or with:BDBONOLCKβ opens the database file with no file locking at all πBDBOLCKNBβ locking is performed without blocking β³
If it worked, you get true back. If not, false. That's the vibe check β
The function tcbdbclose is the one you call to close a B+ tree database object. Bye bestie π
bool tcbdbclose(TCBDB *bdb);
bdbβ the B+ tree database object.
true if it slayed, false if it didn't.
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. Like, actually broken. Not a vibe. Close your databases, i am begging π
The function tcbdbput is how you store a record into a B+ tree database object.
bool tcbdbput(TCBDB *bdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the key.ksizβ size of the region of the key.vbufβ pointer to the region of the value.vsizβ size of the region of the value.
true on success, false otherwise. And if a record with the same key already exists in the database? It gets overwritten. Out with the old π
The function tcbdbput2 stores a string record into a B+ tree database object. Same energy, string edition π
bool tcbdbput2(TCBDB *bdb, const char *kstr, const char *vstr);
bdbβ the B+ tree database object, connected as a writer.kstrβ the string of the key.vstrβ the string of the value.
true if successful, false if not. Same key already there? Overwritten. Simple as that.
The function tcbdbputkeep stores a new record into a B+ tree database object.
bool tcbdbputkeep(TCBDB *bdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the key.ksizβ size of the region of the key.vbufβ pointer to the region of the value.vsizβ size of the region of the value.
true on success, false otherwise. And if a record with that same key already exists in the database, this function has no effect. It just... doesn't. Nothing happens. It's giving polite decline π
ββοΈ
The function tcbdbputkeep2 stores a new string record into a B+ tree database object.
bool tcbdbputkeep2(TCBDB *bdb, const char *kstr, const char *vstr);
bdbβ the B+ tree database object, connected as a writer.kstrβ the string of the key.vstrβ the string of the value.
true if it worked, false if it didn't. Duplicate key? No effect. Iconic restraint honestly.
The function tcbdbputcat concatenates a value onto the end of the existing record in a B+ tree database object. Gluing vibes π«Ά
bool tcbdbputcat(TCBDB *bdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the key.ksizβ size of the region of the key.vbufβ pointer to the region of the value.vsizβ size of the region of the value.
true on success, false otherwise. And if there's no corresponding record? A new record is created. It's like, "fine, i'll start it myself" π
The function tcbdbputcat2 concatenates a string value at the end of the existing record in a B+ tree database object.
bool tcbdbputcat2(TCBDB *bdb, const char *kstr, const char *vstr);
bdbβ the B+ tree database object, connected as a writer.kstrβ the string of the key.vstrβ the string of the value.
true if successful, false if not. No corresponding record? New record, created, done β¨
The function tcbdbputdup stores a record into a B+ tree database object, but it allows duplication of keys. Yes, you can have the same key more than once. Chaotic. Love that for us π
bool tcbdbputdup(TCBDB *bdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the key.ksizβ size of the region of the key.vbufβ pointer to the region of the value.vsizβ size of the region of the value.
true on success, false otherwise. If a record with the same key already exists in the database, the new record is placed after the existing one. Queue up, bestie πΆββοΈ
The function tcbdbputdup2 stores a string record into a B+ tree database object, also allowing duplication of keys.
bool tcbdbputdup2(TCBDB *bdb, const char *kstr, const char *vstr);
bdbβ the B+ tree database object, connected as a writer.kstrβ the string of the key.vstrβ the string of the value.
true if successful, false if not. Same key already in there? New record goes after the existing one. No cutting the line π
The function tcbdbputdup3 stores records (plural!!) into a B+ tree database object, allowing duplication of keys. Group drop π«
bool tcbdbputdup3(TCBDB *bdb, const void *kbuf, int ksiz, const TCLIST *vals);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the common key.ksizβ size of the region of the common key.valsβ a list object containing values.
true on success, false otherwise. If a record with the same key already exists in the database, the new records are placed after the existing one. The whole friend group gets in line π
The function tcbdbout removes a record from a B+ tree database object. Gone. Deleted. Not coming back π₯
bool tcbdbout(TCBDB *bdb, const void *kbuf, int ksiz);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the key.ksizβ size of the region of the key.
true on success, false otherwise. And if you specify the key of duplicated records, the first one is selected. Only the first. Pick your battles βοΈ
The function tcbdbout2 removes a string record from a B+ tree database object.
bool tcbdbout2(TCBDB *bdb, const char *kstr);
bdbβ the B+ tree database object, connected as a writer.kstrβ the string of the key.
true if successful, false if not. Duplicated records with that key? The first one is selected. Yeah. Just the first one π
The function tcbdbout3 removes records (plural) from a B+ tree database object. Full clear-out energy π§Ή
bool tcbdbout3(TCBDB *bdb, const void *kbuf, int ksiz);
bdbβ the B+ tree database object, connected as a writer.kbufβ pointer to the region of the key.ksizβ size of the region of the key.
true on success, false otherwise. If the key of duplicated records is specified, all of them are removed. All. Of. Them. No survivors π
The function tcbdbget retrieves a record from a B+ tree database object. The reading era π
void *tcbdbget(TCBDB *bdb, const void *kbuf, int ksiz, int *sp);
bdbβ the B+ tree database object.kbufβ pointer to the region of the key.ksizβ size of the region of the key.spβ pointer to the variable into which the size of the region of the return value is assigned.
If it worked, you get back the pointer to the region of the value of the corresponding record. If there's no record that corresponds, you get NULL. That's it, that's the whole answer π«₯
If the key of duplicated records is specified, the first one is selected.
And here's the cute part: 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 themalloccall, it should be released with thefreecall when it is no longer in use. Do not forget this. Free your memory, bestie, or it's giving leak π
π tcbdbget2 β the string-in, string-out getter π
okay bestie, so tcbdbget2 is what you call when you wanna retrieve a string record out of a B+ tree database object. string key in, string value out, zero buffer maths required. it's giving convenience. β¨
char *tcbdbget2(TCBDB *bdb, const char *kstr);
bdbβ the B+ tree database object. the main character of this whole story, honestly.kstrβ the string of the key. like, the lil string that tells the database which record you're after.
If it all goes right, the return value is the string of the value of the corresponding record. and if no record corresponds? you get NULL. that's the whole vibe check. π
π¨ if the key of duplicated records is specified, the first one is selected. only the first. not the whole squad.
πΈ and listen, this part matters: the region of the return value is allocated with themalloccall, so it should be released with thefreecall when it is no longer in use. free your memory, free yourself. π«Ά
π¦ tcbdbget3 β get it, but make it volatile π¦
tcbdbget3 retrieves a record in a B+ tree database object as a volatile buffer. cute, fast, and absolutely not yours to keep. π
const void *tcbdbget3(TCBDB *bdb, const void *kbuf, int ksiz, int *sp);
bdbβ the B+ tree database object.kbufβ the pointer to the region of the key.ksizβ the size of the region of the key.spβ the pointer to the variable into which the size of the region of the return value is assigned. yes, you hand it a pointer and it fills in the size for you. teamwork. π€
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. same deal as before with duplicated keys β the first one is selected.
Bestie, two things you need to know:
- an additional zero code is appended at the end of the region of the return value, so the return value can be treated as a character string. convenient! π
- the region of the return value is volatile and it may be spoiled by another operation of the database. so copy that data into another involatile buffer immediately. like, do not pass go, do not collect $200, do not go get a snack first. π
π tcbdbget4 β get all the records π
tcbdbget4 retrieves records in a B+ tree database object β plural, babes. all of them.
TCLIST *tcbdbget4(TCBDB *bdb, const void *kbuf, int ksiz);
bdbβ the B+ tree database object.kbufβ the pointer to the region of the key.ksizβ the size of the region of the key.
If successful, the return value is a list object of the values of the corresponding records. NULL is returned if no record corresponds. this is the one you want when the key has duplicates and you refuse to pick favourites. π
πΈ 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. new it up, delete it down. periodt.
π tcbdbvnum β how many records?? π
tcbdbvnum gets the number of records corresponding a key in a B+ tree database object. counting era. π’
int tcbdbvnum(TCBDB *bdb, const void *kbuf, int ksiz);
bdbβ the B+ tree database object.kbufβ the pointer to the region of the key.ksizβ the size of the region of the key.
If successful, the return value is the number of the corresponding records. else, it is 0. so a zero is a "nope, nothing here" β no cap. π
π§ tcbdbvnum2 β the string-key remix π§
tcbdbvnum2 does the exact same thing but for a string key. glow up. β¨
int tcbdbvnum2(TCBDB *bdb, const char *kstr);
bdbβ the B+ tree database object.kstrβ the string of the key.
If successful, the return value is the number of the corresponding records, else, it is 0. same energy, stringier fit. π
π
tcbdbvsiz β how big is the value tho π
tcbdbvsiz gets the size of the value of a record in a B+ tree database object.
int tcbdbvsiz(TCBDB *bdb, const void *kbuf, int ksiz);
bdbβ the B+ tree database object.kbufβ the pointer to the region of the key.ksizβ the size of the region of the key.
If successful, the return value is the size of the value of the corresponding record. else, it is -1. so -1 is the "no record, bestie" signal. don't @ me.
If the key of duplicated records is specified, the first one is selected. you already know the rule. π
π«Ά tcbdbvsiz2 β size, but string edition π«Ά
tcbdbvsiz2 gets the size of the value of a string record in a B+ tree database object.
int tcbdbvsiz2(TCBDB *bdb, const char *kstr);
bdbβ the B+ tree 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 is -1. and yep β if the key of duplicated records is specified, the first one is selected. π
πΈ tcbdbrange β the range era πΈ
tcbdbrange gets keys of ranged records in a B+ tree database object. this is the one for "gimme everything between here and there". iconic behaviour.
TCLIST *tcbdbrange(TCBDB *bdb, const void *bkbuf, int bksiz, bool binc, const void *ekbuf, int eksiz, bool einc, int max);
bdbβ the B+ tree database object.bkbufβ the pointer to the region of the key of the beginning border. if it isNULL, the first record is specified. start from the top, slay.bksizβ the size of the region of the beginning key.bincβ whether the beginning border is inclusive or not. are we letting the starting key in the club or not. ποΈekbufβ the pointer to the region of the key of the ending border. if it isNULL, the last record is specified.eksizβ the size of the region of the ending key.eincβ whether the ending border is inclusive or not.maxβ the maximum number of keys to be fetched. if it is negative, no limit is specified. unlimited. unhinged. π₯
The return value is a list object of the keys of the corresponding records. this function does never fail β it returns an empty list even if no record corresponds. so no drama, no NULL, just vibes.
π 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.
π tcbdbrange2 β range, but string keys π
tcbdbrange2 gets string keys of ranged records in a B+ tree database object.
TCLIST *tcbdbrange2(TCBDB *bdb, const char *bkstr, bool binc, const char *ekstr, bool einc, int max);
bdbβ the B+ tree database object.bkstrβ the string of the key of the beginning border. if it isNULL, the first record is specified.bincβ whether the beginning border is inclusive or not.ekstrβ the string of the key of the ending border. if it isNULL, the last record is specified.eincβ whether the ending border is inclusive or not.maxβ the maximum number of keys to be fetched. if it is negative, no limit is specified.
The return value is a list object of the keys of the corresponding records. does never fail. empty list even if no record corresponds. same as its sibling, just stringier. π
π 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.
β tcbdbfwmkeys β forward matching keys β
tcbdbfwmkeys gets forward matching keys in a B+ tree database object. you give it a prefix, it gives you every key that starts with that prefix. autocomplete core. π¦
TCLIST *tcbdbfwmkeys(TCBDB *bdb, const void *pbuf, int psiz, int max);
bdbβ the B+ tree database object.pbufβ the pointer to the region of the prefix.psizβ the size of the region of the prefix.maxβ the maximum number of keys to be fetched. if it is negative, no limit is specified. go wild, bestie. π₯
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.
π 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.
π tcbdbfwmkeys2 β forward matching string keys π
tcbdbfwmkeys2 gets forward matching string keys in a B+ tree database object.
TCLIST *tcbdbfwmkeys2(TCBDB *bdb, const char *pstr, int max);
bdbβ the B+ tree database object.pstrβ the string of the prefix.maxβ the maximum number of keys to be fetched. if it is negative, no limit is specified.
The return value is a list object of the corresponding keys. does never fail. empty list even if no key corresponds. no notes. β¨
π 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.
π₯ tcbdbaddint β math but make it a record π₯
tcbdbaddint adds an integer to a record in a B+ tree database object. it's giving calculator energy, but the calculator lives in your database. π
int tcbdbaddint(TCBDB *bdb, const void *kbuf, int ksiz, int num);
bdbβ the B+ tree database object connected as a writer. yes, you need write access for this one. read-only girls can't sit with us on this call. πkbufβ the pointer to the region of the key.ksizβ the size of the region of the key.numβ the additional value. the amount you're adding. the lil number that makes it move. π’
If successful, the return value is the summation value. else, it is INT_MIN. that's the "nope" signal, and yes it's dramatic, that's the point.
Here's how it behaves, no cap:
- 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. so it just... starts one. main character energy. π
π tcbdbadddouble β and the float version π
The function tcbdbadddouble is used in order to add a real number to a record in a B+ tree database object.
β¦and the tea keeps pouring in the next chunk of this page, bestie π«β¨
okay bestie, we're back in the API section and the function tour continues π Let's go, no breaks, we're locked in π₯
double tcbdbadddouble(TCBDB *bdb, const void *kbuf, int ksiz, double num);β adds a number to a record, slay
double tcbdbadddouble(TCBDB *bdb, const void *kbuf, int ksiz, double num);
bdbβ the B+ tree database object, and it has to be connected as a writer, periodtkbufβ pointer to the region of the keyksizβ the size of the region of the keynumβ the additional value
If it works, you get back the summation value. If it doesn't? You get Not-a-Number π ngl that's the vibe check failing. Here's the tea: if the corresponding record already exists, its value is treated as a real number and num gets added to it. If no record matches, a brand new record holding the additional value gets stored. π«Ά
The function tcbdbsync is used in order to synchronize updated contents of a B+ tree database object with the file and the device. (it's giving "save ur work fr fr")
bool tcbdbsync(TCBDB *bdb);β sync that database to disk πΎ
bool tcbdbsync(TCBDB *bdb);
bdbβ the B+ tree database object, connected as a writer
Returns true if it went well, false if not. This one is genuinely useful when another process connects to the same database file β iykyk. β¨
The function tcbdboptimize is used in order to optimize the file of a B+ tree database object. (glow-up for ur database)
bool tcbdboptimize(TCBDB *bdb, int32_t lmemb, int32_t nmemb, int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);β the full database makeover β¨
bool tcbdboptimize(TCBDB *bdb, int32_t lmemb, int32_t nmemb,
int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts);
bdbβ the B+ tree database object, connected as a writerlmembβ the number of members in each leaf page. If it's not more than0, the current setting is not changednmembβ the number of members in each non-leaf page. If it's not more than0, the current setting is not changedbnumβ the number of elements of the bucket array. If it's not more than0, the default value is specified. That default is two times of the number of pagesapowβ the size of record alignment by power of 2. If it's negative, the current setting is not changedfpowβ the maximum number of elements of the free block pool by power of 2. If it's negative, the current setting is not changedoptsβ options by bitwise-or, and there's a whole menu:BDBTLARGEβ says the size of the database can be larger than 2GB by using a 64-bit bucket array πͺBDBTDEFLATEβ each record is compressed with Deflate encodingBDBTBZIPβ each page is compressed with BZIP2 encodingBDBTTCBSβ each page is compressed with TCBS encoding- and if it's
UINT8_MAX, the current setting is not changed
Returns true on success, false otherwise. This function is the one you call to reduce the size of the database file when data fragmentation has happened from successive updating. spring cleaning era π§Ή
The function tcbdbvanish is used in order to remove all records of a B+ tree database object. (nuclear option, no going back)
bool tcbdbvanish(TCBDB *bdb);β poof, gone, all of it π
bool tcbdbvanish(TCBDB *bdb);
bdbβ the B+ tree database object, connected as a writer
Returns true if it succeeded, false if not. Every record. Gone. Main character energy, honestly. π
The function tcbdbcopy is used in order to copy the database file of a B+ tree database object.
bool tcbdbcopy(TCBDB *bdb, const char *path);β backup bestie time π
bool tcbdbcopy(TCBDB *bdb, const char *path);
bdbβ the B+ tree database objectpathβ the path of the destination file. And okay here's the fun part: if it begins with@, the trailing substring is executed as a command line π
Returns true if it worked, false if not. And false gets returned if the executed command returns a non-zero code.
Now this is important so listen up: 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 genuinely useful to create a backup file of the database file. safe, sound, slaying β¨
The function tcbdbtranbegin is used in order to begin the transaction of a B+ tree database object.
bool tcbdbtranbegin(TCBDB *bdb);β start the transaction π¦
bool tcbdbtranbegin(TCBDB *bdb);
bdbβ the B+ tree database object, connected as a writer
Returns true if it went well, false if not.
So the deets: the database is locked by the thread while the transaction is active, so that only one transaction can be activated with a database object at the same time. That means the serializable isolation level is assumed if every database operation is performed in the transaction. And because all pages are cached on memory while the transaction is running, the amount of referred records is limited by the memory capacity. β οΈ memory check, bestie Also, if the database is closed during the transaction, the transaction is aborted implicitly. No cap.
The function tcbdbtrancommit is used in order to commit the transaction of a B+ tree database object.
bool tcbdbtrancommit(TCBDB *bdb);β lock it in, commit it π
bool tcbdbtrancommit(TCBDB *bdb);
bdbβ the B+ tree database object, connected as a writer
Returns true if it worked, false if not. And when it's committed successfully, the update in the transaction is fixed. Periodt. β¨
The function tcbdbtranabort is used in order to abort the transaction of a B+ tree database object.
bool tcbdbtranabort(TCBDB *bdb);β nvm, undo that π
bool tcbdbtranabort(TCBDB *bdb);
bdbβ the B+ tree database object, connected as a writer
Returns true if it worked, false if not. When it's aborted, the update in the transaction is discarded, and the state of the database is rollbacked to before the transaction. like it never happened, iconic
The function tcbdbpath is used in order to get the file path of a B+ tree database object.
const char *tcbdbpath(TCBDB *bdb);β where does this thing even live π
const char *tcbdbpath(TCBDB *bdb);
bdbβ the B+ tree database object
The return value is the path of the database file, or NULL if the object does not connect to any database file. (mystery object energy)
The function tcbdbrnum is used in order to get the number of records of a B+ tree database object.
uint64_t tcbdbrnum(TCBDB *bdb);β how many records we talking π’
uint64_t tcbdbrnum(TCBDB *bdb);
bdbβ the B+ tree database object
The return value is the number of records, or 0 if the object does not connect to any database file.
The function tcbdbfsiz is used in order to get the size of the database file of a B+ tree database object.
uint64_t tcbdbfsiz(TCBDB *bdb);β file size check π
uint64_t tcbdbfsiz(TCBDB *bdb);
bdbβ the B+ tree database object
The return value is the size of the database file, or 0 if the object does not connect to any database file.
The function tcbdbcurnew is used in order to create a cursor object.
BDBCUR *tcbdbcurnew(TCBDB *bdb);β new cursor, who dis π±οΈ
BDBCUR *tcbdbcurnew(TCBDB *bdb);
bdbβ the B+ tree database object
The return value is the new cursor object.
β οΈ Listen up fr fr: the cursor is available only after initialization with thetcbdbcurfirstor thetcbdbcurjumpfunctions and so on. And moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor. So don't be surprised bestie. π
The function tcbdbcurdel is used in order to delete a cursor object.
void tcbdbcurdel(BDBCUR *cur);β bye bye cursor π
void tcbdbcurdel(BDBCUR *cur);
curβ the cursor object
The function tcbdbcurfirst is used in order to move a cursor object to the first record.
bool tcbdbcurfirst(BDBCUR *cur);β jump to the very first record π₯
bool tcbdbcurfirst(BDBCUR *cur);
curβ the cursor object
Returns true if it worked, false if not. And false gets returned if there is no record in the database. (empty database, empty vibes)
The function tcbdbcurlast is used in order to move a cursor object to the last record.
bool tcbdbcurlast(BDBCUR *cur);β jump to the very last record π
bool tcbdbcurlast(BDBCUR *cur);
curβ the cursor object
Returns true if it worked, false if not. And false gets returned if there is no record in the database.
The function tcbdbcurjump is used in order to move a cursor object to the front of records corresponding a key.
bool tcbdbcurjump(BDBCUR *cur, const void *kbuf, int ksiz);β teleport to a key π―
bool tcbdbcurjump(BDBCUR *cur, const void *kbuf, int ksiz);
curβ the cursor objectkbufβ pointer to the region of the keyksizβ the size of the region of the key
Returns true if it worked, false if not. false gets returned if there is no record corresponding the condition.
And here's the lil detail that matters: the cursor is set to the first record corresponding the key, or the next substitute if a completely matching record does not exist. so it always finds the closest vibe β¨
The function tcbdbcurjump2 is used in order to move a cursor object to the front of records corresponding a key string.
bool tcbdbcurjump2(BDBCUR *cur, const char *kstr);β same teleport, but string edition π
bool tcbdbcurjump2(BDBCUR *cur, const char *kstr);
curβ the cursor objectkstrβ the string of the key
Returns true if it worked, false if not. false gets returned if there is no record corresponding the condition. Just like its sibling, the cursor is set to the first record corresponding the key, or the next substitute if a completely matching record does not exist. π¦
The function tcbdbcurprev is used in order to move a cursor object to the previous record.
bool tcbdbcurprev(BDBCUR *cur);β back it up one record β¬ οΈ
bool tcbdbcurprev(BDBCUR *cur);
curβ the cursor object
Returns true if it worked, false if not. false gets returned if there is no previous record.
The function tcbdbcurnext is used in order to move a cursor object to the next record.
bool tcbdbcurnext(BDBCUR *cur);β forward one record β‘οΈ
bool tcbdbcurnext(BDBCUR *cur);
curβ the cursor object
Returns true if it worked, false if not. false gets returned if there is no next record.
The function tcbdbcurput is used in order to insert a record around a cursor object.
π
tcbdbcurput π
bool tcbdbcurput(BDBCUR *cur, const void *vbuf, int vsiz, int cpmode);
curβ the cursor object of a writer connection. Like, you need write access, bestie.vbufβ pointer to the region of the value.vsizβ size of that region.cpmodeβ detail adjustment, and itβs giving three choices:BDBCPCURRENTβ the value of the current record is overwritten.BDBCPBEFOREβ the new record is inserted before the current record.BDBCPAFTERβ the new record is inserted after the current record.
If it slays, the return value is true; otherwise, itβs false. And false shows up when the cursor is at an invalid position. π
After insertion, the cursor is moved to the inserted record. So it follows the new kid. π«
π«Ά tcbdbcurput2 π«Ά
bool tcbdbcurput2(BDBCUR *cur, const char *vstr, int cpmode);
This one is for inserting a string record around a cursor object.
curβ the cursor object of a writer connection.vstrβ the string of the value.cpmodeβ same detail adjustment as above:BDBCPCURRENTβ overwrite the current recordβs value.BDBCPBEFOREβ insert before the current record.BDBCPAFTERβ insert after the current record.
If successful, return value is true; else false. false when the cursor is at an invalid position.
After insertion, the cursor is moved to the inserted record. Periodt. β¨
ποΈ tcbdbcurout ποΈ
bool tcbdbcurout(BDBCUR *cur);
This removes the record where a cursor object is. Bye-bye, data!
curβ the cursor object of a writer connection.
If successful, the return value is true; else false. false when the cursor is at an invalid position.
After deletion, the cursor is moved to the next record if possible. So it doesnβt just ghost you. π»
π tcbdbcurkey π
char *tcbdbcurkey(BDBCUR *cur, int *sp);
Gets the key of the record where the cursor object is.
curβ the cursor object.spβ 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 key; else itβs NULL. NULL is returned when the cursor is at an invalid position.
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. And 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. Donβt leak, bestie! π§
π tcbdbcurkey2 π
char *tcbdbcurkey2(BDBCUR *cur);
Gets the key string of the record where the cursor object is.
curβ the cursor object.
If successful, the return value is the string of the key; else itβs NULL. NULL is returned when the cursor is at an invalid position.
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. Memory hygiene is self-care. π§Ό
π tcbdbcurkey3 π
const char *tcbdbcurkey3(BDBCUR *cur, int *sp);
Gets the key of the record where the cursor object is, as a volatile buffer.
curβ the cursor object.spβ 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 key; else itβs NULL. NULL is returned when the cursor is at an invalid position.
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. But because the region of the return value is volatile and it may be spoiled by another operation of the database, the data should be copied into another involatile buffer immediately. Like, copy it NOW, no waiting. πββοΈπ¨
π tcbdbcurval π
char *tcbdbcurval(BDBCUR *cur, int *sp);
Gets the value of the record where the cursor object is.
curβ the cursor object.spβ 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; else itβs NULL. NULL is returned when the cursor is at an invalid position.
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. Free it, queen. π
π tcbdbcurval2 π
char *tcbdbcurval2(BDBCUR *cur);
Gets the value string of the record where the cursor object is.
curβ the cursor object.
If successful, the return value is the string of the value; else itβs NULL. NULL is returned when the cursor is at an invalid position.
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. Donβt forget, bestie! π
π tcbdbcurval3 π
const char *tcbdbcurval3(BDBCUR *cur, int *sp);
Gets the value of the record where the cursor object is, as a volatile buffer.
curβ the cursor object.spβ 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; else itβs NULL. NULL is returned when the cursor is at an invalid position.
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 volatile and it may be spoiled by another operation of the database, the data should be copied into another involatile buffer immediately. Immediately immediately. β°
π¦ tcbdbcurrec π¦
bool tcbdbcurrec(BDBCUR *cur, TCXSTR *kxstr, TCXSTR *vxstr);
Gets the key and the value of the record where the cursor object is.
curβ the cursor object.kxstrβ the object into which the key is wrote down.vxstrβ the object into which the value is wrote down.
If successful, the return value is true; else itβs false. false is returned when the cursor is at an invalid position. Two for one, iconic. π
β¨ SEE ALSO β¨
Signed, sealed, delivered: this whole vibe is from the TCBDB(3) man page, Man Page edition, dated 2012-08-18. Stay iconic, bestie. ππ¦β¨
π¦ 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