📄 tcutil.h
字号:
/* Add a real number to a record in a tree object. `tree' specifies the tree object. `kbuf' specifies the pointer to the region of the key. `ksiz' specifies the size of the region of the key. `num' specifies the additional value. The return value is the summation value. 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. */double tctreeadddouble(TCTREE *tree, const void *kbuf, int ksiz, double num);/* Clear a tree object. `tree' specifies the tree object. All records are removed. */void tctreeclear(TCTREE *tree);/* Remove fringe records of a tree object. `tree' specifies the tree object. `num' specifies the number of records to be removed. */void tctreecutfringe(TCTREE *tree, int num);/* Serialize a tree object into a byte array. `tree' specifies the tree object. `sp' specifies the pointer to the variable into which the size of the region of the return value is assigned. The return value is the pointer to the region of the result serial region. 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 *tctreedump(const TCTREE *tree, int *sp);/* Create a tree object from a serialized byte array. `ptr' specifies the pointer to the region of serialized byte array. `size' specifies the size of the region. `cmp' specifies the pointer to the custom comparison function. `cmpop' specifies an arbitrary pointer to be given as a parameter of the comparison function. If it is not needed, `NULL' can be specified. The return value is a new tree object. Because the object of the return value is created with the function `tctreenew', it should be deleted with the function `tctreedel' when it is no longer in use. */TCTREE *tctreeload(const void *ptr, int size, TREECMP cmp, void *cmpop);/* Extract a tree record from a serialized byte array. `ptr' specifies the pointer to the region of serialized byte array. `size' specifies the size of the region. `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 when 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. */void *tctreeloadone(const void *ptr, int size, const void *kbuf, int ksiz, int *sp);/************************************************************************************************* * on-memory hash database *************************************************************************************************/typedef struct { /* type of structure for a on-memory hash database */ void **mmtxs; /* mutexes for method */ void *imtx; /* mutex for iterator */ TCMAP **maps; /* internal map objects */ int iter; /* index of maps for the iterator */} TCMDB;/* Create an on-memory hash database object. The return value is the new on-memory hash database object. The object can be shared by plural threads because of the internal mutex. */TCMDB *tcmdbnew(void);/* Create an on-memory hash database object with specifying the number of the buckets. `bnum' specifies the number of the buckets. The return value is the new on-memory hash database object. The object can be shared by plural threads because of the internal mutex. */TCMDB *tcmdbnew2(uint32_t bnum);/* Delete an on-memory hash database object. `mdb' specifies the on-memory hash database object. */void tcmdbdel(TCMDB *mdb);/* Store a record into an on-memory hash database object. `mdb' specifies the on-memory hash 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 a record with the same key exists in the database, it is overwritten. */void tcmdbput(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Store a string record into an on-memory hash database object. `mdb' specifies the on-memory hash database object. `kstr' specifies the string of the key. `vstr' specifies the string of the value. If a record with the same key exists in the database, it is overwritten. */void tcmdbput2(TCMDB *mdb, const char *kstr, const char *vstr);/* Store a record of the value of two regions into an on-memory hash database object. `mdb' specifies the on-memory hash database object. `kbuf' specifies the pointer to the region of the key. `ksiz' specifies the size of the region of the key. `fvbuf' specifies the pointer to the former region of the value. `fvsiz' specifies the size of the former region of the value. `lvbuf' specifies the pointer to the latter region of the value. `lvsiz' specifies the size of the latter region of the value. If a record with the same key exists in the database, it is overwritten. */void tcmdbput3(TCMDB *mdb, const void *kbuf, int ksiz, const void *fvbuf, int fvsiz, const void *lvbuf, int lvsiz);/* Store a new record into an on-memory hash database object. `mdb' specifies the on-memory hash 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. */bool tcmdbputkeep(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Store a new string record into an on-memory hash database object. `mdb' specifies the on-memory hash 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. */bool tcmdbputkeep2(TCMDB *mdb, const char *kstr, const char *vstr);/* Concatenate a value at the end of the existing record in an on-memory hash database. `mdb' specifies the on-memory hash 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 there is no corresponding record, a new record is created. */void tcmdbputcat(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Concatenate a string at the end of the existing record in an on-memory hash database. `mdb' specifies the on-memory hash database object. `kstr' specifies the string of the key. `vstr' specifies the string of the value. If there is no corresponding record, a new record is created. */void tcmdbputcat2(TCMDB *mdb, const char *kstr, const char *vstr);/* Remove a record of an on-memory hash database object. `mdb' specifies the on-memory hash 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. False is returned when no record corresponds to the specified key. */bool tcmdbout(TCMDB *mdb, const void *kbuf, int ksiz);/* Remove a string record of an on-memory hash database object. `mdb' specifies the on-memory hash database object. `kstr' specifies the string of the key. If successful, the return value is true. False is returned when no record corresponds to the specified key. */bool tcmdbout2(TCMDB *mdb, const char *kstr);/* Retrieve a record in an on-memory hash database object. `mdb' specifies the on-memory 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. If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when 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 *tcmdbget(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);/* Retrieve a string record in an on-memory hash database object. `mdb' specifies the on-memory hash database object. `kstr' specifies the string of the key. If successful, the return value is the string of the value of the corresponding record. `NULL' is returned when 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 *tcmdbget2(TCMDB *mdb, const char *kstr);/* Retrieve a record and move it astern in an on-memory hash database object. `mdb' specifies the on-memory 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. If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when 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. The internal region of the returned record is moved to the tail so that the record will survive for a time under LRU cache algorithm removing records from the head. */void *tcmdbget3(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);/* Get the size of the value of a record in an on-memory hash database object. `mdb' specifies the on-memory hash 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 the size of the value of the corresponding record, else, it is -1. */int tcmdbvsiz(TCMDB *mdb, const void *kbuf, int ksiz);/* Get the size of the value of a string record in an on-memory hash database object. `mdb' specifies the on-memory hash database object. `kstr' specifies the string of the key. If successful, the return value is the size of the value of the corresponding record, else, it is -1. */int tcmdbvsiz2(TCMDB *mdb, const char *kstr);/* Initialize the iterator of an on-memory hash database object. `mdb' specifies the on-memory hash database object. The iterator is used in order to access the key of every record stored in the on-memory database. */void tcmdbiterinit(TCMDB *mdb);/* Get the next key of the iterator of an on-memory hash database object. `mdb' specifies the on-memory hash database object. `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 next key, else, it is `NULL'. `NULL' is returned when no record can be fetched from the iterator. 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. The order of iteration is assured to be the same as the stored order. */void *tcmdbiternext(TCMDB *mdb, int *sp);/* Get the next key string of the iterator of an on-memory hash database object. `mdb' specifies the on-memory hash database object. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record can be fetched from the iterator. 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 order of iteration is assured to be the same as the stored order. */char *tcmdbiternext2(TCMDB *mdb);/* Get forward matching keys in an on-memory hash database object. `mdb' specifies the on-memory hash database object. `pbuf' specifies the pointer to the region of the prefix. `psiz' specifies the size of the region of the prefix. `max' specifies 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. This function does never fail and return an empty list even if no key corresponds. Because the object of the return value is created with the function `tclistnew', it should be
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -