📄 tcutil.h
字号:
/* Store a record and make it semivolatile in a map object. `map' specifies the map 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 map, it is overwritten. The record is moved to the tail. */void tcmapput3(TCMAP *map, const void *kbuf, int ksiz, const char *vbuf, int vsiz);/* Store a record of the value of two regions into a map object. `map' specifies the map 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 map, it is overwritten. */void tcmapput4(TCMAP *map, const void *kbuf, int ksiz, const void *fvbuf, int fvsiz, const void *lvbuf, int lvsiz);/* Concatenate a value at the existing record and make it semivolatile in a map object. `map' specifies the map 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 tcmapputcat3(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Store a record into a map object with a duplication handler. `map' specifies the map 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. `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 tcmapputproc(TCMAP *map, const void *kbuf, int ksiz, const char *vbuf, int vsiz, TCPDPROC proc, void *op);/* Retrieve a semivolatile record in a map object. `map' specifies the map 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. 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. */const void *tcmapget3(TCMAP *map, const void *kbuf, int ksiz, int *sp);/* Get the value bound to the key fetched from the iterator of a map object. `kbuf' specifies the pointer to the region of the iteration key. `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 value of the corresponding record. 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. */const void *tcmapiterval(const void *kbuf, int *sp);/* Get the value string bound to the key fetched from the iterator of a map object. `kstr' specifies the string of the iteration key. The return value is the pointer to the region of the value of the corresponding record. */const char *tcmapiterval2(const char *kstr);/* Create an array of strings of all keys in a map object. `map' specifies the map object. `np' specifies the pointer to a variable into which the number of elements of the return value is assigned. The return value is the pointer to the array of all string keys in the map object. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use. Note that elements of the array point to the inner objects, whose life duration is synchronous with the map object. */const char **tcmapkeys2(const TCMAP *map, int *np);/* Create an array of strings of all values in a map object. `map' specifies the map object. `np' specifies the pointer to a variable into which the number of elements of the return value is assigned. The return value is the pointer to the array of all string values in the map object. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use. Note that elements of the array point to the inner objects, whose life duration is synchronous with the map object. */const char **tcmapvals2(const TCMAP *map, int *np);/* Extract a map 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 *tcmaploadone(const void *ptr, int size, const void *kbuf, int ksiz, int *sp);/************************************************************************************************* * ordered tree *************************************************************************************************/typedef struct _TCTREEREC { /* type of structure for an element of a tree */ uint32_t ksiz; /* size of the region of the key */ uint32_t vsiz; /* size of the region of the value */ struct _TCTREEREC *left; /* pointer to the left child */ struct _TCTREEREC *right; /* pointer to the right child */} TCTREEREC;typedef struct { /* type of structure for a tree */ TCTREEREC *root; /* pointer to the root element */ TCTREEREC *cur; /* pointer to the current element */ uint64_t rnum; /* number of records */ uint64_t msiz; /* total size of records */ TCCMP cmp; /* pointer to the comparison function */ void *cmpop; /* opaque object for the comparison function */} TCTREE;/* Create a tree object. The return value is the new tree object. */TCTREE *tctreenew(void);/* Create a tree object with specifying the custom comparison function. `cmp' 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. `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 the new tree object. The default comparison function compares keys of two records by lexical order. The functions `tccmplexical' (dafault), `tccmpdecimal', `tccmpint32', and `tccmpint64' are built-in. */TCTREE *tctreenew2(TCCMP cmp, void *cmpop);/* Copy a tree object. `tree' specifies the tree object. The return value is the new tree object equivalent to the specified object. */TCTREE *tctreedup(const TCTREE *tree);/* Delete a tree object. `tree' specifies the tree object. Note that the deleted object and its derivatives can not be used anymore. */void tctreedel(TCTREE *tree);/* Store a record into 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. `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 tree, it is overwritten. */void tctreeput(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Store a string record into a tree object. `tree' specifies the tree 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 tree, it is overwritten. */void tctreeput2(TCTREE *tree, const char *kstr, const char *vstr);/* Store a new record into 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. `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 tree, this function has no effect. */bool tctreeputkeep(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Store a new string record into a tree object. `tree' specifies the tree 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 tree, this function has no effect. */bool tctreeputkeep2(TCTREE *tree, const char *kstr, const char *vstr);/* Concatenate a value at the end of the value of the existing 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. `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 tctreeputcat(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);/* Concatenate a string value at the end of the value of the existing record in a tree object. `tree' specifies the tree 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 tctreeputcat2(TCTREE *tree, const char *kstr, const char *vstr);/* Store a record into a tree object with a duplication handler. `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. `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 tctreeputproc(TCTREE *tree, const void *kbuf, int ksiz, const char *vbuf, int vsiz, TCPDPROC proc, void *op);/* Remove a record of 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. If successful, the return value is true. False is returned when no record corresponds to the specified key. */bool tctreeout(TCTREE *tree, const void *kbuf, int ksiz);/* Remove a string record of a tree object. `tree' specifies the tree 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 tctreeout2(TCTREE *tree, const char *kstr);/* Retrieve 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. `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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -