Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

tst(3) [suse man page]

tst(3)							    InterNetNews Documentation							    tst(3)

NAME
tst - ternary search trie functions SYNOPSIS
#include <inn/tst.h> 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
tst_init allocates memory for members of struct tst, and allocates the first node_line_width nodes. A NULL pointer is returned by tst_init if any part of the memory allocation fails. On success, a pointer to a struct tst is returned. 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. tst_cleanup frees all memory allocated to nodes, internal structures, as well as tst itself. 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. 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. Note that the data argument must never be NULL. If it is, then calls to tst_search will fail for a key that exists because the data value was set to NULL, which is what tst_search returns. If you just want a simple existence tree, use the tst pointer as the data pointer. 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 assocaited with that key. If key is not found then NULL is returned, otherwise the data pointer associated with key is returned. 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. $Id: tst.pod 8200 2008-11-30 13:31:30Z iulius $ INN 2.5.2 2009-05-21 tst(3)

Check Out this Related Man Page

tsearch(3)						     Library Functions Manual							tsearch(3)

Name
       tsearch, tfind, tdelete, twalk - manage binary search trees

Syntax
       #include <search.h>

       void *tsearch (key, rootp, compar)
       void *key;
       void **rootp;
       int (*compar)( );

       void *tfind (key, rootp, compar)
       void *key;
       void **rootp;
       int (*compar)( );

       void *tdelete (key, rootp, compar)
       void *key;
       void **rootp;
       int (*compar)( );

       void twalk (root, action)
       void * root;
       void (*action)( );

Description
       The  subroutine	is  a  binary tree search routine generalized from Knuth (6.2.2) Algorithm T.  It returns a pointer into a tree indicating
       where a datum may be found.  If the datum does not occur, it is added at an appropriate point in the tree.  The key points to the datum	to
       be  sought in the tree.	The rootp points to a variable that points to the root of the tree.  A NULL pointer value for the variable denotes
       an empty tree; in this case, the variable will be set to point to the datum at the root of the new tree.  The compar is	the  name  of  the
       comparison  function.  It is called with two arguments that point to the elements being compared.  The function must return an integer less
       than, equal to, or greater than zero according as the first argument is to be considered less than, equal to, or greater than the second.

       Like will search for a datum in the tree, returning a pointer to it if found.  However, if it is not found, will  return  a  NULL  pointer.
       The arguments for are the same as for

       The  subroutine deletes a node from a binary search tree.  It is generalized from Knuth (6.2.2) algorithm D.  The arguments are the same as
       for The variable pointed to by rootp will be changed if the deleted node was the root of the tree.  The subroutine returns a pointer to the
       parent of the deleted node, or a NULL pointer if the node is not found.

       The  subroutine	traverses a binary search tree.  The root is the root of the tree to be traversed.  (Any node in a tree may be used as the
       root for a walk below that node.)  The action is the name of a routine to be invoked at each node.  This routine is, in turn,  called  with
       three  arguments.   The	first  argument is the address of the node being visited.  The second argument is a value from an enumeration data
       type typedef enum { preorder, postorder, endorder, leaf } VISIT; (defined in the <search.h> header file), depending on whether this is  the
       first, second or third time that the node has been visited (during a depth-first, left-to-right traversal of the tree), or whether the node
       is a leaf.  The third argument is the level of the node in the tree, with the root being level zero.  The pointers to the key and the  root
       of the tree should be of type pointer-to-element, and cast to type pointer-to-character.

       The  comparison	function  need	not compare every byte, so arbitrary data may be contained in the elements in addition to the values being
       compared.

       Although declared as type pointer-to-character, the value returned should be cast into type pointer-to-element.

       Note that the root argument to is one level of indirection less than the rootp arguments to and

Return Values
       A NULL pointer is returned by if there is not enough space available to create a new node.
       A NULL pointer is returned by and if rootp is NULL on entry.
       If the datum is found, both and return a pointer to it.	If not, returns NULL, and returns a pointer to the inserted item.

Restrictions
       Results are unpredictable if the calling function alters the pointer to the root.

Diagnostics
       A NULL pointer is returned by and if rootp is NULL on entry.

See Also
       bsearch(3), hsearch(3), lsearch(3)

																	tsearch(3)
Man Page