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           enum tst_constants {
12               TST_OK,
13               TST_NULL_KEY,
14               TST_NULL_DATA,
15               TST_DUPLICATE_KEY,
16               TST_REPLACE
17           };
18
19           struct tst;
20
21           struct tst *tst_init(int node_line_width);
22
23           void tst_cleanup(struct tst *tst);
24
25           int tst_insert(struct tst *tst, const unsigned char *key,
26                          void *data, int option, void **exist_ptr);
27
28           void *tst_search(struct tst *tst, const unsigned char *key);
29
30           void *tst_delete(struct tst *tst, const unsigned char *key);
31

DESCRIPTION

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

HISTORY

79       Converted to POD from Peter A. Friend's ternary search trie
80       documentation by Alex Kiernan <alex.kiernan@thus.net> for
81       InterNetNews 2.4.0.
82

SEE ALSO

84       libinn(3).
85
86
87
88INN 2.7.0                         2022-07-10                     libinn_tst(3)
Impressum