1libinn_tst(3)             InterNetNews Documentation             libinn_tst(3)
2
3
4

NAME

6       tst - ternary search trie functions
7

SYNOPSIS

9           #include <inn/tst.h>
10
11           struct tst;
12
13           struct tst *tst_init(int node_line_width);
14
15           void tst_cleanup(struct tst *tst);
16
17           int tst_insert(struct tst *tst, const unsigned char *key, void *data, int option, void **exist_ptr);
18
19           void *tst_search(struct tst *tst, const unsigned char *key);
20
21           void *tst_delete(struct tst *tst, const unsigned char *key);
22

DESCRIPTION

24       tst_init allocates memory for members of struct tst, and allocates the
25       first node_line_width nodes. A NULL pointer is returned by tst_init if
26       any part of the memory allocation fails. On success, a pointer to a
27       struct tst is returned.
28
29       The value for node_line_width must be chosen very carefully. One node
30       is required for every character in the tree. If you choose a value that
31       is too small, your application will spend too much time calling
32       malloc(3) and your node space will be too spread out. Too large a value
33       is just a waste of space.
34
35       tst_cleanup frees all memory allocated to nodes, internal structures,
36       as well as tst itself.
37
38       tst_insert inserts the string key into the tree. Behavior when a
39       duplicate key is inserted is controlled by option. If key is already in
40       the tree then TST_DUPLICATE_KEY is returned, and the data pointer for
41       the existing key is placed in exist_ptr.  If option is set to
42       TST_REPLACE then the existing data pointer for the existing key is
43       replaced by data.  Note that the old data pointer will still be placed
44       in exist_ptr.
45
46       If a duplicate key is encountered and option is not set to TST_REPLACE
47       then TST_DUPLICATE_KEY is returned. If key is zero length then
48       TST_NULL_KEY is returned. A successful insert or replace returns
49       TST_OK. A return value of TST_ERROR indicates that a memory allocation
50       error occurred while trying to grow the node free.
51
52       Note that the data argument must never be NULL. If it is, then calls to
53       tst_search will fail for a key that exists because the data value was
54       set to NULL, which is what tst_search returns. If you just want a
55       simple existence tree, use the tst pointer as the data pointer.
56
57       tst_search finds the string key in the tree if it exists and returns
58       the data pointer associated with that key.
59
60       If key is not found then NULL is returned, otherwise the data pointer
61       associated with key is returned.
62
63       tst_delete deletes the string key from the tree if it exists and
64       returns the data pointer assocaited with that key.
65
66       If key is not found then NULL is returned, otherwise the data pointer
67       associated with key is returned.
68

HISTORY

70       Converted to POD from Peter A. Friend's ternary search trie
71       documentation by Alex Kiernan <alex.kiernan@thus.net> for
72       InterNetNews 2.4.0.
73
74
75
76INN 2.6.5                         2022-02-18                     libinn_tst(3)
Impressum