libinn_tst(3)
β¨ NAME β¨
libinn_tst(3) is the InterNetNews Documentation page for tst β ternary search trie functions. Bestie, this is the whole vibe: a little C library for storing stuff in a ternary search trie. π¦
πΈ SYNOPSIS πΈ
Here's the exact shape of the API, no cap:
#include <inn/tst.h>
enum tst_constants {
TST_OK,
TST_NULL_KEY,
TST_NULL_DATA,
TST_DUPLICATE_KEY,
TST_REPLACE
};
struct tst;
struct tst *tst_init(int node_line_width);
void tst_cleanup(struct tst *tst);
int tst_insert(struct tst *tst, const unsigned char *key,
void *data, int option, void **exist_ptr);
void *tst_search(struct tst *tst, const unsigned char *key);
void *tst_delete(struct tst *tst, const unsigned char *key);
π₯ DESCRIPTION π₯
Okay so first up: tst_init allocates memory for members of struct tst, and it allocates the first node_line_width nodes. If any part of the memory allocation fails, tst_init returns a NULL pointer. On success, you get a pointer to a struct tst. Slay. π
The value for node_line_width must be chosen very carefully. One node is required for every character in the tree. If you choose a value that is too small, your application will spend too much time calling malloc(3) and your node space will be too spread out. Too large a value is just a waste of space. So yeah β pick your number with intention, bestie. π
tst_cleanup frees all memory allocated to nodes, internal structures, as well as tst itself. It's the full cleanup arc, no leftovers. β¨
tst_insert inserts the string key into the tree. Behavior when a duplicate key is inserted is controlled by option. If key is already in the tree, then TST_DUPLICATE_KEY is returned, and the data pointer for the existing key is placed in exist_ptr. If option is set to TST_REPLACE, then the existing data pointer for the existing key is replaced by data. Note that the old data pointer will still be placed in exist_ptr. Keeping receipts, fr fr. π«Ά
If a duplicate key is encountered and option is not set to TST_REPLACE, then TST_DUPLICATE_KEY is returned. If key is zero length, then TST_NULL_KEY is returned. A successful insert or replace returns TST_OK. A return value of TST_ERROR indicates that a memory allocation error occurred while trying to grow the node free. Yeah, that's the dramatic plot twist. π
Note that thedataargument must never beNULL. If it is, then calls totst_searchwill fail for a key that exists because the data value was set toNULL, which is whattst_searchreturns. If you just want a simple existence tree, use thetstpointer as the data pointer. This is the one warning that will absolutely ruin your day if you ignore it. π
tst_search finds the string key in the tree if it exists and returns the data pointer associated with that key.
If key is not found then NULL is returned, otherwise the data pointer associated with key is returned.
tst_delete deletes the string key from the tree if it exists and returns the data pointer associated with that key.
If key is not found, then NULL is returned, otherwise the data pointer associated with key is returned. Same energy, different function. π
π HISTORY π
Converted to POD from Peter A. Friend's ternary search trie documentation by Alex Kiernan <alex.kiernan@thus.net> for InterNetNews 2.4.0. Historical icon behavior, honestly. π
π SEE ALSO π
Okay that's the whole page, bestie: this is from INN 2.7.4, dated 2022-07-10, and it's the libinn_tst(3) manual page. Mwah π
π¦ where this page comes from
- arch rolling: inn 2.7.4-4 Β· ISC
- epel 10: inn-devel 2.7.4-5.el10_3 Β· ISC AND BSD-3-Clause AND BSD-4-Clause AND FSFAP AND (GPL-1.0-or-later OR Artistic-1.0-Perl) AND GPL-3.0-or-later WITH Bison-exception-2.2 AND LicenseRef-Fedora-Public-Domain AND MIT AND NTP
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms