bintree.h

00001 
00088 /*---------------------------------------------------------------
00089  HISTORY
00090  7-Dec-2004     Graeme McKerrell    
00091    Updated to use the "lub" prefix
00092 27-Feb-2004     Graeme McKerrell    
00093    updated to simplify node initialisation
00094 9-Feb-2004      Graeme McKerrell    
00095    updated to make the comparision function compare a "clientnode" and
00096    "key"
00097    Updated getkey() function to fill out a provides "key" from a "clientnode"
00098 23-Jan-2004     Graeme McKerrell    
00099    Initial version
00100 --------------------------------------------------------------
00101 Copyright (C) 2004 3Com Corporation. All Rights Reserved.
00102 **************************************************************** */
00103 #ifndef _lub_bintree_h
00104 #define _lub_bintree_h
00105 #include <stddef.h>
00106 
00107 /****************************************************************
00108  * TYPE DEFINITIONS
00109  **************************************************************** */
00118 typedef struct lub_bintree_node_s lub_bintree_node_t;
00122 struct lub_bintree_node_s
00123 {lub_bintree_node_t *left; lub_bintree_node_t *right;
00126 };
00127 
00140 typedef int
00141         lub_bintree_compare_fn(const void *clientnode,
00142                        const void *clientkey);
00148 #define lub_bintree_MAX_KEY_STORAGE (200)
00149 
00154 typedef struct lub_bintree_key_s lub_bintree_key_t;
00158 struct lub_bintree_key_s
00159 {char storage[lub_bintree_MAX_KEY_STORAGE];int  magic;
00162 };
00163 
00174 typedef void
00175         lub_bintree_getkey_fn(const void        *clientnode,
00176                               lub_bintree_key_t *key);
00177 
00181 typedef struct lub_bintree_s lub_bintree_t;
00185 struct lub_bintree_s
00186 {lub_bintree_node_t     *root;size_t                  node_offset;lub_bintree_compare_fn *compareFn;lub_bintree_getkey_fn  *getkeyFn;
00191 };
00192 
00196 typedef struct lub_bintree_iterator_s lub_bintree_iterator_t;
00200 struct lub_bintree_iterator_s
00201 {lub_bintree_t    *tree;lub_bintree_key_t key;
00204 };
00205 
00206 /****************************************************************
00207  * BINTREE OPERATIONS
00208  **************************************************************** */
00216 extern void
00217     lub_bintree_init(
00221         lub_bintree_t         *tree,
00227         size_t                 node_offset,
00232         lub_bintree_compare_fn compareFn,
00236         lub_bintree_getkey_fn  getkeyFn
00237     );
00238 
00248 extern void
00249         lub_bintree_node_init(
00253             lub_bintree_node_t *node
00254         );
00255 
00256 /*****************************************
00257  * NODE MANIPULATION OPERATIONS
00258  ***************************************** */
00273 extern int
00274         lub_bintree_insert(
00278             lub_bintree_t *tree,
00283             void          *clientnode
00284         );
00285 
00297 extern void
00298         lub_bintree_remove(
00302             lub_bintree_t *tree,
00306             void          *clientnode
00307         );
00308 
00309 /*****************************************
00310  * NODE RETRIEVAL OPERATIONS
00311  ***************************************** */
00320 extern void *
00321     lub_bintree_findfirst(
00325         lub_bintree_t *tree
00326     );
00327 
00336 extern void *
00337     lub_bintree_findlast(
00341         lub_bintree_t *tree
00342     );
00343 
00353 extern void *
00354     lub_bintree_find(
00358         lub_bintree_t *tree,
00362             const void    *key
00363     );
00364 
00376 extern void *
00377     lub_bintree_findnext(
00381         lub_bintree_t *tree,
00385             const void    *key
00386     );
00387 
00399 extern void *
00400     lub_bintree_findprevious(
00404         lub_bintree_t *tree,
00408                 const void    *key
00409     );
00410 
00411 /*****************************************
00412  * ITERATION OPERATIONS
00413  ***************************************** */
00425 extern void
00426         lub_bintree_iterator_init(
00430             lub_bintree_iterator_t *iter,
00434             lub_bintree_t          *tree,
00438             const void             *clientnode
00439             );
00440 
00452 extern void *
00453     lub_bintree_iterator_next(
00457         lub_bintree_iterator_t *iter
00458     );
00459 
00471 extern void *
00472     lub_bintree_iterator_previous(
00476         lub_bintree_iterator_t *iter
00477     );
00485 extern void
00486     lub_bintree_dump(
00490     lub_bintree_t *tree
00491     );
00492 
00493 #endif /* _lub_bintree_h */
00494 

Generated on Tue Apr 29 13:41:07 2008 for CLISH by  doxygen 1.5.1