X-Git-Url: http://git.silc.fi/gitweb/?p=runtime.git;a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilctree_i.h;fp=lib%2Fsilcutil%2Fsilctree_i.h;h=734c1ce92b3035d949cf6ae281afb29a83a9acac;hp=9f3a6aa36607fe21456081dd6e976f62613a7412;hb=55dac5fbf2f83e8ca4278fa6fcdbbccbeb1d12cd;hpb=9df31f979d5ebd26edd45dceed544c4eb166ccd4 diff --git a/lib/silcutil/silctree_i.h b/lib/silcutil/silctree_i.h index 9f3a6aa3..734c1ce9 100644 --- a/lib/silcutil/silctree_i.h +++ b/lib/silcutil/silctree_i.h @@ -28,16 +28,16 @@ struct SilcTreeOpsStruct { SilcBool (*add)(SilcTree *tree, void *entry); SilcBool (*del)(SilcTree *tree, void *entry); - void *(*find)(SilcTree *tree, void *entry, SilcTreeCompare compare, + void *(*find)(SilcTree *tree, void *entry, SilcCompare compare, void *context); }; /* Generic tree header, present in each entry in tree */ struct SilcTreeHeaderStruct { - struct SilcTreeHeaderStruct *parent; - struct SilcTreeHeaderStruct *left; - struct SilcTreeHeaderStruct *right; - struct SilcTreeHeaderStruct *dup; + struct SilcTreeHeaderStruct *parent; /* Parent of this node */ + struct SilcTreeHeaderStruct *left; /* Left leaft */ + struct SilcTreeHeaderStruct *right; /* Right leaft */ + struct SilcTreeHeaderStruct *dup; /* Duplicates, middle leaf, etc. */ SilcInt16 t; unsigned int duplicate : 1; }; @@ -46,7 +46,7 @@ struct SilcTreeHeaderStruct { struct SilcTreeStruct { const struct SilcTreeOpsStruct *ops; SilcTreeHeader *root; - SilcTreeCompare compare; + SilcCompare compare; void *context; SilcUInt32 count; unsigned int offset : 31; @@ -61,4 +61,28 @@ struct SilcTreeStruct { #define SILC_TREE_GET_ENTRY(tree, pos) \ ((void *)((unsigned char *)(pos) - tree->offset)) +/* Low level undocumented macro API for creating three-leaf binary trees. */ + +#define silc_tree_set_root(tree, root) \ + (tree).root = SILC_TREE_GET_HEADER(&(tree), (root)) +#define silc_tree_set_parent(tree, at, parent) \ + (at)->parent = SILC_TREE_GET_HEADER(&(tree), (parent)) +#define silc_tree_set_left(tree, at, left) \ + (at)->left = SILC_TREE_GET_HEADER(&(tree), (left)) +#define silc_tree_set_middle(tree, at, middle) \ + (at)->dup = SILC_TREE_GET_HEADER(&(tree), (middle)) +#define silc_tree_set_right(tree, at, right) \ + (at)->right = SILC_TREE_GET_HEADER(&(tree), (right)) + +#define silc_tree_get_root(tree) \ + SILC_TREE_GET_ENTRY(&(tree), (tree).root) +#define silc_tree_get_parent(tree, at) \ + SILC_TREE_GET_ENTRY(&(tree), (at)->parent) +#define silc_tree_get_left(tree, at) \ + SILC_TREE_GET_ENTRY(&(tree), (at)->left) +#define silc_tree_get_middle(tree, at) \ + SILC_TREE_GET_ENTRY(&(tree), (at)->middle) +#define silc_tree_get_right(tree, at) \ + SILC_TREE_GET_ENTRY(&(tree), (at)->right) + #endif /* SILCTREE_I_H */