📄 tchdb.h
字号:
/* Get the file path of a hash database object. `hdb' specifies the hash database object. The return value is the path of the database file or `NULL' if the object does not connect to any database file. */const char *tchdbpath(TCHDB *hdb);/* Get the number of records of a hash database object. `hdb' specifies the hash database object. The return value is the number of records or 0 if the object does not connect to any database file. */uint64_t tchdbrnum(TCHDB *hdb);/* Get the size of the database file of a hash database object. `hdb' specifies the hash database object. The return value is the size of the database file or 0 if the object does not connect to any database file. */uint64_t tchdbfsiz(TCHDB *hdb);/************************************************************************************************* * features for experts *************************************************************************************************//* Set the error code of a hash database object. `hdb' specifies the hash database object. `ecode' specifies the error code. `file' specifies the file name of the code. `line' specifies the line number of the code. `func' specifies the function name of the code. */void tchdbsetecode(TCHDB *hdb, int ecode, const char *filename, int line, const char *func);/* Set the type of a hash database object. `hdb' specifies the hash database object. `type' specifies the database type. */void tchdbsettype(TCHDB *hdb, uint8_t type);/* Set the file descriptor for debugging output. `hdb' specifies the hash database object. `fd' specifies the file descriptor for debugging output. */void tchdbsetdbgfd(TCHDB *hdb, int fd);/* Get the file descriptor for debugging output. `hdb' specifies the hash database object. The return value is the file descriptor for debugging output. */int tchdbdbgfd(TCHDB *hdb);/* Check whether mutual exclusion control is set to a hash database object. `hdb' specifies the hash database object. If mutual exclusion control is set, it is true, else it is false. */bool tchdbhasmutex(TCHDB *hdb);/* Synchronize updating contents on memory of a hash database object. `hdb' specifies the hash database object connected as a writer. `phys' specifies whether to synchronize physically. If successful, the return value is true, else, it is false. */bool tchdbmemsync(TCHDB *hdb, bool phys);/* Clear the cache of a hash tree database object. `hdb' specifies the hash tree database object. If successful, the return value is true, else, it is false. */bool tchdbcacheclear(TCHDB *hdb);/* Get the number of elements of the bucket array of a hash database object. `hdb' specifies the hash database object. The return value is the number of elements of the bucket array or 0 if the object does not connect to any database file. */uint64_t tchdbbnum(TCHDB *hdb);/* Get the record alignment of a hash database object. `hdb' specifies the hash database object. The return value is the record alignment or 0 if the object does not connect to any database file. */uint32_t tchdbalign(TCHDB *hdb);/* Get the maximum number of the free block pool of a a hash database object. `hdb' specifies the hash database object. The return value is the maximum number of the free block pool or 0 if the object does not connect to any database file. */uint32_t tchdbfbpmax(TCHDB *hdb);/* Get the size of the extra mapped memory of a hash database object. `hdb' specifies the hash database object. The return value is the size of the extra mapped memory or 0 if the object does not connect to any database file. */uint64_t tchdbxmsiz(TCHDB *hdb);/* Get the inode number of the database file of a hash database object. `hdb' specifies the hash database object. The return value is the inode number of the database file or 0 if the object does not connect to any database file. */uint64_t tchdbinode(TCHDB *hdb);/* Get the modification time of the database file of a hash database object. `hdb' specifies the hash database object. The return value is the inode number of the database file or 0 if the object does not connect to any database file. */time_t tchdbmtime(TCHDB *hdb);/* Get the connection mode of a hash database object. `hdb' specifies the hash database object. The return value is the connection mode. */int tchdbomode(TCHDB *hdb);/* Get the database type of a hash database object. `hdb' specifies the hash database object. The return value is the database type. */uint8_t tchdbtype(TCHDB *hdb);/* Get the additional flags of a hash database object. `hdb' specifies the hash database object. The return value is the additional flags. */uint8_t tchdbflags(TCHDB *hdb);/* Get the options of a hash database object. `hdb' specifies the hash database object. The return value is the options. */uint8_t tchdbopts(TCHDB *hdb);/* Get the pointer to the opaque field of a hash database object. `hdb' specifies the hash database object. The return value is the pointer to the opaque field whose size is 128 bytes. */char *tchdbopaque(TCHDB *hdb);/* Get the number of used elements of the bucket array of a hash database object. `hdb' specifies the hash database object. The return value is the number of used elements of the bucket array or 0 if the object does not connect to any database file. */uint64_t tchdbbnumused(TCHDB *hdb);/* Set the custom codec functions of a hash database object. `hdb' specifies the hash database object. `enc' specifies the pointer to the custom encoding function. It receives four parameters. The first parameter is the pointer to the region. The second parameter is the size of the region. The third parameter is the pointer to the variable into which the size of the region of the return value is assigned. The fourth parameter is the pointer to the optional opaque object. It returns the pointer to the result object allocated with `malloc' call if successful, else, it returns `NULL'. `encop' specifies an arbitrary pointer to be given as a parameter of the encoding function. If it is not needed, `NULL' can be specified. `dec' specifies the pointer to the custom decoding function. `decop' specifies an arbitrary pointer to be given as a parameter of the decoding function. If it is not needed, `NULL' can be specified. If successful, the return value is true, else, it is false. Note that the custom codec functions should be set before the database is opened and should be set every time the database is being opened. */bool tchdbsetcodecfunc(TCHDB *hdb, TCCODEC enc, void *encop, TCCODEC dec, void *decop);/* Get the custom codec functions of a hash database object. `hdb' specifies the hash database object. `ep' specifies the pointer to a variable into which the pointer to the custom encoding function is assigned `eop' specifies the pointer to a variable into which the arbitrary pointer to be given to the encoding function is assigned. `dp' specifies the pointer to a variable into which the pointer to the custom decoding function is assigned `dop' specifies the pointer to a variable into which the arbitrary pointer to be given to the decoding function is assigned. */void tchdbcodecfunc(TCHDB *hdb, TCCODEC *ep, void **eop, TCCODEC *dp, void **dop);/* Store a record into a hash database object with a duplication handler. `hdb' specifies the hash database object connected as a writer. `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. `NULL' means that record addition is ommited if there is no corresponding record. `vsiz' specifies the size of the region of the value. `proc' specifies the pointer to the callback function to process duplication. It receives four parameters. The first parameter is the pointer to the region of the value. The second parameter is the size of the region of the value. The third parameter is the pointer to the variable into which the size of the region of the return value is assigned. The fourth parameter is the pointer to the optional opaque object. It returns the pointer to the result object allocated with `malloc'. It is released by the caller. If it is `NULL', the record is not modified. If it is `(void *)-1', the record is removed. `op' specifies an arbitrary pointer to be given as a parameter of the callback function. If it is not needed, `NULL' can be specified. If successful, the return value is true, else, it is false. */bool tchdbputproc(TCHDB *hdb, const void *kbuf, int ksiz, const char *vbuf, int vsiz, TCPDPROC proc, void *op);/* Retrieve the next record of a record in a hash database object. `hdb' specifies the hash database object. `kbuf' specifies the pointer to the region of the key. If it is `NULL', the first record is retrieved. `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 key of the next 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. */void *tchdbgetnext(TCHDB *hdb, const void *kbuf, int ksiz, int *sp);/* Retrieve the next string record in a hash database object. `hdb' specifies the hash database object. `kstr' specifies the string of the key. If it is `NULL', the first record is retrieved. If successful, the return value is the string of the key of the next record. `NULL' is returned if no record corresponds. 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. */char *tchdbgetnext2(TCHDB *hdb, const char *kstr);/* Retrieve the key and the value of the next record of a record in a hash database object. `hdb' specifies the hash 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. `vbp' specifies the pointer to the variable into which the pointer to the value is assigned. `vsp' specifies the pointer to the variable into which the size of the value is assigned. If successful, the return value is the pointer to the region of the key of the next record. 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. The retion pointed to by `vbp' should not be released. */char *tchdbgetnext3(TCHDB *hdb, const char *kbuf, int ksiz, int *sp, const char **vbp, int *vsp);/* Process each record atomically of a hash database object. `hdb' specifies the hash database object. `iter' specifies the pointer to the iterator function called for each record. It receives five parameters. The first parameter is the pointer to the region of the key. The second parameter is the size of the region of the key. The third parameter is the pointer to the region of the value. The fourth parameter is the size of the region of the value. The fifth parameter is the pointer to the optional opaque object. It returns true to continue iteration or false to stop iteration. `op' specifies an arbitrary pointer to be given as a parameter of the iterator function. If it is not needed, `NULL' can be specified. If successful, the return value is true, else, it is false. */bool tchdbforeach(TCHDB *hdb, TCITER iter, void *op);/* Void the transaction of a hash database object. `hdb' specifies the hash database object connected as a writer. If successful, the return value is true, else, it is false. This function should be called only when no update in the transaction. */bool tchdbtranvoid(TCHDB *hdb);__TCHDB_CLINKAGEEND#endif /* duplication check *//* END OF FILE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -