home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTBTree.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  2.1 KB  |  105 lines

  1. /*                  /Net/dxcern/userd/timbl/hypertext/WWW/Library/Implementation/HTBTree.html
  2.                          BALANCED BINARY TREE FOR SORTING THINGS
  3.                                              
  4.    Tree creation, traversal and freeing.  User-supplied comparison routine.
  5.    
  6.    Author: Arthur Secret, CERN. Public domain.  Please mail bugs and changes to
  7.    www-request@info.cern.ch
  8.    
  9.    part of libWWW
  10.    
  11.  */
  12. #ifdef SHORT_NAMES
  13. #define HTBTree_new             HTBTNew
  14. #define HTBTree_free            HTBTFree
  15. #define HTBTreeAndObject_free   HTBTAOFr
  16. #define HTBTree_add             HTBTAdd
  17. #define HTBTree_next            HTBTNext
  18. /* #define      HTBTree_object          HTBTObje already a macro */
  19. #endif
  20.  
  21.  
  22. /*
  23.  
  24. Data structures
  25.  
  26.  */
  27. typedef struct _HTBTree_element {
  28.     void                        *object;        /* User object */
  29.     struct _HTBTree_element     *up;
  30.     struct _HTBTree_element     *left;
  31.     int                         left_depth;
  32.     struct _HTBTree_element     *right;
  33.     int                         right_depth;
  34. } HTBTElement;
  35.  
  36. typedef int (*HTComparer) PARAMS((void * a, void * b));
  37.  
  38. typedef struct _HTBTree_top {
  39.     HTComparer                  compare;
  40.     struct _HTBTree_element     *top;
  41. } HTBTree;
  42.  
  43.  
  44. /*
  45.  
  46. Create a binary tree given its discrimination routine
  47.  
  48.  */
  49. extern HTBTree * HTBTree_new PARAMS((HTComparer comp));
  50.  
  51.  
  52.  
  53. /*
  54.  
  55. Free storage of the tree but not of the objects
  56.  
  57.  */
  58. extern void HTBTree_free PARAMS((HTBTree* tree));
  59.  
  60.  
  61.  
  62. /*
  63.  
  64. Free storage of the tree and of the objects
  65.  
  66.  */
  67. extern void HTBTreeAndObject_free PARAMS((HTBTree* tree));
  68.  
  69.  
  70.  
  71. /*
  72.  
  73. Add an object to a binary tree
  74.  
  75.  */
  76.  
  77. extern void HTBTree_add PARAMS((HTBTree* tree, void * object));
  78.  
  79.  
  80. /*
  81.  
  82. Find user object for element
  83.  
  84.  */
  85. #define HTBTree_object(element)  ((element)->object)
  86.  
  87.  
  88. /*
  89.  
  90. Find next element in depth-first order
  91.  
  92.   ON ENTRY,
  93.   
  94.   ele                    if NULL, start with leftmost element. if != 0 give next object to
  95.                          the right.
  96.                          
  97.   returns                Pointer to element ot NULL if none left.
  98.                          
  99.  */
  100. extern HTBTElement * HTBTree_next PARAMS((HTBTree* tree, HTBTElement * ele));
  101.  
  102. /*
  103.  
  104.    end  */
  105.