silc_tree_init

SYNOPSIS

    SilcBool silc_tree_init(SilcTree tree, SilcTreeType type,
                            SilcCompare compare, void *context,
                            SilcUInt16 offset, SilcBool duplicates);

DESCRIPTION

Initializes the `tree' as a tree type indicated by `type'. The `compare' function will be called to compare entries in the tree, for example, when finding entries from the tree. The `context' is delivered to the callback function.

The `offset' is the byte offset of the SilcTreeHeader structure field in the entry structure that is going to be added to the tree. Each structure that is added to the tree must contain SilcTreeHeader structure. Use silc_offsetof to get the byte offset.

If the `duplicates' is TRUE the tree will allow the addition of duplicate values. However, the entry context to be added must not already be in the tree, but its value may be same as some other context's.

The `tree' need not be uninitialized. The caller is responsible of freeing the entries it has added to the tree.

Return FALSE if the `type' is of unknown tree type. Returns TRUE otherwise. This function does not allocate any memory.

EXAMPLE

 // Structure that is going to be added to tree
 typedef struct {
   SilcTreeHeader header;
   char *name;
   int id;
 } FooEntry;

 SilcTree tree;
 silc_tree_init(tree, SILC_TREE_AVL, compare, context,
                silc_offsetof(FooEntry, header));