📄 tcutil.h
字号:
/* type of the pointer to a comparison function. `aptr' specifies the pointer to the region of one key. `asiz' specifies the size of the region of one key. `bptr' specifies the pointer to the region of the other key. `bsiz' specifies the size of the region of the other key. `op' specifies the pointer to the optional opaque object. The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent. */typedef int (*TREECMP)(const char *aptr, int asiz, const char *bptr, int bsiz, void *op);typedef struct _TCTREEREC { /* type of structure for an element of a tree */ int ksiz; /* size of the region of the key */ int 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 */ TREECMP 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. `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 `tctreecmplexical' (dafault), `tctreecmpdecimal', `tctreecmpint32', and `tctreecmpint64' are built-in. */TCTREE *tctreenew2(TREECMP 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);/* 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. 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 *tctreeget(TCTREE *tree, const void *kbuf, int ksiz, int *sp);/* Retrieve a string record in a tree object. `tree' specifies the tree 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. */const char *tctreeget2(TCTREE *tree, const char *kstr);/* Retrieve a record in a tree object without balancing nodes. `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. 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 *tctreeget3(const TCTREE *tree, const void *kbuf, int ksiz, int *sp);/* Initialize the iterator of a tree object. `tree' specifies the tree object. The iterator is used in order to access the key of every record stored in the tree object. */void tctreeiterinit(TCTREE *tree);/* Initialize the iterator of a tree object in front of records corresponding a key. `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. The iterator is set to the first record corresponding the key or the next substitute if completely matching record does not exist. */void tctreeiterinit2(TCTREE *tree, const void *kbuf, int ksiz);/* Initialize the iterator of a tree object in front of records corresponding a key string. `tree' specifies the tree object. `kstr' specifies the string of the key. The iterator is set to the first record corresponding the key or the next substitute if completely matching record does not exist. */void tctreeiterinit3(TCTREE *tree, const char *kstr);/* Get the next key of the iterator of a tree object. `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. 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. The order of iteration is assured to be ascending of the keys. */const void *tctreeiternext(TCTREE *tree, int *sp);/* Get the next key string of the iterator of a tree object. `tree' specifies the tree 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. The order of iteration is assured to be ascending of the keys. */const char *tctreeiternext2(TCTREE *tree);/* Get the value bound to the key fetched from the iterator of a tree 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 *tctreeiterval(const void *kbuf, int *sp);/* Get the value string bound to the key fetched from the iterator of a tree 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 *tctreeiterval2(const char *kstr);/* Get the number of records stored in a tree object. `tree' specifies the tree object. The return value is the number of the records stored in the tree object. */uint64_t tctreernum(const TCTREE *tree);/* Get the total size of memory used in a tree object. `tree' specifies the tree object. The return value is the total size of memory used in a tree object. */uint64_t tctreemsiz(const TCTREE *tree);/* Create a list object containing all keys in a tree object. `tree' specifies the tree object. The return value is the new list object containing all keys in the tree object. Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use. */TCLIST *tctreekeys(const TCTREE *tree);/* Create an array of strings of all keys in a tree object. `tree' specifies the tree 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 tree 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 tree object. */const char **tctreekeys2(const TCTREE *tree, int *np);/* Create a list object containing all values in a tree object. `tree' specifies the tree object. The return value is the new list object containing all values in the tree object. Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use. */TCLIST *tctreevals(const TCTREE *tree);/* Create an array of strings of all values in a tree object. `tree' specifies the tree 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 tree 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 tree object. */const char **tctreevals2(const TCTREE *tree, int *np);/* Add an integer 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 an integer and is added to. If no record corresponds, a new record of the additional value is stored. */int tctreeaddint(TCTREE *tree, const void *kbuf, int ksiz, int num);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -