?? tcbdb.3
字號:
.TH "TCBDB" 3 "2009-02-13" "Man Page" "Tokyo Cabinet".SH NAMEtcbdb \- the B+ tree database API.SH DESCRIPTION.PPB+ tree database is a file containing a B+ tree and is handled with the B+ tree database API..PPTo use the B+ tree database API, include `\fBtcutil.h\fR', `\fBtcbdb.h\fR', and related standard header files. Usually, write the following description near the front of a source file..PP.RS.br\fB#include <tcutil.h>\fR.br\fB#include <tcbdb.h>\fR.br\fB#include <stdlib.h>\fR.br\fB#include <time.h>\fR.br\fB#include <stdbool.h>\fR.br\fB#include <stdint.h>\fR.RE.PPObjects whose type is pointer to `\fBTCBDB\fR' are used to handle B+ tree databases. A B+ tree database object is created with the function `\fBtcbdbnew\fR' and is deleted with the function `\fBtcbdbdel\fR'. To avoid memory leak, it is important to delete every object when it is no longer in use..PPBefore 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 `\fBtcbdbopen\fR' is used to open a database file and the function `\fBtcbdbclose\fR' 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..SH API.PPThe function `tcbdberrmsg' is used in order to get the message string corresponding to an error code..PP.RS.br\fBconst char *tcbdberrmsg(int \fIecode\fB);\fR.RS`\fIecode\fR' specifies the error code..RE.RSThe return value is the message string of the error code..RE.RE.PPThe function `tcbdbnew' is used in order to create a B+ tree database object..PP.RS.br\fBTCBDB *tcbdbnew(void);\fR.RSThe return value is the new B+ tree database object..RE.RE.PPThe function `tcbdbdel' is used in order to delete a B+ tree database object..PP.RS.br\fBvoid tcbdbdel(TCBDB *\fIbdb\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object..RE.RSIf the database is not closed, it is closed implicitly. Note that the deleted object and its derivatives can not be used anymore..RE.RE.PPThe function `tcbdbecode' is used in order to get the last happened error code of a B+ tree database object..PP.RS.br\fBint tcbdbecode(TCBDB *\fIbdb\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object..RE.RSThe return value is the last happened error code..RE.RSThe following error codes are defined: `TCESUCCESS' for success, `TCETHREAD' for threading error, `TCEINVALID' for invalid operation, `TCENOFILE' for file not found, `TCENOPERM' for no permission, `TCEMETA' for invalid meta data, `TCERHEAD' for invalid record header, `TCEOPEN' for open error, `TCECLOSE' for close error, `TCETRUNC' for trunc error, `TCESYNC' for sync error, `TCESTAT' for stat error, `TCESEEK' for seek error, `TCEREAD' for read error, `TCEWRITE' for write error, `TCEMMAP' for mmap error, `TCELOCK' for lock error, `TCEUNLINK' for unlink error, `TCERENAME' for rename error, `TCEMKDIR' for mkdir error, `TCERMDIR' for rmdir error, `TCEKEEP' for existing record, `TCENOREC' for no record found, and `TCEMISC' for miscellaneous error..RE.RE.PPThe function `tcbdbsetmutex' is used in order to set mutual exclusion control of a B+ tree database object for threading..PP.RS.br\fBbool tcbdbsetmutex(TCBDB *\fIbdb\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object which is not opened..RE.RSIf successful, the return value is true, else, it is false..RE.RSNote that the mutual exclusion control of the database should be set before the database is opened..RE.RE.PPThe function `tcbdbsetcmpfunc' is used in order to set the custom comparison function of a B+ tree database object..PP.RS.br\fBbool tcbdbsetcmpfunc(TCBDB *\fIbdb\fB, TCCMP \fIcmp\fB, void *\fIcmpop\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object which is not opened..RE.RS`\fIcmp\fR' specifies 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..RE.RS`\fIcmpop\fR' specifies an arbitrary pointer to be given as a parameter of the comparison function. If it is not needed, `NULL' can be specified..RE.RSIf successful, the return value is true, else, it is false..RE.RSThe default comparison function compares keys of two records by lexical order. The functions `tccmplexical' (dafault), `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..RE.RE.PPThe function `tcbdbtune' is used in order to set the tuning parameters of a B+ tree database object..PP.RS.br\fBbool tcbdbtune(TCBDB *\fIbdb\fB, int32_t \fIlmemb\fB, int32_t \fInmemb\fB, int64_t \fIbnum\fB, int8_t \fIapow\fB, int8_t \fIfpow\fB, uint8_t \fIopts\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object which is not opened..RE.RS`\fIlmemb\fR' specifies 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..RE.RS`\fInmemb\fR' specifies 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..RE.RS`\fIbnum\fR' specifies 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..RE.RS`\fIapow\fR' specifies 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..RE.RS`\fIfpow\fR' specifies 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..RE.RS`\fIopts\fR' specifies options by bitwise-or: `BDBTLARGE' specifies that the size of the database can be larger than 2GB by using 64\-bit bucket array, `BDBTDEFLATE' specifies that each page is compressed with Deflate encoding, `BDBTBZIP' specifies that each page is compressed with BZIP2 encoding, `BDBTTCBS' specifies that each page is compressed with TCBS encoding..RE.RSIf successful, the return value is true, else, it is false..RE.RSNote that the tuning parameters should be set before the database is opened..RE.RE.PPThe function `tcbdbsetcache' is used in order to set the caching parameters of a B+ tree database object..PP.RS.br\fBbool tcbdbsetcache(TCBDB *\fIbdb\fB, int32_t \fIlcnum\fB, int32_t \fIncnum\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object which is not opened..RE.RS`\fIlcnum\fR' specifies 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..RE.RS`\fIncnum\fR' specifies 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..RE.RSIf successful, the return value is true, else, it is false..RE.RSNote that the caching parameters should be set before the database is opened..RE.RE.PPThe function `tcbdbsetxmsiz' is used in order to set the size of the extra mapped memory of a B+ tree database object..PP.RS.br\fBbool tcbdbsetxmsiz(TCBDB *\fIbdb\fB, int64_t \fIxmsiz\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object which is not opened..RE.RS`\fIxmsiz\fR' specifies 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..RE.RSIf successful, the return value is true, else, it is false..RE.RSNote that the mapping parameters should be set before the database is opened..RE.RE.PPThe function `tcbdbopen' is used in order to open a database file and connect a B+ tree database object..PP.RS.br\fBbool tcbdbopen(TCBDB *\fIbdb\fB, const char *\fIpath\fB, int \fIomode\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object which is not opened..RE.RS`\fIpath\fR' specifies the path of the database file..RE.RS`\fIomode\fR' specifies the connection mode: `BDBOWRITER' as a writer, `BDBOREADER' as a reader. If the mode is `BDBOWRITER', the following may be added by bitwise-or: `BDBOCREAT', which means it creates a new database if not exist, `BDBOTRUNC', which means it creates a new database regardless if one exists, `BDBOTSYNC', which means every transaction synchronizes updated contents with the device. Both of `BDBOREADER' and `BDBOWRITER' can be added to by bitwise-or: `BDBONOLCK', which means it opens the database file without file locking, or `BDBOLCKNB', which means locking is performed without blocking..RE.RSIf successful, the return value is true, else, it is false..RE.RE.PPThe function `tcbdbclose' is used in order to close a B+ tree database object..PP.RS.br\fBbool tcbdbclose(TCBDB *\fIbdb\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object..RE.RSIf successful, the return value is true, else, it is false..RE.RSUpdate 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..RE.RE.PPThe function `tcbdbput' is used in order to store a record into a B+ tree database object..PP.RS.br\fBbool tcbdbput(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the key..RE.RS`\fIksiz\fR' specifies the size of the region of the key..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, it is overwritten..RE.RE.PPThe function `tcbdbput2' is used in order to store a string record into a B+ tree database object..PP.RS.br\fBbool tcbdbput2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkstr\fR' specifies the string of the key..RE.RS`\fIvstr\fR' specifies the string of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, it is overwritten..RE.RE.PPThe function `tcbdbputkeep' is used in order to store a new record into a B+ tree database object..PP.RS.br\fBbool tcbdbputkeep(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the key..RE.RS`\fIksiz\fR' specifies the size of the region of the key..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, this function has no effect..RE.RE.PPThe function `tcbdbputkeep2' is used in order to store a new string record into a B+ tree database object..PP.RS.br\fBbool tcbdbputkeep2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkstr\fR' specifies the string of the key..RE.RS`\fIvstr\fR' specifies the string of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, this function has no effect..RE.RE.PPThe function `tcbdbputcat' is used in order to concatenate a value at the end of the existing record in a B+ tree database object..PP.RS.br\fBbool tcbdbputcat(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the key..RE.RS`\fIksiz\fR' specifies the size of the region of the key..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf there is no corresponding record, a new record is created..RE.RE.PPThe function `tcbdbputcat2' is used in order to concatenate a string value at the end of the existing record in a B+ tree database object..PP.RS.br\fBbool tcbdbputcat2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkstr\fR' specifies the string of the key..RE.RS`\fIvstr\fR' specifies the string of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf there is no corresponding record, a new record is created..RE.RE.PPThe function `tcbdbputdup' is used in order to store a record into a B+ tree database object with allowing duplication of keys..PP.RS.br\fBbool tcbdbputdup(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the key..RE.RS`\fIksiz\fR' specifies the size of the region of the key..RE.RS`\fIvbuf\fR' specifies the pointer to the region of the value..RE.RS`\fIvsiz\fR' specifies the size of the region of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, the new record is placed after the existing one..RE.RE.PPThe function `tcbdbputdup2' is used in order to store a string record into a B+ tree database object with allowing duplication of keys..PP.RS.br\fBbool tcbdbputdup2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkstr\fR' specifies the string of the key..RE.RS`\fIvstr\fR' specifies the string of the value..RE.RSIf successful, the return value is true, else, it is false..RE.RSIf a record with the same key exists in the database, the new record is placed after the existing one..RE.RE.PPThe function `tcbdbputdup3' is used in order to store records into a B+ tree database object with allowing duplication of keys..PP.RS.br\fBbool tcbdbputdup3(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const TCLIST *\fIvals\fB);\fR.RS`\fIbdb\fR' specifies the B+ tree database object connected as a writer..RE.RS`\fIkbuf\fR' specifies the pointer to the region of the common key..RE.RS`\fIksiz\fR' specifies the size of the region of the common key..RE
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -