TCUTIL(3)
๐ TCUTIL ๐
okay bestie, welcome to TCUTIL(3), the utility API from Tokyo Cabinet โจ โ this is the section 3 manual page and it's a long one so buckle up, we're doing this together ๐ซถ
โจ NAME โจ
tcutil โ the utility API ๐
๐ธ DESCRIPTION ๐ธ
Okay so. The utility API is a whole set of routines that let you handle records on memory easily. And especially โ and I need you to hear me on this โ extensible string, array list, hash map, and ordered tree are useful. Like, genuinely iconic. ๐ฆ
To use the utility API, you include tcutil.h and the related standard header files. Usually you write this near the front of a source file:
#include <tcutil.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
Now, the object lineup, because you need to know who's who ๐
- Objects whose type is pointer to
TCXSTRare used for extensible string. An extensible string object is created withtcxstrnewand is deleted withtcxstrdel. - Objects whose type is pointer to
TCLISTare used for array list. A list object is created withtclistnewand is deleted withtclistdel. - Objects whose type is pointer to
TCMAPare used for hash map. A map object is created withtcmapnewand is deleted withtcmapdel. - Objects whose type is pointer to
TCTREEare used for ordered tree. A tree object is created withtctreenewand is deleted withtctreedel.
To avoid memory leak, it is important to delete every object when it is no longer in use. Like, this is the main character rule of memory management, no cap. ๐ฅ
๐ API OF BASIC UTILITIES ๐
The constant tcversion is the string containing the version information.
extern const char *tcversion;
The variable tcfatalfunc is the pointer to the call back function for handling a fatal error.
extern void (*tcfatalfunc)(const char *);
- The argument specifies the error message.
- The initial value of this variable is
NULL. If the value isNULL, the default function is called when a fatal error occurs. - A fatal error occurs when memory allocation is failed. ๐ญ
The function tcmalloc is used in order to allocate a region on memory.
void *tcmalloc(size_t size);
sizespecifies the size of the region.- The return value is the pointer to the allocated region.
- This function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. ๐
The function tccalloc is used in order to allocate a nullified region on memory.
void *tccalloc(size_t nmemb, size_t size);
nmembspecifies the number of elements.sizespecifies the size of each element.- The return value is the pointer to the allocated nullified region.
- This function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the
calloccall, it should be released with thefreecall when it is no longer in use. ๐
The function tcrealloc is used in order to re-allocate a region on memory.
void *tcrealloc(void *ptr, size_t size);
ptrspecifies the pointer to the region.sizespecifies the size of the region.- The return value is the pointer to the re-allocated region.
- This function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the
realloccall, it should be released with thefreecall when it is no longer in use. โจ
The function tcmemdup is used in order to duplicate a region on memory.
void *tcmemdup(const void *ptr, size_t size);
ptrspecifies the pointer to the region.sizespecifies the size of the region.- The return value is the pointer to the allocated region of the duplicate.
- 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
malloccall, it should be released with thefreecall when it is no longer in use. ๐ซถ
The function tcstrdup is used in order to duplicate a string on memory.
char *tcstrdup(const void *str);
strspecifies the string.- The return value is the allocated string equivalent to the specified string.
- Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. ๐ธ
The function tcfree is used in order to free a region on memory.
void tcfree(void *ptr);
ptrspecifies the pointer to the region. If it isNULL, this function has no effect.- Although this function is just a wrapper of
freecall, this is useful in applications using another package of themallocseries. ๐
๐ง API OF EXTENSIBLE STRING ๐ง
The function tcxstrnew is used in order to create an extensible string object.
TCXSTR *tcxstrnew(void);
- The return value is the new extensible string object. ๐
The function tcxstrnew2 is used in order to create an extensible string object from a character string.
TCXSTR *tcxstrnew2(const char *str);
strspecifies the string of the initial content.- The return value is the new extensible string object containing the specified string. โจ
The function tcxstrnew3 is used in order to create an extensible string object with the initial allocation size.
TCXSTR *tcxstrnew3(int asiz);
asizspecifies the initial allocation size.- The return value is the new extensible string object. ๐
The function tcxstrdup is used in order to copy an extensible string object.
TCXSTR *tcxstrdup(const TCXSTR *xstr);
xstrspecifies the extensible string object.- The return value is the new extensible string object equivalent to the specified object. ๐ฆ
The function tcxstrdel is used in order to delete an extensible string object.
void tcxstrdel(TCXSTR *xstr);
xstrspecifies the extensible string object.- Note that the deleted object and its derivatives can not be used anymore. ๐
The function tcxstrcat is used in order to concatenate a region to the end of an extensible string object.
void tcxstrcat(TCXSTR *xstr, const void *ptr, int size);
xstrspecifies the extensible string object.ptrspecifies the pointer to the region to be appended.sizespecifies the size of the region. ๐
The function tcxstrcat2 is used in order to concatenate a character string to the end of an extensible string object.
void tcxstrcat2(TCXSTR *xstr, const char *str);
xstrspecifies the extensible string object.strspecifies the string to be appended. ๐
The function tcxstrptr is used in order to get the pointer of the region of an extensible string object.
const void *tcxstrptr(const TCXSTR *xstr);
xstrspecifies the extensible string object.- The return value is the pointer of the region of the object.
- 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 function tcxstrsize is used in order to get the size of the region of an extensible string object.
int tcxstrsize(const TCXSTR *xstr);
xstrspecifies the extensible string object.- The return value is the size of the region of the object. ๐
The function tcxstrclear is used in order to clear an extensible string object.
void tcxstrclear(TCXSTR *xstr);
xstrspecifies the extensible string object.- The internal buffer of the object is cleared and the size is set zero. โจ
The function tcxstrprintf is used in order to perform formatted output into an extensible string object.
void tcxstrprintf(TCXSTR *xstr, const char *format, ...);
xstrspecifies the extensible string object.formatspecifies the printf-like format string. The conversion character%can be used with such flag characters ass,d,o,u,x,X,c,e,E,f,g,G,@,?,b, and%.@works as withsbut escapes meta characters of XML.?works as withsbut escapes meta characters of URL.bconverts an integer to the string as binary numbers. The other conversion character work as with each original.- The other arguments are used according to the format string. ๐
The function tcsprintf is used in order to allocate a formatted string on memory.
char *tcsprintf(const char *format, ...);
formatspecifies the printf-like format string. The conversion character%can be used with such flag characters ass,d,o,u,x,X,c,e,E,f,g,G,@,?,b, and%.@works as withsbut escapes meta characters of XML.?works as withsbut escapes meta characters of URL.bconverts an integer to the string as binary numbers. The other conversion character work as with each original.- The other arguments are used according to the format string.
- The return value is the pointer to the region of the result string.
- Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. ๐ฅ
๐ API OF ARRAY LIST ๐
The function tclistnew is used in order to create a list object.
TCLIST *tclistnew(void);
- The return value is the new list object. ๐
The function tclistnew2 is used in order to create a list object with expecting the number of elements.
The function tclistnew2 is your โจplanned aheadโจ list maker โ same list energy, but you tell it up front how much stuff you're gonna cram in there.
TCLIST *tclistnew2(int anum);
anumโ the number of elements you expect to store in the list. Manifesting capacity, bestie ๐- The return value is the new list object. Shiny, fresh, yours.
Then there's tclistnew3, which is the one you call when you already know your elements and you're just done waiting. It builds a list object with initial string elements, all in one go ๐
TCLIST *tclistnew3(const char *str, ...);
strโ the string of the first element.- The other arguments are other elements. They should be trailed by a
NULLargument โ yes, theNULLis mandatory, it's the little periodt at the end of your sentence, do not skip it ๐ - The return value is the new list object.
tclistdup is the copy-paste of the list world. Dupe it, bestie ๐ฆ
TCLIST *tclistdup(const TCLIST *list);
listโ the list object.- The return value is the new list object equivalent to the specified object. Same vibe, different memory.
tclistdel is the goodbye function. Clean up after yourself, it's giving responsible main character ๐ธ
void tclistdel(TCLIST *list);
listโ the list object.- > โ ๏ธ Note that the deleted object and its derivatives can not be used anymore. Like, cannot. That pointer is a ghost now, do not touch it ๐
tclistnum tells you how many elements are in the list. The headcount, the roll call, the "how many of us are in this group chat" ๐
int tclistnum(const TCLIST *list);
listโ the list object.- The return value is the number of elements of the list.
tclistval hands you the pointer to the region of an element. Not a copy, the actual region โ so don't go feral editing it without thinking, iykyk โจ
const void *tclistval(const TCLIST *list, int index, int *sp);
listโ the list object.indexโ the index of the element.spโ 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.
- 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. Free little bonus byte, slay ๐
- If
indexis equal to or more than the number of elements, the return value isNULL. Out of bounds means nothing for you, bestie ๐ญ
tclistval2 is tclistval but it's the string-forward version, no size variable required ๐
const char *tclistval2(const TCLIST *list, int index);
listโ the list object.indexโ the index of the element.- The return value is the string of the value.
- If
indexis equal to or more than the number of elements, the return value isNULL.
tclistpush adds an element at the end of the list. Tail-end girlie, always arriving last but making an entrance ๐
void tclistpush(TCLIST *list, const void *ptr, int size);
listโ the list object.ptrโ the pointer to the region of the new element.sizeโ the size of the region.
tclistpush2 is the string-flavoured push โ same end-of-list placement, but you just hand it a string and it handles the rest ๐
void tclistpush2(TCLIST *list, const char *str);
listโ the list object.strโ the string of the new element.
tclistpop yanks the element off the end of the list and gives it to you. Reverse push, it's giving poetic symmetry ๐
void *tclistpop(TCLIST *list, int *sp);
listโ the list object.spโ 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 removed element.
- 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
malloccall, it should be released with thefreecall when it is no longer in use. Free your pops, bestie, or you're leaking memory and that's not the aesthetic. ๐ญ - If the list is empty, the return value is
NULL.
tclistpop2 โ same pop, but it gives you a string and saves you a step ๐ง
char *tclistpop2(TCLIST *list);
listโ the list object.- The return value is the string of the removed element.
- > ๐จ Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. Same rules, no exceptions. - If the list is empty, the return value is
NULL.
tclistunshift adds an element at the top of the list. Front of the line, main character energy, no waiting ๐
void tclistunshift(TCLIST *list, const void *ptr, int size);
listโ the list object.ptrโ the pointer to the region of the new element.sizeโ the size of the region.
tclistunshift2 is the string version of that top-of-list insert ๐ธ
void tclistunshift2(TCLIST *list, const char *str);
listโ the list object.strโ the string of the new element.
tclistshift removes the element at the top of the list and hands it over. Unshift's chaotic twin ๐ฅ
void *tclistshift(TCLIST *list, int *sp);
listโ the list object.spโ 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 removed element.
- 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
malloccall, it should be released with thefreecall when it is no longer in use. You will be freeing this, bestie, I'm watching ๐ - If the list is empty, the return value is
NULL.
tclistshift2 โ string-flavoured shift, top of the list, no size variable, immaculate vibes โจ
char *tclistshift2(TCLIST *list);
listโ the list object.- The return value is the string of the removed element.
- > ๐จ Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. - If the list is empty, the return value is
NULL.
tclistinsert slides a new element in at the exact spot you name. Precision, periodt ๐ฏ
void tclistinsert(TCLIST *list, int index, const void *ptr, int size);
listโ the list object.indexโ the index of the new element.ptrโ the pointer to the region of the new element.sizeโ the size of the region.- If
indexis equal to or more than the number of elements, this function has no effect. Nothing happens. It simply does not engage ๐
tclistinsert2 โ same precise insertion, but with a string instead of a pointer-plus-size ๐
void tclistinsert2(TCLIST *list, int index, const char *str);
listโ the list object.indexโ the index of the new element.strโ the string of the new element.- If
indexis equal to or more than the number of elements, this function has no effect.
tclistremove takes out the element at the index you specify and gives it to you. Eviction notice, served ๐
void *tclistremove(TCLIST *list, int index, int *sp);
listโ the list object.indexโ the index of the element to be removed.spโ 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 removed element.
- 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
malloccall, it should be released with thefreecall when it is no longer in use. - If
indexis equal to or more than the number of elements, no element is removed and the return value isNULL.
tclistremove2 โ string edition of the index eviction, zero extra variables required ๐ฆ
char *tclistremove2(TCLIST *list, int index);
listโ the list object.indexโ the index of the element to be removed.- The return value is the string of the removed element.
- > ๐จ Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. - If
indexis equal to or more than the number of elements, no element is removed and the return value isNULL.
tclistover doesn't add, doesn't remove โ it overwrites whatever's sitting at that index. Glow-up via replacement, lowkey iconic ๐
void tclistover(TCLIST *list, int index, const void *ptr, int size);
listโ the list object.indexโ the index of the element to be overwritten.ptrโ the pointer to the region of the new content.sizeโ the size of the new content.- If
indexis equal to or more than the number of elements, this function has no effect.
tclistover2 is the string-flavoured overwrite. Swap the content, keep the slot ๐
void tclistover2(TCLIST *list, int index, const char *str);
listโ the list object.indexโ the index of the element to be overwritten.strโ the string of the new content.- If
indexis equal to or more than the number of elements, this function has no effect.
And finally (for now ๐), the function tclistsort is used in order to sort elements of a list object in lexical order.
tclistsort โ sorts a list object ๐ซ
void tclistsort(TCLIST *list);
listspecifies the list object.
tclistlsearch โ finds an element with a linear search ๐
int tclistlsearch(const TCLIST *list, const void *ptr, int size);
listspecifies the list object.ptrspecifies the pointer to the region of the key.sizespecifies the size of the region.- The return value is the index of a corresponding element, or
-1if there is no corresponding element. - If two or more elements correspond, the former returns โ so you get the first one, no cap.
tclistbsearch โ finds an element with a binary search โก
int tclistbsearch(const TCLIST *list, const void *ptr, int size);
listspecifies the list object. It should be sorted in lexical order.ptrspecifies the pointer to the region of the key.sizespecifies the size of the region.- The return value is the index of a corresponding element, or
-1if there is no corresponding element. - If two or more elements correspond, which one returns is not defined. So likeโฆ don't count on a specific one, bestie, it's giving chaos ๐
tclistclear โ wipes a list object clean ๐งผ
void tclistclear(TCLIST *list);
listspecifies the list object.- All elements are removed. Every single one. Gone. ๐
tclistdump โ serializes a list object into a byte array ๐ฆ
void *tclistdump(const TCLIST *list, int *sp);
listspecifies the list object.spspecifies 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
malloccall, it should be released with thefreecall when it is no longer in use.
๐ซถ bestie pls do not forget the free. That's a leak and the leak is not the vibe.
tclistload โ builds a list object back from a serialized byte array ๐ช
TCLIST *tclistload(const void *ptr, int size);
ptrspecifies the pointer to the region of serialized byte array.sizespecifies the size of the region.- The return value is a new list object.
- Because the object of the return value is created with the function
tclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use.
๐บ๏ธ API OF HASH MAP ๐บ๏ธ
okay this is the section where things get actually iconic โ key/value maps, aka the data structure of all time โจ
tcmapnew โ creates a map object ๐
TCMAP *tcmapnew(void);
- The return value is the new map object.
tcmapnew2 โ creates a map object, but you pick how many buckets ๐ชฃ
TCMAP *tcmapnew2(uint32_t bnum);
bnumspecifies the number of the buckets.- The return value is the new map object.
tcmapnew3 โ creates a map object that's already got string elements in it ๐ธ
TCMAP *tcmapnew3(const char *str, ...);
strspecifies the string of the first element.- The other arguments are other elements. They should be trailed by a
NULLargument. - The return value is the new map object.
- The key and the value of each record are situated one after the other.
๐ fr fr remember the trailing NULL โ that's how it knows you're done.
tcmapdup โ copies a map object ๐ฏ
TCMAP *tcmapdup(const TCMAP *map);
mapspecifies the map object.- The return value is the new map object equivalent to the specified object.
tcmapdel โ deletes a map object ๐๏ธ
void tcmapdel(TCMAP *map);
mapspecifies the map object.
๐ Note that the deleted object and its derivatives can not be used anymore. Not even a little. Not even to peek. It's over, periodt.
tcmapput โ stores a record into a map object ๐พ
void tcmapput(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies the size of the region of the value.- If a record with the same key exists in the map, it is overwritten.
tcmapput2 โ stores a string record into a map object โจ
void tcmapput2(TCMAP *map, const char *kstr, const char *vstr);
mapspecifies the map object.kstrspecifies the string of the key.vstrspecifies the string of the value.- If a record with the same key exists in the map, it is overwritten.
tcmapputkeep โ stores a new record, and refuses to clobber ๐
bool tcmapputkeep(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies the size of the region of the value.- If successful, the return value is
true, else, it isfalse. - If a record with the same key exists in the map, this function has no effect.
tcmapputkeep2 โ same energy, but with strings ๐
bool tcmapputkeep2(TCMAP *map, const char *kstr, const char *vstr);
mapspecifies the map object.kstrspecifies the string of the key.vstrspecifies the string of the value.- If successful, the return value is
true, else, it isfalse. - If a record with the same key exists in the map, this function has no effect.
tcmapputcat โ glues a value onto the end of an existing value ๐งฉ
void tcmapputcat(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies the size of the region of the value.- If there is no corresponding record, a new record is created.
tcmapputcat2 โ glues a string value onto the end of an existing value ๐ง
void tcmapputcat2(TCMAP *map, const char *kstr, const char *vstr);
mapspecifies the map object.kstrspecifies the string of the key.vstrspecifies the string of the value.- If there is no corresponding record, a new record is created.
tcmapout โ removes a record from a map object โ๏ธ
bool tcmapout(TCMAP *map, const void *kbuf, int ksiz);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.- If successful, the return value is
true.falseis returned when no record corresponds to the specified key.
tcmapout2 โ removes a string record from a map object ๐
bool tcmapout2(TCMAP *map, const char *kstr);
mapspecifies the map object.kstrspecifies the string of the key.- If successful, the return value is
true.falseis returned when no record corresponds to the specified key.
tcmapget โ retrieves a record from a map object ๐
const void *tcmapget(const TCMAP *map, const void *kbuf, int ksiz, int *sp);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.spspecifies 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.
NULLis 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.
๐ that last bit is the good stuff โ free null-termination, no extra work, we love a considerate API.
tcmapget2 โ retrieves a string record from a map object ๐
const char *tcmapget2(const TCMAP *map, const char *kstr);
mapspecifies the map object.kstrspecifies the string of the key.- If successful, the return value is the string of the value of the corresponding record.
NULLis returned when no record corresponds.
tcmapmove โ moves a record to the edge of a map object ๐
bool tcmapmove(TCMAP *map, const void *kbuf, int ksiz, bool head);
mapspecifies the map object.kbufspecifies the pointer to the region of a key.ksizspecifies the size of the region of the key.headspecifies the destination which is the head if it istrueor the tail if else.- If successful, the return value is
true.falseis returned when no record corresponds to the specified key.
tcmapmove2 โ moves a string record to the edge of a map object ๐ฆ
The function tcmapmove2 is used in order to move a string record to the edge of a map object.
The function tcmapmove2 is giving "rearrange the lineup" energy โ it moves a record to the head or the tail of the map object, bestie.
bool tcmapmove2(TCMAP *map, const char *kstr, bool head);
mapspecifies the map object.kstrspecifies the string of a key.headspecifies the destination which is the head if it is true or the tail if else.
If it worked, the return value is true. False comes back when no record corresponds to the specified key. ๐
The function tcmapiterinit is used in order to initialize the iterator of a map object.
void tcmapiterinit(TCMAP *map);
mapspecifies the map object.
The iterator is used in order to access the key of every record stored in the map object. โจ
The function tcmapiternext is used in order to get the next key of the iterator of a map object.
const void *tcmapiternext(TCMAP *map, int *sp);
mapspecifies the map object.spspecifies 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 the same as the stored order. ๐ฆ
The function tcmapiternext2 is used in order to get the next key string of the iterator of a map object.
const char *tcmapiternext2(TCMAP *map);
mapspecifies the map 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 the same as the stored order. ๐ธ
The function tcmaprnum is used in order to get the number of records stored in a map object.
uint64_t tcmaprnum(const TCMAP *map);
mapspecifies the map object.
The return value is the number of the records stored in the map object. Counting era, periodt. ๐ข
The function tcmapmsiz is used in order to get the total size of memory used in a map object.
uint64_t tcmapmsiz(const TCMAP *map);
mapspecifies the map object.
The return value is the total size of memory used in a map object. ๐พ
The function tcmapkeys is used in order to create a list object containing all keys in a map object.
TCLIST *tcmapkeys(const TCMAP *map);
mapspecifies the map object.
The return value is the new list object containing all keys in the map 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. Don't forget the cleanup, bestie, we do not leak in this house. ๐
The function tcmapvals is used in order to create a list object containing all values in a map object.
TCLIST *tcmapvals(const TCMAP *map);
mapspecifies the map object.
The return value is the new list object containing all values in the map 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. ๐ซถ
The function tcmapaddint is used in order to add an integer to a record in a map object.
int tcmapaddint(TCMAP *map, const void *kbuf, int ksiz, int num);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.numspecifies 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. It's giving math but make it map energy. โ
The function tcmapadddouble is used in order to add a real number to a record in a map object.
double tcmapadddouble(TCMAP *map, const void *kbuf, int ksiz,
double num);
mapspecifies the map object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.numspecifies 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. โจ
The function tcmapclear is used in order to clear a map object.
void tcmapclear(TCMAP *map);
mapspecifies the map object.
All records are removed. Total wipe, no survivors, iconic behavior. ๐
The function tcmapcutfront is used in order to remove front records of a map object.
void tcmapcutfront(TCMAP *map, int num);
mapspecifies the map object.numspecifies the number of records to be removed.
The function tcmapdump is used in order to serialize a map object into a byte array.
void *tcmapdump(const TCMAP *map, int *sp);
mapspecifies the map object.spspecifies 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. Free it. Free it. Free it. ๐ฅ
The function tcmapload is used in order to create a map object from a serialized byte array.
TCMAP *tcmapload(const void *ptr, int size);
ptrspecifies the pointer to the region of serialized byte array.sizespecifies the size of the region.
The return value is a new map object. Because the object of the return value is created with the function tcmapnew, it should be deleted with the function tcmapdel when it is no longer in use. ๐ง
๐ณ API OF ORDERED TREE ๐ณ
Okay so now we're in tree territory and it is so organized, everything stays in order, main character energy fr fr. ๐ฒ
The function tctreenew is used in order to create a tree object.
TCTREE *tctreenew(void);
The return value is the new tree object. Fresh out the box. ๐
The function tctreenew2 is used in order to create a tree object with specifying the custom comparison function.
TCTREE *tctreenew2(TCCMP cmp, void *cmpop);
cmpspecifies 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.cmpopspecifies an arbitrary pointer to be given as a parameter of the comparison function. If it is not needed,NULLcan 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 (default), tccmpdecimal, tccmpint32, and tccmpint64 are built-in. ๐ฆ
The function tctreedup is used in order to copy a tree object.
TCTREE *tctreedup(const TCTREE *tree);
treespecifies the tree object.
The return value is the new tree object equivalent to the specified object. Copy paste but make it legal. โจ
The function tctreedel is used in order to delete a tree object.
void tctreedel(TCTREE *tree);
treespecifies the tree object.
Note that the deleted object and its derivatives can not be used anymore. Not even a little bit. It's gone gone. ๐
The function tctreeput is used in order to store a record into a tree object.
void tctreeput(TCTREE *tree, const void *kbuf, int ksiz, const
void *vbuf, int vsiz);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies the size of the region of the value.
If a record with the same key exists in the tree, it is overwritten. No mercy, it just gets replaced. ๐
The function tctreeput2 is used in order to store a string record into a tree object.
void tctreeput2(TCTREE *tree, const char *kstr, const char
*vstr);
treespecifies the tree object.kstrspecifies the string of the key.vstrspecifies the string of the value.
If a record with the same key exists in the tree, it is overwritten. Same deal, same energy. ๐ธ
The function tctreeputkeep is used in order to store a new record into a tree object.
bool tctreeputkeep(TCTREE *tree, const void *kbuf, int ksiz,
const void *vbuf, int vsiz);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies 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. It's the respectful one, it does not touch what's already there. ๐
The function tctreeputkeep2 is used in order to store a new string record into a tree object.
bool tctreeputkeep2(TCTREE *tree, const char *kstr, const char *vstr);
treespecifies the tree object.kstrspecifies the string of the key.vstrspecifies the string of the value.- If successful, the return value is
true, else, it isfalse. - If a record with the same key exists in the tree, this function has no effect.
Okay so this one is the "bestie, if it's already there I'm literally not touching it" version โ no overwrite, no drama, just vibes. โจ
The function tctreeputcat is used in order to concatenate a value at the end of the value of the existing record in a tree object.
void tctreeputcat(TCTREE *tree, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.vbufspecifies the pointer to the region of the value.vsizspecifies the size of the region of the value.- If there is no corresponding record, a new record is created.
Concatenate = gluing the new value onto the end of the old one, like adding a lil sticker to the bottom of a note. ๐
The function tctreeputcat2 is used in order to concatenate a string value at the end of the value of the existing record in a tree object.
void tctreeputcat2(TCTREE *tree, const char *kstr, const char *vstr);
treespecifies the tree object.kstrspecifies the string of the key.vstrspecifies the string of the value.- If there is no corresponding record, a new record is created.
The function tctreeout is used in order to remove a record of a tree object.
bool tctreeout(TCTREE *tree, const void *kbuf, int ksiz);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.- If successful, the return value is
true.falseis returned when no record corresponds to the specified key.
The function tctreeout2 is used in order to remove a string record of a tree object.
bool tctreeout2(TCTREE *tree, const char *kstr);
treespecifies the tree object.kstrspecifies the string of the key.- If successful, the return value is
true.falseis returned when no record corresponds to the specified key.
It's giving eviction notice but make it binary โ true means it's gone, false means bestie there was never anything there. ๐
The function tctreeget is used in order to retrieve a record in a tree object.
const void *tctreeget(TCTREE *tree, const void *kbuf, int ksiz, int *sp);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.spspecifies 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.
NULLis 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.
Note the extra zero code at the end โ that's your free '\0', so you can literally just treat the returned value as a C string. No cap. ๐ซถ
The function tctreeget2 is used in order to retrieve a string record in a tree object.
const char *tctreeget2(TCTREE *tree, const char *kstr);
treespecifies the tree object.kstrspecifies the string of the key.- If successful, the return value is the string of the value of the corresponding record.
NULLis returned when no record corresponds.
The function tctreeiterinit is used in order to initialize the iterator of a tree object.
void tctreeiterinit(TCTREE *tree);
treespecifies the tree object.- The iterator is used in order to access the key of every record stored in the tree object.
Bestie you have to init before you next, that's the whole ritual, don't skip it. ๐ง
The function tctreeiternext is used in order to get the next key of the iterator of a tree object.
const void *tctreeiternext(TCTREE *tree, int *sp);
treespecifies the tree object.spspecifies 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.NULLis 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.
The order is ascending, periodt. You will never get a chaotic random shuffle here โ keys come out in order, every single time. ๐
The function tctreeiternext2 is used in order to get the next key string of the iterator of a tree object.
const char *tctreeiternext2(TCTREE *tree);
treespecifies the tree object.- If successful, the return value is the pointer to the region of the next key, else, it is
NULL.NULLis returned when no record can be fetched from the iterator. - The order of iteration is assured to be ascending of the keys.
The function tctreernum is used in order to get the number of records stored in a tree object.
uint64_t tctreernum(const TCTREE *tree);
treespecifies the tree object.- The return value is the number of the records stored in the tree object.
The function tctreemsiz is used in order to get the total size of memory used in a tree object.
uint64_t tctreemsiz(const TCTREE *tree);
treespecifies the tree object.- The return value is the total size of memory used in a tree object.
The function tctreekeys is used in order to create a list object containing all keys in a tree object.
TCLIST *tctreekeys(const TCTREE *tree);
treespecifies 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 functiontclistdelwhen it is no longer in use.
Cleanup check!! This list is yours now โ tclistdel it when you're done or it just sits there haunting your heap. ๐
The function tctreevals is used in order to create a list object containing all values in a tree object.
TCLIST *tctreevals(const TCTREE *tree);
treespecifies 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 functiontclistdelwhen it is no longer in use.
Same deal, bestie โ new list, new responsibility. Free it with tclistdel. ๐
The function tctreeaddint is used in order to add an integer to a record in a tree object.
int tctreeaddint(TCTREE *tree, const void *kbuf, int ksiz, int num);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.numspecifies 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.
It's a counter, it's a tally, it's math happening inside your tree. ๐ฅ
The function tctreeadddouble is used in order to add a real number to a record in a tree object.
double tctreeadddouble(TCTREE *tree, const void *kbuf, int ksiz, double num);
treespecifies the tree object.kbufspecifies the pointer to the region of the key.ksizspecifies the size of the region of the key.numspecifies 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.
The function tctreeclear is used in order to clear a tree object.
void tctreeclear(TCTREE *tree);
treespecifies the tree object.- All records are removed.
All of them. Every last one. It's giving factory reset. ๐ญ
The function tctreecutfringe is used in order to remove fringe records of a tree object.
void tctreecutfringe(TCTREE *tree, int num);
treespecifies the tree object.numspecifies the number of records to be removed.
The function tctreedump is used in order to serialize a tree object into a byte array.
void *tctreedump(const TCTREE *tree, int *sp);
treespecifies the tree object.spspecifies 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
malloccall, it should be released with thefreecall when it is no longer in use.
Important!!mallocgave it to you, sofreehas to take it back. That's the deal. Don't ghost your allocated memory. ๐
The function tctreeload is used in order to create a tree object from a serialized byte array.
TCTREE *tctreeload(const void *ptr, int size, TCCMP cmp, void *cmpop);
ptrspecifies the pointer to the region of serialized byte array.sizespecifies the size of the region.cmpspecifies the pointer to the custom comparison function.cmpopspecifies an arbitrary pointer to be given as a parameter of the comparison function. If it is not needed,NULLcan 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 functiontctreedelwhen it is no longer in use.
So tctreedump writes the tree out, and tctreeload brings it right back like nothing ever happened. Serialization glow-up. โจ And yeah โ tctreedel it when you're finished with it, always. ๐ซถ
๐ธ API OF ON-MEMORY HASH DATABASE ๐ธ
The function tcmdbnew is used in order to create an on-memory hash database object.
TCMDB *tcmdbnew(void);
- The return value is the new on-memory hash database object.
- The object can be shared by plural threads because of the internal mutex.
Thread-safe because of the internal mutex โ so multiple threads can all be besties with the same database object and nobody's stepping on anybody. ๐๐
tcmdbnew2โ makes you a fresh on-memory hash database object, but this time you get to say how many buckets it has. Queen behaviour, honestly.
TCMDB *tcmdbnew2(uint32_t bnum);
bnumโ the number of buckets. that's it, that's the whole vibe.- the return value is the new on-memory hash database object. โจ
- the object can be shared by plural threads because of the internal mutex โ so yes bestie, it's thread-safe, go off ๐ซถ
tcmdbdelโ yeets an on-memory hash database object into the void. it's gone, it's over, no cap.
void tcmdbdel(TCMDB *mdb);
mdbโ the on-memory hash database object. (say bye ๐ )
tcmdbputโ stores a record into an on-memory hash database object.
void tcmdbput(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
mdbโ the on-memory hash database object.kbufโ the pointer to the region of the key.ksizโ the size of the region of the key.vbufโ the pointer to the region of the value.vsizโ the size of the region of the value.- if a record with the same key already exists in the database, it is overwritten. not a merge, not a chat, just overwritten. periodt.
tcmdbput2โ same energy as above but for a string record. cute, effortless, string-coded.
void tcmdbput2(TCMDB *mdb, const char *kstr, const char *vstr);
mdbโ the on-memory hash database object.kstrโ the string of the key.vstrโ the string of the value.- if a record with the same key exists in the database, it is overwritten. same rule, same drama.
tcmdbputkeepโ stores a new record and refuses to touch anything that's already there. it's giving "respectfully, i'm not doing that" ๐
bool tcmdbputkeep(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
mdbโ the on-memory hash database object.kbufโ the pointer to the region of the key.ksizโ the size of the region of the key.vbufโ the pointer to the region of the value.vsizโ the size of the region of the value.- if successful, the return value is
true, else, it isfalse. - if a record with the same key exists in the database, this function has no effect. literally nothing happens. it just stands there, gorgeous, doing zero.
tcmdbputkeep2โ the string version of the above. stores a new string record, keeps its hands to itself.
bool tcmdbputkeep2(TCMDB *mdb, const char *kstr, const char *vstr);
mdbโ the on-memory hash database object.kstrโ the string of the key.vstrโ the string of the value.- if successful, the return value is
true, else, it isfalse. - if a record with the same key exists in the database, this function has no effect. we stay unbothered.
tcmdbputcatโ glues your value onto the end of whatever record is already there. it's the "โฆand another thing" of database functions ๐ฅ
void tcmdbputcat(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
mdbโ the on-memory hash database object.kbufโ the pointer to the region of the key.ksizโ the size of the region of the key.vbufโ the pointer to the region of the value.vsizโ the size of the region of the value.- if there is no corresponding record, a new record is created. so it never ghosts you, it just starts fresh. ๐ฆ
tcmdbputcat2โ the string edition. concatenates a string at the end of the existing record.
void tcmdbputcat2(TCMDB *mdb, const char *kstr, const char *vstr);
mdbโ the on-memory hash database object.kstrโ the string of the key.vstrโ the string of the value.- if there is no corresponding record, a new record is created. again, no abandonment here.
tcmdboutโ removes a record from an on-memory hash database object. the block button, essentially.
bool tcmdbout(TCMDB *mdb, const void *kbuf, int ksiz);
mdbโ the on-memory hash database object.kbufโ the pointer to the region of the key.ksizโ the size of the region of the key.- if successful, the return value is
true.falseis returned when no record corresponds to the specified key โ i.e. there was nothing there to remove, awkward ๐
tcmdbout2โ removes a string record from an on-memory hash database object.
bool tcmdbout2(TCMDB *mdb, const char *kstr);
mdbโ the on-memory hash database object.kstrโ the string of the key.- if successful, the return value is
true.falseis returned when no record corresponds to the specified key. same deal, same energy.
tcmdbgetโ retrieves a record. the main character function, honestly ๐
void *tcmdbget(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);
mdbโ the on-memory hash database object.kbufโ the pointer to the region of the key.ksizโ the size of the region of the key.spโ 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.
NULLis 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. cute lil bonus.
- because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. do not forget this one bestie, that's a leak ๐ญ
tcmdbget2โ retrieves a string record. same function, string-coded entrance.
char *tcmdbget2(TCMDB *mdb, const char *kstr);
mdbโ the on-memory hash database object.kstrโ the string of the key.- if successful, the return value is the string of the value of the corresponding record.
NULLis returned when no record corresponds. - because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. again.freeit. i'm not asking twice, i'm asking once but louder. ๐
tcmdbvsizโ tells you how big the value of a record is, without actually handing you the value. it's giving "i'm not showing you the text but i'll tell you how long it is" ๐
int tcmdbvsiz(TCMDB *mdb, const void *kbuf, int ksiz);
mdbโ the on-memory hash database object.kbufโ the pointer to the region of the key.ksizโ 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.
tcmdbvsiz2โ the string-record version of the size check.
int tcmdbvsiz2(TCMDB *mdb, const char *kstr);
mdbโ the on-memory hash database object.kstrโ the string of the key.- if successful, the return value is the size of the value of the corresponding record, else, it is
-1.
tcmdbiterinitโ sets up the iterator for an on-memory hash database object. think of it as hitting "start" on the slideshow of every key in there.
void tcmdbiterinit(TCMDB *mdb);
mdbโ the on-memory hash database object.- the iterator is used in order to access the key of every record stored in the on-memory hash database. every single one. no skipping. ๐
tcmdbiternextโ grabs the next key off the iterator. one at a time, bestie, we're not greedy.
void *tcmdbiternext(TCMDB *mdb, int *sp);
mdbโ the on-memory hash database object.spโ 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.NULLis returned when no record can be fetched from the iterator. soNULL= we're done here, thank u next. โจ - 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
malloccall, it should be released with thefreecall when it is no longer in use. yes. again.free. every time. ๐ง - the order of iteration is assured to be the same as the stored order. so it's consistent, it's reliable, it's lowkey iconic.
tcmdbiternext2โ same as above but it hands you the next key as a string. the easy-mode entrance.
char *tcmdbiternext2(TCMDB *mdb);
mdbโ 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.NULLis returned when no record can be fetched from the iterator. - because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. (you know the drill by now ๐) - the order of iteration is assured to be the same as the stored order.
tcmdbfwmkeysโ gets you the forward matching keys in an on-memory hash database object. prefix squad, rise ๐
TCLIST *tcmdbfwmkeys(TCMDB *mdb, const void *pbuf, int psiz, int max);
TCLIST *tcmdbfwmkeys(TCMDB *mdb, const void *pbuf, int psiz, int max);mdbโ the on-memory hash database object, bestie.pbufโ pointer to the region of the prefix.psizโ size of the region of the prefix.maxโ the maximum number of keys to be fetched. If it's negative, no limit is specified, go wild.- What you get back is a list object of the corresponding keys. This function does never fail. Even if no key corresponds, you get an empty list, no drama.
- Because the object of the return value is created with the function
tclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use. Clean up after yourself, it's giving basic hygiene ๐ - > Heads up: this function may be very slow because every key in the database is scanned. Like, scanning every single key. It's giving "going through your entire camera roll for one pic" energy ๐ญ
The function tcmdbfwmkeys2 is used in order to get forward matching string keys in an on-memory hash database object.
TCLIST *tcmdbfwmkeys2(TCMDB *mdb, const char *pstr, int max);mdbโ the on-memory hash database object.pstrโ the string of the prefix.maxโ 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. It returns an empty list even if no key corresponds.
- Because the object of the return value is created with the function
tclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use. - > And again: this function may be very slow because every key in the database is scanned. Same vibe, same warning, no cap ๐ข
The function tcmdbrnum is used in order to get the number of records stored in an on-memory hash database object.
uint64_t tcmdbrnum(TCMDB *mdb);mdbโ the on-memory hash database object.- The return value is the number of the records stored in the database. That's it, that's the whole function ๐ซถ
The function tcmdbmsiz is used in order to get the total size of memory used in an on-memory hash database object.
uint64_t tcmdbmsiz(TCMDB *mdb);mdbโ the on-memory hash database object.- The return value is the total size of memory used in the database. The receipts on how much RAM this thing is eating ๐ธ
The function tcmdbaddint is used in order to add an integer to a record in an on-memory hash database object.
int tcmdbaddint(TCMDB *mdb, const void *kbuf, int ksiz, int num);mdbโ the on-memory hash database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.numโ 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. Math o'clock โจ
The function tcmdbadddouble is used in order to add a real number to a record in an on-memory hash database object.
double tcmdbadddouble(TCMDB *mdb, const void *kbuf, int ksiz, double num);mdbโ the on-memory hash database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.numโ 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. Floating point girlies, this one's for you ๐ธ
The function tcmdbvanish is used in order to clear an on-memory hash database object.
void tcmdbvanish(TCMDB *mdb);mdbโ the on-memory hash database object.- All records are removed. Poof. Gone. Nothing left but vibes ๐
The function tcmdbcutfront is used in order to remove front records of an on-memory hash database object.
void tcmdbcutfront(TCMDB *mdb, int num);mdbโ the on-memory hash database object.numโ the number of records to be removed.
๐ณ API OF ON-MEMORY TREE DATABASE ๐ณ
The function tcndbnew is used in order to create an on-memory tree database object.
TCNDB *tcndbnew(void);- The return value is the new on-memory tree database object.
- The object can be shared by plural threads because of the internal mutex. Thread-safe and thriving, we love to see it ๐ฅ
The function tcndbnew2 is used in order to create an on-memory tree database object with specifying the custom comparison function.
TCNDB *tcndbnew2(TCCMP cmp, void *cmpop);cmpโ pointer to the custom comparison function.cmpopโ an arbitrary pointer to be given as a parameter of the comparison function. If it is not needed,NULLcan be specified.- The return value is the new on-memory tree database object.
- The default comparison function compares keys of two records by lexical order. The functions
tccmplexical(default),tccmpdecimal,tccmpint32, andtccmpint64are built-in. Pick your fighter ๐ - The object can be shared by plural threads because of the internal mutex.
The function tcndbdel is used in order to delete an on-memory tree database object.
void tcndbdel(TCNDB *ndb);ndbโ the on-memory tree database object.
The function tcndbput is used in order to store a record into an on-memory tree database object.
void tcndbput(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.vbufโ pointer to the region of the value.vsizโ size of the region of the value.- If a record with the same key exists in the database, it is overwritten. Sorry not sorry, it's replaceable ๐
The function tcndbput2 is used in order to store a string record into an on-memory tree database object.
void tcndbput2(TCNDB *ndb, const char *kstr, const char *vstr);ndbโ the on-memory tree database object.kstrโ the string of the key.vstrโ the string of the value.- If a record with the same key exists in the database, it is overwritten.
The function tcndbputkeep is used in order to store a new record into an on-memory tree database object.
bool tcndbputkeep(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.vbufโ pointer to the region of the value.vsizโ 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. It's giving "I'm not touching that, that's taken" energy ๐
The function tcndbputkeep2 is used in order to store a new string record into an on-memory tree database object.
bool tcndbputkeep2(TCNDB *ndb, const char *kstr, const char *vstr);ndbโ the on-memory tree database object.kstrโ the string of the key.vstrโ 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.
The function tcndbputcat is used in order to concatenate a value at the end of the existing record in an on-memory tree database.
void tcndbputcat(TCNDB *ndb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.vbufโ pointer to the region of the value.vsizโ size of the region of the value.- If there is no corresponding record, a new record is created. So either way you're getting a record, bestie ๐ฆ
The function tcndbputcat2 is used in order to concatenate a string at the end of the existing record in an on-memory tree database.
void tcndbputcat2(TCNDB *ndb, const char *kstr, const char *vstr);ndbโ the on-memory tree database object.kstrโ the string of the key.vstrโ the string of the value.- If there is no corresponding record, a new record is created.
The function tcndbout is used in order to remove a record of an on-memory tree database object.
bool tcndbout(TCNDB *ndb, const void *kbuf, int ksiz);ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ 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. Blocked and deleted โจ
The function tcndbout2 is used in order to remove a string record of an on-memory tree database object.
bool tcndbout2(TCNDB *ndb, const char *kstr);ndbโ the on-memory tree database object.kstrโ the string of the key.- If successful, the return value is true. False is returned when no record corresponds to the specified key.
The function tcndbget is used in order to retrieve a record in an on-memory tree database object.
tcndbget
void *tcndbget(TCNDB *ndb, const void *kbuf, int ksiz, int *sp);
ndbโ the on-memory tree database object, bestie. the one we're vibing with.kbufโ pointer to the region of the key.ksizโ size of the region of the key.spโ pointer to the variable where the size of the region of the return value gets assigned.
If it hits, the return value is a pointer to the region of the value of the record that matches. When nothing matches, you get NULL back. ๐
And okay, cute detail: an extra zero code gets appended at the end of the return value's region, so you can literally treat it as a character string. โจ But because that region was allocated with the malloc call, you have to release it with the free call once you're done with it. no cap, don't leak.
tcndbget2
So tcndbget2 is the one you call when you want to retrieve a string record in an on-memory tree database object. ๐
char *tcndbget2(TCNDB *ndb, const char *kstr);
ndbโ the on-memory tree database object.kstrโ the string of the key.
If it works out, the return value is the string of the value of the corresponding record. No record? NULL. simple as that.
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. ๐
tcndbvsiz
tcndbvsiz is your girl for getting the size of the value of a record in an on-memory tree database object.
int tcndbvsiz(TCNDB *ndb, const void *kbuf, int ksiz);
ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.
If it succeeds, the return value is the size of the value of the corresponding record. Otherwise? -1. ๐ญ
tcndbvsiz2
And tcndbvsiz2 does that same thing but for the value of a string record in an on-memory tree database object.
int tcndbvsiz2(TCNDB *ndb, const char *kstr);
ndbโ the on-memory tree database object.kstrโ the string of the key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1. ๐ฆ
tcndbiterinit
tcndbiterinit initializes the iterator of an on-memory tree database object. ๐ง
void tcndbiterinit(TCNDB *ndb);
ndbโ the on-memory tree database object.
The iterator is used in order to access the key of every record stored in the on-memory database. like, all of them. one by one. iconic behavior honestly.
tcndbiternext
tcndbiternext grabs you the next key of the iterator of an on-memory tree database object. โจ
void *tcndbiternext(TCNDB *ndb, int *sp);
ndbโ the on-memory tree database object.spโ pointer to the variable where the size of the region of the return value gets assigned.
If successful, the return value is the pointer to the region of the next key, else, it is NULL. And NULL shows up specifically when no record can be fetched from the iterator, so don't panic โ that's just the end. ๐
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. ๐ฅ
tcndbiternext2
tcndbiternext2 is the string-flavored twin โ it gets the next key string of the iterator of an on-memory tree database object.
char *tcndbiternext2(TCNDB *ndb);
ndbโ the on-memory tree 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. ๐
tcndbfwmkeys
tcndbfwmkeys gets forward matching keys in an on-memory tree database object. ๐
TCLIST *tcndbfwmkeys(TCNDB *ndb, const void *pbuf, int psiz, int max);
ndbโ the on-memory tree database object.pbufโ pointer to the region of the prefix.psizโ size of the region of the prefix.maxโ 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. And listen โ this function does never fail. it returns an empty list even if no key corresponds. so chill. ๐
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.
tcndbfwmkeys2
tcndbfwmkeys2 is the string version โ forward matching string keys in an on-memory tree database object.
TCLIST *tcndbfwmkeys2(TCNDB *ndb, const char *pstr, int max);
ndbโ the on-memory tree database object.pstrโ the string of the prefix.maxโ 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. It returns an empty list even if no key corresponds. ๐
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.
tcndbrnum
tcndbrnum counts the records stored in an on-memory tree database object. ๐
uint64_t tcndbrnum(TCNDB *ndb);
ndbโ the on-memory tree database object.
The return value is the number of the records stored in the database.
tcndbmsiz
tcndbmsiz tells you the total size of memory used in an on-memory tree database object. ๐ธ
uint64_t tcndbmsiz(TCNDB *ndb);
ndbโ the on-memory tree database object.
The return value is the total size of memory used in the database.
tcndbaddint
tcndbaddint adds an integer to a record in an on-memory tree database object. ๐
int tcndbaddint(TCNDB *ndb, const void *kbuf, int ksiz, int num);
ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.numโ 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. so it just... makes one. slay. โจ
tcndbadddouble
tcndbadddouble is the same energy but for adding a real number to a record in an on-memory tree database object.
double tcndbadddouble(TCNDB *ndb, const void *kbuf, int ksiz, double num);
ndbโ the on-memory tree database object.kbufโ pointer to the region of the key.ksizโ size of the region of the key.numโ 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. ๐ซ
tcndbvanish
tcndbvanish clears an on-memory tree database object. ๐
void tcndbvanish(TCNDB *ndb);
ndbโ the on-memory tree database object.
All records are removed. all of them. gone. periodt.
tcndbcutfringe
tcndbcutfringe removes fringe records of an on-memory tree database object. ๐ซถ
void tcndbcutfringe(TCNDB *ndb, int num);
ndbโ the on-memory tree database object.numโ the number of records to be removed.
โจ API OF MEMORY POOL โจ
okay bestie, it's memory pool o'clock ๐ this is the part where you make a whole cleanup crew so you don't have to manually free every little thing. It's giving organized. No cap.
tcmpoolnew โ new pool, who dis ๐ธ
This function is used in order to create a memory pool object. Slay, now you have a pool. โจ
TCMPOOL *tcmpoolnew(void);
- The return value is the new memory pool object.
tcmpooldel โ bye bye pool ๐
This function is used in order to delete a memory pool object. It's literally the opposite of new. ๐
void tcmpooldel(TCMPOOL *mpool);
mpoolspecifies the memory pool object.
Note that the deleted object and its derivatives can not be used anymore. Like, do not touch. Periodt.
tcmpoolpush โ relegate an arbitrary object to the pool ๐ซถ
This function is used in order to relegate an arbitrary object to a memory pool object. It's basically adopting an object into the pool family. ๐กโจ
void *tcmpoolpush(TCMPOOL *mpool, void *ptr, void (*del)(void *));
mpoolspecifies the memory pool object.ptrspecifies the pointer to the object to be relegated. If it isNULL, this function has no effect.delspecifies the pointer to the function to delete the object.- The return value is the pointer to the given object.
- This function assures that the specified object is deleted when the memory pool object is deleted.
tcmpoolpushptr โ relegate an allocated region ๐ง
This function is used in order to relegate an allocated region to a memory pool object. Lowkey iconic.
void *tcmpoolpushptr(TCMPOOL *mpool, void *ptr);
mpoolspecifies the memory pool object.ptrspecifies the pointer to the region to be relegated. If it isNULL, this function has no effect.- The return value is the pointer to the given object.
- This function assures that the specified region is released when the memory pool object is deleted.
tcmpoolpushxstr โ relegate an extensible string object ๐
This function is used in order to relegate an extensible string object to a memory pool object. String bestie, you're in the pool now. ๐ซถ
TCXSTR *tcmpoolpushxstr(TCMPOOL *mpool, TCXSTR *xstr);
mpoolspecifies the memory pool object.xstrspecifies the extensible string object. If it isNULL, this function has no effect.- The return value is the pointer to the given object.
- This function assures that the specified object is deleted when the memory pool object is deleted.
tcmpoolpushlist โ relegate a list object ๐ฆ
This function is used in order to relegate a list object to a memory pool object. List, you're safe now. โจ
TCLIST *tcmpoolpushlist(TCMPOOL *mpool, TCLIST *list);
mpoolspecifies the memory pool object.listspecifies the list object. If it isNULL, this function has no effect.- The return value is the pointer to the given object.
- This function assures that the specified object is deleted when the memory pool object is deleted.
tcmpoolpushmap โ relegate a map object ๐บ๏ธ
This function is used in order to relegate a map object to a memory pool object. Map it out, bestie. ๐
TCMAP *tcmpoolpushmap(TCMPOOL *mpool, TCMAP *map);
mpoolspecifies the memory pool object.mapspecifies the map object. If it isNULL, this function has no effect.- The return value is the pointer to the given object.
- This function assures that the specified object is deleted when the memory pool object is deleted.
tcmpoolpushtree โ relegate a tree object ๐ณ
This function is used in order to relegate a tree object to a memory pool object. Tree, you're rooted in the pool now. ๐ฒ
TCTREE *tcmpoolpushtree(TCMPOOL *mpool, TCTREE *tree);
mpoolspecifies the memory pool object.treespecifies the tree object. If it isNULL, this function has no effect.- The return value is the pointer to the given object.
- This function assures that the specified object is deleted when the memory pool object is deleted.
tcmpoolmalloc โ allocate a region relegated to the pool ๐
This function is used in order to allocate a region relegated to a memory pool object. Get that memory, bestie. โจ
void *tcmpoolmalloc(TCMPOOL *mpool, size_t size);
mpoolspecifies the memory pool object.- The return value is the pointer to the allocated region under the memory pool.
tcmpoolxstrnew โ new extensible string, but make it pool ๐
This function is used in order to create an extensible string object relegated to a memory pool object.
TCXSTR *tcmpoolxstrnew(TCMPOOL *mpool);
- The return value is the new extensible string object under the memory pool.
tcmpoollistnew โ new list, pool edition ๐
This function is used in order to create a list object relegated to a memory pool object.
TCLIST *tcmpoollistnew(TCMPOOL *mpool);
- The return value is the new list object under the memory pool.
tcmpoolmapnew โ new map, pool edition ๐บ๏ธ
This function is used in order to create a map object relegated to a memory pool object.
TCMAP *tcmpoolmapnew(TCMPOOL *mpool);
- The return value is the new map object under the memory pool.
tcmpooltreenew โ new tree, pool edition ๐ฒ
This function is used in order to create a tree object relegated to a memory pool object.
TCTREE *tcmpooltreenew(TCMPOOL *mpool);
- The return value is the new tree object under the memory pool.
tcmpoolpop โ pop the most recent cleanup handler ๐ซง
This function is used in order to remove the most recently installed cleanup handler of a memory pool object. Pop off, literally. ๐
void tcmpoolpop(TCMPOOL *mpool, bool exe);
mpoolspecifies the memory pool object.exespecifies whether to execute the destructor of the removed handler.
tcmpoolclear โ clear all the cleanup handlers ๐งผ
This function is used in order to remove all cleanup handler of a memory pool object. Clean slate energy. โจ
void tcmpoolclear(TCMPOOL *mpool, bool exe);
mpoolspecifies the memory pool object.exespecifies whether to execute the destructors of the removed handlers.
tcmpoolglobal โ the global memory pool, the main character ๐
This function is used in order to get the global memory pool object. Main character energy, fr fr.
TCMPOOL *tcmpoolglobal(void);
- The return value is the global memory pool object.
- The global memory pool object is a singleton and assured to be deleted when the process is terminating normally.
๐ API OF MISCELLANEOUS UTILITIES ๐
Now we're in the miscellaneous section, bestie. These are the little helper functions that don't fit anywhere else, and honestly? They ate. โจ
tclmax โ bigger of two integers ๐ผ
This function is used in order to get the larger value of two integers. Bigger is better, lowkey.
long tclmax(long a, long b);
aspecifies an integer.bspecifies the other integer.- The return value is the larger value of the two.
tclmin โ lesser of two integers ๐ฝ
This function is used in order to get the lesser value of two integers. Smaller, but still iconic.
long tclmin(long a, long b);
aspecifies an integer.bspecifies the other integer.- The return value is the lesser value of the two.
tclrand โ random unsigned long, uniform distribution ๐ฒ
This function is used in order to get a random number as long integer based on uniform distribution. Randomness? Obsessed.
unsigned long tclrand(void);
- The return value is the random number between 0 and
ULONG_MAX. - This function uses the random number source device and generates a real random number if possible.
tcdrand โ random double, uniform distribution ๐ฒ
This function is used in order to get a random number as double decimal based on uniform distribution. Double the drama, double the random. ๐
double tcdrand(void);
- The return value is the random number equal to or greater than 0, and less than 1.0.
- This function uses the random number source device and generates a real random number if possible.
tcdrandnd โ random double, normal distribution ๐
This function is used in order to get a random number as double decimal based on normal distribution. Bell curve realness. ๐
double tcdrandnd(double avg, double sd);
avgspecifies the average.sdspecifies the standard deviation.- The return value is the random number.
- This function uses the random number source device and generates a real random number if possible.
tcstricmp โ case-insensitive string compare ๐ซถ
This function is used in order to compare two strings with case insensitive evaluation. No cap, case doesn't matter here.
int tcstricmp(const char *astr, const char *bstr);
astrspecifies a string.bstrspecifies of the other string.- The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent.
tcstrfwm โ does it begin with key? ๐
This function is used in order to check whether a string begins with a key. Forward matching, bestie.
bool tcstrfwm(const char *str, const char *key);
strspecifies the target string.keyspecifies the forward matching key string.- The return value is true if the target string begins with the key, else, it is false.
tcstrifwm โ begin with key, case-insensitive? ๐
This function is used in order to check whether a string begins with a key with case insensitive evaluation. Same vibe, no case drama.
bool tcstrifwm(const char *str, const char *key);
strspecifies the target string.keyspecifies the forward matching key string.- The return value is true if the target string begins with the key, else, it is false.
tcstrbwm โ does it end with key? ๐
This function is used in order to check whether a string ends with a key. Backward matching, periodt.
bool tcstrbwm(const char *str, const char *key);
strspecifies the target string.keyspecifies the backward matching key string.- The return value is true if the target string ends with the key, else, it is false.
tcstribwm โ end with key, case-insensitive? ๐
This function is used in order to check whether a string ends with a key with case insensitive evaluation. No case, all vibe.
bool tcstribwm(const char *str, const char *key);
strspecifies the target string.keyspecifies the backward matching key string.- The return value is true if the target string ends with the key, else, it is false.
tcstrdist โ edit distance, byte by byte ๐
This function is used in order to calculate the edit distance of two strings. Levenshtein distance, but make it bytes.
int tcstrdist(const char *astr, const char *bstr);
astrspecifies a string.bstrspecifies of the other string.- The return value is the edit distance which is known as the Levenshtein distance. The cost is calculated by byte.
tcstrdistutf โ edit distance, Unicode character by character ๐
This function is used in order to calculate the edit distance of two UTF-8 strings. Levenshtein distance, Unicode edition. โจ
int tcstrdistutf(const char *astr, const char *bstr);
astrspecifies a string.bstrspecifies of the other string.- The return value is the edit distance which is known as the Levenshtein distance. The cost is calculated by Unicode character.
char *tcstrtoupper(char *str)โ bestie, this one uppercases every letter in your string, all caps, main character energy ๐strโ the string to be converted.- The return value is the string itself. Yep, it hands you back the very same string, mutated in place. In-place glow-up, periodt.
char *tcstrtolower(char *str)โ the lowercase sibling, takes your letters down to lower case ๐ธstrโ the string to be converted.- The return value is the string itself. Again, same string, changed right where it lives.
char *tcstrtrim(char *str)โ trims the space characters off the head and the tail of a string โ๏ธ (not the middle, bestie, the middle stays)strโ the string to be converted.- The return value is the string itself.
char *tcstrsqzspc(char *str)โ squeezes the space characters down and trims it, so all that extra whitespace gets its vibe check ๐strโ the string to be converted.- The return value is the string itself.
char *tcstrsubchr(char *str, const char *rstr, const char *sstr)โ swaps characters in a string, like a little find-and-replace but character-wise ๐strโ the string to be converted.rstrโ the string containing the characters to be replaced.sstrโ the string containing the characters to be substituted.- Heads up: if the substitute string is shorter than the replacement string, the corresponding characters are removed. Gone. Poof. ๐
- The return value is the string itself.
int tcstrcntutf(const char *str)โ counts how many characters live in a UTF-8 string, and yes it counts characters, not bytes, because UTF-8 said "one glyph, many bytes" ๐ฆstrโ the string of UTF-8.- The return value is the number of characters in the string.
char *tcstrcututf(char *str, int num)โ cuts a UTF-8 string at a given number of characters, safely on a character boundary ๐strโ the string of UTF-8.numโ the number of characters to be kept.- The return value is the string itself.
void tcstrutftoucs(const char *str, uint16_t *ary, int *np)โ converts a UTF-8 string into a UCS-2 array โจstrโ the UTF-8 string.aryโ the pointer to the region into which the result UCS-2 codes are written. The size of the buffer should be sufficient.npโ the pointer to a variable into which the number of elements of the result array is assigned.
int tcstrucstoutf(const uint16_t *ary, int num, char *str)โ the reverse glow-up: UCS-2 array back into a UTF-8 string ๐aryโ the array of UCS-2 codes.numโ the number of the array.strโ the pointer to the region into which the result UTF-8 string is written. The size of the buffer should be sufficient.- The return value is the length of the result string.
TCLIST *tcstrsplit(const char *str, const char *delims)โ splits a string up and hands you a whole list object out of it, like a group chat breaking into side conversations ๐ฌstrโ the source string.delimsโ a string containing delimiting characters.- The return value is a list object of the split elements.
- Note: if two delimiters are successive, it is assumed that an empty element is between the two.
- Because the object of the return value is created with the function
tclistnew, it should be deleted with the functiontclistdelwhen it is no longer in use. Clean up after yourself, queen.
char *tcstrjoin(const TCLIST *list, char delim)โ the other direction: glues all the elements of a list object into one string ๐ซถlistโ a list object.delimโ a delimiting character.- The return value is the result string.
- Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use.
int64_t tcatoi(const char *str)โ string โก๏ธ integer, no cap ๐งฎstrโ the string.- The return value is the integer. If the string does not contain numeric expression,
0is returned. - This function is equivalent to
atollexcept that it does not depend on the locale. Locale? Never heard of her.
int64_t tcatoix(const char *str)โ string โก๏ธ integer, but with a metric prefix allowed, so you can vibe in K, M, G and beyond ๐ฅstrโ the string, which can be trailed by a binary metric prefix."K","M","G","T","P", and"E"are supported. They are case-insensitive.- The return value is the integer. If the string does not contain numeric expression,
0is returned. If the integer overflows the domain,INT64_MAXorINT64_MINis returned according to the sign. She caps out, bestie โ she does not just keep going.
double tcatof(const char *str)โ string โก๏ธ real number ๐strโ the string.- The return value is the real number. If the string does not contain numeric expression,
0.0is returned. - This function is equivalent to
atofexcept that it does not depend on the locale.
bool tcregexmatch(const char *str, const char *regex)โ checks whether a string matches a regular expression ๐strโ the target string.regexโ the regular expression string. If it begins with*, the trailing substring is used as a case-insensitive regular expression.- The return value is
trueif matching is success, else, it isfalse.
char *tcregexreplace(const char *str, const char *regex, const char *alt)โ replaces every substring that matches a regular expression โจstrโ the target string.regexโ the regular expression string for substrings. If it begins with*, the trailing substring is used as a case-insensitive regular expression.altโ the alternative string with which each substrings is replaced. Each&in the string is replaced with the matched substring. Eachยดin the string escapes the following character. Special escapes"1"through"9"referring to the corresponding matching sub-expressions in the regular expression string are supported.- The return value is a new converted string. Even if the regular expression is invalid, a copy of the original string is returned.
- Because the region of the return value is allocated with the
malloccall, it should be released with thefreecall when it is no longer in use. Free her when you're done, okay??
void tcmd5hash(const void *ptr, int size, char *buf)โ grabs the MD5 hash value of a serial object ๐ptrโ the pointer to the region.sizeโ the size of the region.bufโ the pointer to the region into which the result string is written. The size of the buffer should be equal to or more than 48 bytes.
void tcarccipher(const void *ptr, int size, const void *kbuf, int ksiz, void *obuf)โ ciphers or deciphers a serial object with the Arcfour stream cipher, because it's the same operation both ways, iykyk ๐งptrโ the pointer to the region.sizeโ the size of the region.kbufโ the pointer to the region of the cipher key.ksizโ the size of the region of the cipher key.obufโ the pointer to the region into which the result data is written. The size of the buffer should be equal to or more than the input region.
double tctime(void)โ gives you the time of day in seconds โฐ- The return value is the time of day in seconds. The accuracy is in microseconds. Microsecond precision? She's precise and she knows it.
void tccalendar(int64_t t, int jl, int *yearp, int *monp, int *dayp, int *hourp, int *minp, int *secp)โ turns a time into the Gregorian calendar breakdown ๐๏ธtโ the source time in seconds from the epoch. If it isINT64_MAX, the current time is specified.jlโ the jet lag of a location in seconds. If it isINT_MAX, the local jet lag is specified.yearpโ the pointer to a variable to which the year is assigned. If it isNULL, it is not used.monpโ the pointer to a variable to which the month is assigned. If it isNULL, it is not used.1means January and12means December.daypโ the pointer to a variable to which the day of the month is assigned. If it isNULL, it is not used.hourpโ the pointer to a variable to which the hours is assigned. If it isNULL, it is not used.minpโ the pointer to a variable to which the minutes is assigned. If it isNULL, it is not used.secpโ the pointer to a variable to which the seconds is assigned. If it isNULL, it is not used.- Every single one of those pointers is optional, so pass
NULLfor whatever you don't care about. She's flexible like that. ๐
tcdatestrwwwโ formats a date as a string in W3CDTF โญ
okay so we're picking up right in the middle of the date/time glow-up ๐ โ tcdatestrwww is the W3CDTF one, and here's its exact signature:
void tcdatestrwww(int64_t t, int jl, char *buf);
tโ specifies the source time in seconds from the epoch. If it isINT64_MAX, the current time is specified.jlโ specifies the jet lag of a location in seconds. If it isINT_MAX, the local jet lag is specified.bufโ specifies the pointer to the region into which the result string is written. The size of the buffer should be equal to or more than 48 bytes.
W3CDTF represents a date as "YYYY-MM-DDThh:mm:ddTZD". slay โจ
The function tcdatestrhttp is used in order to format a date as a string in RFC 1123 format. obsessed with her ๐
void tcdatestrhttp(int64_t t, int jl, char *buf);
tโ specifies the source time in seconds from the epoch. If it isINT64_MAX, the current time is specified.jlโ specifies the jet lag of a location in seconds. If it isINT_MAX, the local jet lag is specified.bufโ specifies the pointer to the region into which the result string is written. The size of the buffer should be equal to or more than 48 bytes.
RFC 1123 format represents a date as "Wdy, DD-Mon-YYYY hh:mm:dd TZD". iykyk ๐
The function tcstrmktime is used in order to get the time value of a date string. main character energy fr fr ๐ฆ
int64_t tcstrmktime(const char *str);
strโ specifies the date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). Decimal can be trailed by"s"for in seconds,"m"for in minutes,"h"for in hours, and"d"for in days.
The return value is the time value of the date or INT64_MIN if the format is invalid. do not ignore that sentinel bestie ๐ญ
The function tcjetlag is used in order to get the jet lag of the local time. timezone tea ๐ธ
int tcjetlag(void);
The return value is the jet lag of the local time in seconds. no cap โญ
The function tcdayofweek is used in order to get the day of week of a date. calendar bestie ๐
int tcdayofweek(int year, int mon, int day);
yearโ specifies the year of a date.monโ specifies the month of the date.dayโ specifies the day of the date.
The return value is the day of week of the date. 0 means Sunday and 6 means Saturday. weekend vibes only ๐
โจ API OF FILESYSTEM UTILITIES โจ
The function tcrealpath is used in order to get the canonicalized absolute path of a file. path glow-up ๐
char *tcrealpath(const char *path);
pathโ specifies the path of the file.
The return value is the canonicalized absolute path of a file, or NULL if the path is invalid. 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. don't leak, bestie ๐ซถ
The function tcstatfile is used in order to get the status information of a file. stat check โจ
bool tcstatfile(const char *path, bool *isdirp, int64_t *sizep,
int64_t *mtimep);
pathโ specifies the path of the file.isdirpโ specifies the pointer to a variable into which whether the file is a directory is assigned. If it isNULL, it is ignored.sizepโ specifies the pointer to a variable into which the size of the file is assigned. If it isNULL, it is ignored.ntimepโ specifies the pointer to a variable into which the size of the file is assigned. If it isNULL, it is ignored. yes, it really saysntimepin the manpage โ keep it moving ๐
If successful, the return value is true, else, it is false. simple ๐
The function tcreadfile is used in order to read whole data of a file. file nom nom ๐
void *tcreadfile(const char *path, int limit, int *sp);
pathโ specifies the path of the file. If it isNULL, the standard input is specified.limitโ specifies the limiting size of reading data. If it is not more than 0, the limitation is not specified.spโ specifies the pointer to the variable into which the size of the region of the return value is assigned. If it isNULL, it is not used.
The return value is the pointer to the allocated region of the read data, or NULL if the file could not be opened. 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 when is no longer in use. the double "when" is canon, bestie ๐ญ
The function tcreadfilelines is used in order to read every line of a file. line by line ๐
TCLIST *tcreadfilelines(const char *path);
pathโ specifies the path of the file. If it isNULL, the standard input is specified.
The return value is a list object of every lines if successful, else it is NULL. Line separators are cut out. 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. tclistdel or it's a whole situation ๐
The function tcwritefile is used in order to write data into a file. write it down โ๏ธ
bool tcwritefile(const char *path, const void *ptr, int size);
pathโ specifies the path of the file. If it isNULL, the standard output is specified.ptrโ specifies the pointer to the data region.sizeโ specifies the size of the region.
If successful, the return value is true, else, it is false. periodt ๐
The function tccopyfile is used in order to copy a file. copy paste realness ๐ฆ
bool tccopyfile(const char *src, const char *dest);
srcโ specifies the path of the source file.destโ specifies the path of the destination file.
The return value is true if successful, else, it is false. If the destination file exists, it is overwritten. overwritten, no hesitation ๐
The function tcreaddir is used in order to read names of files in a directory. directory tea โ
TCLIST *tcreaddir(const char *path);
pathโ specifies the path of the directory.
The return value is a list object of names if successful, else it is NULL. Links to the directory itself and to the parent directory are ignored. 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. don't forget the cleanup ๐ซถ
The function tcglobpat is used in order to expand a pattern into a list of matched paths. glob glob ๐ธ
TCLIST *tcglobpat(const char *pattern);
patternโ specifies the matching pattern.
The return value is a list object of matched paths. If no path is matched, an empty list is returned. 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. empty list is still a list, bestie ๐
The function tcremovelink is used in order to remove a file or a directory and its sub ones recursively. recursive delete, be careful ๐ญ
bool tcremovelink(const char *path);
pathโ specifies the path of the link.
If successful, the return value is true, else, it is false. False is returned when the link does not exist or the permission is denied. permission denied is a whole mood ๐
The function tcwrite is used in order to write data into a file. fd write โจ
bool tcwrite(int fd, const void *buf, size_t size);
fdโ specifies the file descriptor.bufโ specifies the buffer to be written.sizeโ specifies the size of the buffer.
The return value is true if successful, else, it is false. simple ๐
The function tcread is used in order to read data from a file. fd read ๐ฆ
bool tcread(int fd, void *buf, size_t size);
fdโ specifies the file descriptor.bufโ specifies the buffer to store into.sizeโ specifies the size of the buffer.
The return value is true if successful, else, it is false. periodt ๐
The function tclock is used in order to lock a file. lock it down ๐
bool tclock(int fd, bool ex, bool nb);
fdโ specifies the file descriptor.exโ specifies whether an exclusive lock or a shared lock is performed.nbโ specifies whether to request with non-blocking.
The return value is true if successful, else, it is false. no cap ๐
The function tcunlock is used in order to unlock a file. unlock the vibes ๐
bool tcunlock(int fd);
fdโ specifies the file descriptor.
The return value is true if successful, else, it is false. slay โจ
The function tcsystem is used in order to execute a shell command. shell command energy ๐ป
int tcsystem(const char **args, int anum);
argsโ specifies an array of the command name and its arguments.anumโ specifies the number of elements of the array.
The return value is the exit code of the command or INT_MAX on failure. The command name and the arguments are quoted and meta characters are escaped. quoted and escaped, periodt ๐
โจ API OF ENCODING UTILITIES โจ
The function tcurlencode is used in order to encode a serial object with URL encoding. URL encode bestie ๐
char *tcurlencode(const char *ptr, int size);
ptrโ specifies the pointer to the region.sizeโ specifies the size of the region.
The return value is the result string. 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. free it, fr fr ๐
The function tcurldecode is used in order to decode a string encoded with URL encoding. decode the vibes ๐ฆ
๐ tcurldecode ๐
char *tcurldecode(const char *str, int *sp);
strโ the encoded string, the one you wanna crack wide open.spโ a pointer to a variable where the size of the region of the return value gets assigned. ๐
The return value is a pointer to the region of the result. And because an extra zero code gets tacked onto the end of that region, you can lowkey just treat the return value as a character string. ๐ Since that region was allocated with the malloc call, release it with the free call the second it's no longer in use. Do not be out here leaking, bestie. ๐ซถ
๐ tcurlbreak ๐
This one is your URL shredder โ it breaks a URL up into its little elements.
TCMAP *tcurlbreak(const char *str);
strโ the URL string.
The return value is a map object whose keys are the name of elements. And ooh, the key tea is so good:
"self"โ indicates the URL itself."scheme"โ indicates the scheme."host"โ indicates the host of the server."port"โ indicates the port number of the server."authority"โ indicates the authority information."path"โ indicates the path of the resource."file"โ indicates the file name without the directory section."query"โ indicates the query string."fragment"โ indicates the fragment string.
Supported schema are HTTP, HTTPS, FTP, and FILE โ uppercase, periodt. Absolute URL and relative URL are both supported, which is giving range honestly. ๐
Because the object of the return value is created with the function tcmapnew, it should be deleted with the function tcmapdel when it is no longer in use. Clean up after yourself, queen. ๐งน
๐งฉ tcurlresolve ๐งฉ
Need to figure out where a relative URL actually lives? That's this function. It resolves a relative URL against an absolute URL.
char *tcurlresolve(const char *base, const char *target);
baseโ the absolute URL of the base location.targetโ the URL to be resolved.
The return value is the resolved URL. If the target URL is relative, you get a new URL of relative location from the base location. Else, you get a copy of the target URL. Simple as. โจ
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. ๐ซถ
๐ tcbaseencode ๐
Base64 encoding time. This function encodes a serial object with Base64 encoding.
char *tcbaseencode(const char *ptr, int size);
ptrโ the pointer to the region.sizeโ the size of the region.
The return value is the result string. And 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. ๐ธ
๐ tcbasedecode ๐
And here's the reverse โ decode a string that was encoded with Base64 encoding.
char *tcbasedecode(const char *str, int *sp);
strโ the encoded string.spโ the pointer to a 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. 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 โ iconic behaviour, honestly. ๐
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. ๐
โ๏ธ tcquoteencode โ๏ธ
Quoted-printable encoding, incoming. This one encodes a serial object with Quoted-printable encoding.
char *tcquoteencode(const char *ptr, int size);
ptrโ the pointer to the region.sizeโ the size of the region.
The return value is the result 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. ๐
๐ฌ tcquotedecode ๐ฌ
The un-quoting. This decodes a string that was encoded with Quoted-printable encoding.
char *tcquotedecode(const char *str, int *sp);
strโ the encoded string.spโ the pointer to a 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. 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. ๐ซถ
๐ tcmimeencode ๐
MIME encoding, the glow-up your strings deserve.
char *tcmimeencode(const char *str, const char *encname, bool base);
strโ the string.encnameโ the string of the name of the character encoding.baseโ whether to use Base64 encoding. If it isfalse, Quoted-printable is used.
The return value is the result 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. โจ
๐ tcmimedecode ๐
Peel the MIME back off. This decodes a string that was encoded with MIME encoding.
char *tcmimedecode(const char *str, char *enp);
strโ the encoded string.enpโ the pointer to the region into which the name of encoding is written. If it isNULL, it is not used. The size of the buffer should be equal to or more than 32 bytes. Don't skimp on the buffer, bestie. ๐
The return value is the result 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. ๐
โ๏ธ tcmimebreak โ๏ธ
This one splits a string of MIME into headers and the body. Very demure, very mindful. ๐
char *tcmimebreak(const char *ptr, int size, TCMAP *headers, int *sp);
ptrโ the pointer to the region of MIME data.sizeโ the size of the region.headersโ a map object to store headers. If it isNULL, it is not used. Each key of the map is an uncapitalized header name. (Lowercase keys, no shouting. ๐คซ)spโ 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 body data.
And the special keys that show up in the header map when the relevant stuff is defined โ obsessed with this list:
- If the content type is defined, the header map has the key
"TYPE"specifying the type. - If the character encoding is defined, the key
"CHARSET"indicates the encoding name. - If the boundary string of multipart is defined, the key
"BOUNDARY"indicates the string. - If the content disposition is defined, the key
"DISPOSITION"indicates the direction. - If the file name is defined, the key
"FILENAME"indicates the name. - If the attribute name is defined, the key
"NAME"indicates the name.
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. ๐ซถ
๐งฉ tcmimeparts ๐งฉ
Multipart data? Chop it into its parts.
TCLIST *tcmimeparts(const char *ptr, int size, const char *boundary);
ptrโ the pointer to the region of multipart data of MIME.sizeโ the size of the region.boundaryโ the boundary string.
The return value is a list object. Each element of the list is the data of a part. ๐
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. ๐งน
๐ข tchexencode ๐ข
Hexadecimal encoding โ the aesthetic of the encoding world, fr fr.
char *tchexencode(const char *ptr, int size);
ptrโ the pointer to the region.sizeโ the size of the region.
The return value is the result 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. ๐
๐ข tchexdecode ๐ข
Decode a string that was encoded with hexadecimal encoding.
char *tchexdecode(const char *str, int *sp);
strโ the encoded string.spโ the pointer to a 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. 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. ๐ซถ
๐ฆ tcpackencode ๐ฆ
Last one for this stretch: tcpackencode is used in order to compress a serial object with Packbits encoding. ๐๏ธ
okay bestie, next up in the encoding roster: the compress-y glow-up squad ๐ these are the ones that take your serial object and squeeze it into a smaller lil package, or un-squeeze it back. pay attention to which ones give you a zero-terminated string at the end, because that's a big difference ๐
The function tcpackencode is the one you call when you wanna compress a serial object with Packbits encoding โจ
char *tcpackencode(const char *ptr, int size, int *sp);
ptrโ points at the region. that's your input, bestie ๐ซถsizeโ how big that region is.spโ points at the variable where the size of the return value's region gets stashed.
If it works, the return value is the pointer to the result object. If it doesn't? NULL. sad. ๐ญ
and because that return region is allocated with themalloccall, you gotta release it with thefreecall once you're done with it. no leaks, no cap. ๐ง
The function tcpackdecode is its other half โ you use it to decompress a serial object that got compressed with Packbits encoding. ๐ฅ
char *tcpackdecode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at a variable where the size of the return value's region gets assigned.
Same deal: successful โ pointer to the result object, otherwise NULL. BUT here's the cute part โ because an additional zero code is appended at the end of the region of the return value, you can treat the return value as a character string ๐ so convenient.
and yeah,malloc-allocated region, sofreeit when it's no longer in use. periodt. ๐
The function tcbsencode compresses a serial object with TCBS encoding ๐
char *tcbsencode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at the variable where the size of the return value's region is assigned.
Success โ pointer to the result object. Fail โ NULL. and it's malloc'd, so free it when you're done. standard. โจ
The function tcbsdecode is the decompress side of that โ for serial objects compressed with TCBS encoding. ๐ฆ
char *tcbsdecode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at a variable where the size of the return value's region gets assigned.
Success โ pointer to the result object, else NULL. and yup, 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 ๐ฅฐ and also yup, it's malloc'd so free it when it's no longer in use.
The function tcdeflate compresses a serial object with Deflate encoding ๐ธ
char *tcdeflate(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at the variable where the size of the return value's region is assigned.
Success โ pointer to the result object, otherwise NULL. malloc'd, so free it when it's no longer in use. ๐
The function tcinflate decompresses a serial object compressed with Deflate encoding ๐
char *tcinflate(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at a variable where the size of the return value's region gets assigned.
Success โ pointer to the result object, else NULL. and because an additional zero code is appended at the end of the region of the return value, it can be treated as a character string ๐ and it's malloc'd, so free it when it's no longer in use.
The function tcgzipencode compresses a serial object with GZIP encoding ๐
char *tcgzipencode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at the variable where the size of the return value's region is assigned.
Success โ pointer to the result object, else NULL. malloc'd โ free it when it's no longer in use, bestie. ๐ซถ
The function tcgzipdecode decompresses a serial object compressed with GZIP encoding โจ
char *tcgzipdecode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at a variable where the size of the return value's region gets assigned.
Success โ pointer to the result object, else NULL. 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 ๐ and it's malloc'd, so free it when it's no longer in use.
The function tcgetcrc is your checksum girlie โ you use it to get the CRC32 checksum of a serial object. ๐
unsigned int tcgetcrc(const char *ptr, int size);
ptrโ points at the region.sizeโ the size of the region.
The return value is the CRC32 checksum of the object. that's it, that's the whole thing, no malloc drama here ๐
The function tcbzipencode compresses a serial object with BZIP2 encoding ๐ฅ
char *tcbzipencode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at the variable where the size of the return value's region is assigned.
Success โ pointer to the result object, else NULL. malloc'd โ free it when it's no longer in use. ๐
The function tcbzipdecode decompresses a serial object compressed with BZIP2 encoding ๐ธ
char *tcbzipdecode(const char *ptr, int size, int *sp);
ptrโ points at the region.sizeโ the size of the region.spโ points at a variable where the size of the return value's region gets assigned.
Success โ pointer to the result object, else NULL. 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 ๐ and it's malloc'd, so free it when it's no longer in use. you know the drill by now bestie, it's giving consistent ๐
The function tcberencode encodes an array of nonnegative integers with BER encoding โจ
char *tcberencode(const unsigned int *ary, int anum, int *sp);
aryโ points at the array of nonnegative integers.anumโ the size of the array.spโ points at a variable where the size of the return value's region gets assigned.
The return value is the pointer to the region of the result ๐ and because that region is allocated with the malloc call, it should be released with the free call when it's no longer in use. ๐ง
The function tcberdecode decodes a serial object encoded with BER encoding ๐ฆ
unsigned int *tcberdecode(const char *ptr, int size, int *np);
ptrโ points at the region.sizeโ the size of the region.npโ points at a variable where the number of elements of the return value gets assigned.
The return value is the pointer to the array of the result ๐ and because that region is allocated with the malloc call, it should be released with the free call when it's no longer in use.
The function tcxmlescape is here to escape meta characters in a string using the entity references of XML ๐
char *tcxmlescape(const char *str);
strโ the string.
The return value is the pointer to the escaped string. and heads up โ this function escapes only &, <, >, and ". that's the whole list, don't @ me ๐
because the region of the return value is allocated with themalloccall, it should be released with thefreecall when it's no longer in use. ๐ซถ
The function tcxmlunescape is used in order to unescape entity references in a string of XML ๐
โจ char *tcxmlunescape(const char *str); โจ
str is the string you're handing over, bestie โ that's the one getting unescaped.
What you get back is the unescaped string. ๐
Now, the tea: this function is not out here restoring every entity in the known universe. It only puts back these four, and these four only:
&<>"
That's the whole list. No extras, no surprises. ๐
Heads up, queen: the region of the return value is allocated with themalloccall, so you have to release it with thefreecall once you're done with it. Not freeing it is giving leak energy and we do not stan. ๐ญ
๐ SEE ALSO ๐
and that's a wrap on TCUTIL(3), my love!! ๐ฆ you made it all the way through all fourteen parts, which is genuinely iconic behaviour and I'm so proud of you fr fr. ๐
this little masterpiece lives in the source/version line as Man Page, dated 2012-08-18 โ so if you ever need to cite it, that's the receipt. ๐
now go forth and free your mallocs, bestie. mwah. ๐๐ธ
๐ฆ where this page comes from
- debian bookworm: libtokyocabinet-dev 1.4.48-15 ยท LGPL-2.1-or-later
- debian trixie: libtokyocabinet-dev 1.4.48-15.1+b1 ยท LGPL-2.1-or-later
- ubuntu jammy: libtokyocabinet-dev 1.4.48-14build1 ยท LGPL-2.1-or-later
- ubuntu noble: libtokyocabinet-dev 1.4.48-15.1build1 ยท LGPL-2.1-or-later
- ubuntu questing: libtokyocabinet-dev 1.4.48-15.1build2
- ubuntu resolute: libtokyocabinet-dev 1.4.48-15.1build3 ยท LGPL-2.1-or-later
- ubuntu stonking: libtokyocabinet-dev 1.4.48-15.1build3 ยท LGPL-2.1-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms