avlLib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:2k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* avlLib.h - AVL trees library header file */
  2. /* Copyright 1999 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01f,24jan01,sn  end file with newline(!) to avoid cpp errors
  7. 01e,10feb00,abd added avlMinimumGet and avlMaximumGet
  8. 01d,10feb00,abd added avlTreeWalk, avlTreePrint, avlTreeErase, avlTreePrintErase
  9. 01c,03feb00,abd added avlInsertInform, avlRemoveInsert
  10. 01b,24jan00,abd added avlSuccessorGet and avlPredecessorGet
  11. 01a,08feb99,wkn created.
  12. */
  13. #ifndef __INCavlLibh
  14. #define __INCavlLibh
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /* typedefs */
  19. typedef struct
  20.     {
  21.     void *  left;   /* pointer to the left subtree */
  22.     void *  right;  /* pointer to the right subtree */
  23.     int     height; /* height of the subtree rooted at this node */
  24.     } AVL_NODE;
  25. typedef AVL_NODE * AVL_TREE;    /* points to the root node of the tree */
  26. typedef union
  27.     {
  28.     int     i;
  29.     UINT    u;
  30.     void *  p;
  31.     } GENERIC_ARGUMENT;
  32. /* function declarations */
  33. void avlRebalance (AVL_NODE *** ancestors, int count);
  34. void * avlSearch (AVL_TREE root, GENERIC_ARGUMENT key,
  35.           int compare (void *, GENERIC_ARGUMENT));
  36. void * avlSuccessorGet (AVL_TREE root, GENERIC_ARGUMENT key,
  37.          int compare (void *, GENERIC_ARGUMENT)); 
  38. void * avlPredecessorGet (AVL_TREE root, GENERIC_ARGUMENT key,
  39.          int compare (void *, GENERIC_ARGUMENT)); 
  40. void * avlMinimumGet (AVL_TREE root);
  41. void * avlMaximumGet (AVL_TREE root);
  42. STATUS avlInsert (AVL_TREE * root, void * newNode, GENERIC_ARGUMENT key,
  43.           int compare (void *, GENERIC_ARGUMENT));
  44. STATUS avlInsertInform (AVL_TREE * pRoot, void * pNewNode, GENERIC_ARGUMENT key,
  45.           void ** ppKeyHolder,
  46.           int compare (void *, GENERIC_ARGUMENT));
  47. void * avlRemoveInsert (AVL_TREE * pRoot, void * pNewNode, GENERIC_ARGUMENT key,
  48.           int compare (void *, GENERIC_ARGUMENT));
  49. void * avlDelete (AVL_TREE * root, GENERIC_ARGUMENT key,
  50.           int compare (void *, GENERIC_ARGUMENT));
  51. STATUS avlTreeWalk(AVL_TREE * pRoot, void walkExec(AVL_TREE * nodepp));
  52. STATUS avlTreePrint(AVL_TREE * pRoot, void printNode(void * nodep));
  53. STATUS avlTreeErase(AVL_TREE * pRoot);
  54. STATUS avlTreePrintErase(AVL_TREE * pRoot, void printNode(void * nodep));
  55. /* specialized implementation functions */
  56. void * avlSearchUnsigned (AVL_TREE root, UINT key);
  57. STATUS avlInsertUnsigned (AVL_TREE * root, void * newNode);
  58. void * avlDeleteUnsigned (AVL_TREE * root, UINT key);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* __INCavlLibh */