1tst(3) InterNetNews Documentation tst(3)
2
3
4
6 tst - ternary search trie functions
7
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,
18 int option, void **exist_ptr);
19
20 void *tst_search(struct tst *tst, const unsigned char *key);
21
22 void *tst_delete(struct tst *tst, const unsigned char *key);
23
25 tst_init allocates memory for members of struct tst, and allocates the
26 first node_line_width nodes. A NULL pointer is returned by tst_init if
27 any part of the memory allocation fails. On success, a pointer to a
28 struct tst is returned.
29
30 The value for node_line_width must be chosen very carefully. One node
31 is required for every character in the tree. If you choose a value that
32 is too small, your application will spend too much time calling
33 malloc(3) and your node space will be too spread out. Too large a value
34 is just a waste of space.
35
36 tst_cleanup frees all memory allocated to nodes, internal structures,
37 as well as tst itself.
38
39 tst_insert inserts the string key into the tree. Behavior when a
40 duplicate key is inserted is controlled by option. If key is already in
41 the tree then TST_DUPLICATE_KEY is returned, and the data pointer for
42 the existing key is placed in exist_ptr. If option is set to
43 TST_REPLACE then the existing data pointer for the existing key is
44 replaced by data. Note that the old data pointer will still be placed
45 in exist_ptr.
46
47 If a duplicate key is encountered and option is not set to TST_REPLACE
48 then TST_DUPLICATE_KEY is returned. If key is zero length then
49 TST_NULL_KEY is returned. A successful insert or replace returns
50 TST_OK. A return value of TST_ERROR indicates that a memory allocation
51 error occurred while trying to grow the node free.
52
53 Note that the data argument must never be NULL. If it is, then calls to
54 tst_search will fail for a key that exists because the data value was
55 set to NULL, which is what tst_search returns. If you just want a
56 simple existence tree, use the tst pointer as the data pointer.
57
58 tst_search finds the string key in the tree if it exists and returns
59 the data pointer associated with that key.
60
61 If key is not found then NULL is returned, otherwise the data pointer
62 associated with key is returned.
63
64 tst_delete deletes the string key from the tree if it exists and
65 returns the data pointer assocaited with that key.
66
67 If key is not found then NULL is returned, otherwise the data pointer
68 associated with key is returned.
69
71 Converted to POD from Peter A. Friend's ternary search trie
72 documentation by Alex Kiernan <alex.kiernan@thus.net> for
73 InterNetNews 2.4.0.
74
75 $Id: tst.pod 8200 2008-11-30 13:31:30Z iulius $
76
77
78
79INN 2.5.2 2010-08-11 tst(3)