home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / dict / dict0.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  5.1 KB  |  120 lines

  1. /*************************************************************/
  2. /**                                                         **/
  3. /**                 Microsoft RPC Examples                  **/
  4. /**                 Dictionary Application                  **/
  5. /**             Copyright(c) Microsoft Corp. 1992-1996      **/
  6. /**                                                         **/
  7. /*************************************************************/
  8.  
  9. /**************************************************************/
  10. /*  user interface header file for top down splay package     */
  11. /*  based on Sleator & Tarjan's Self Adjusting Trees          */
  12. /**************************************************************/
  13.  
  14. typedef int (*cmp_rec_func)(void *, void *);
  15.                             /* type of a comparison function */
  16.  
  17. typedef struct tnode {
  18.     struct tnode *left;     /* left child pointer */
  19.     struct tnode *right;    /* right child pointer */
  20.     void *item;             /* pointer to some structure */
  21. } TreeNode;
  22.  
  23. typedef struct dictnode {
  24.     TreeNode *root;                 /* pointer to the root of a SAT     */
  25.     long size;                      /* number of records in dictionary  */
  26.     void * state;                   /* reserved for state info          */
  27.     cmp_rec_func cmp_rec;           /* pointer to a comparison function */
  28.     TreeNode* (*splay)(TreeNode *, void *, cmp_rec_func);
  29.                                     /* pointer to a splay function      */
  30.     void (*print_rec)(void *);      /* one line print function          */
  31. } Dictionary;
  32.  
  33. /*************************************************************************/
  34. /*****              Core functions (internal)                        *****/
  35. /*************************************************************************/
  36.  
  37. TreeNode *              /* returns the new root                 */
  38. tdSplay(                /* general top down splay               */
  39.     TreeNode *root,     /* the current root of the tree         */
  40.     void *keyItem,      /* pointer to a "key item" searched for */
  41.     int (*cmp)(void *, void *) );
  42.                         /* pointer to a comparison function     */
  43.  
  44. TreeNode*
  45. tdSplayLeft(TreeNode* root);
  46.  
  47. TreeNode*
  48. tdSplayRight(TreeNode* root);
  49.  
  50. void
  51. print_tree_sat(         /* prints the binary tree (indented right subtree,
  52.                            followed by the root, followed by the indented
  53.                            right dubtree) */
  54.     Dictionary * dp,
  55.     int indent);        /* number of blanks to indent subtrees */
  56.  
  57. /*************************************************************************/
  58. /***    Minimal Dictionary Operations:                                 ***/
  59. /***                                                                   ***/
  60. /***    Dictionary *Dict_New(Cmp_rec*, Splay*, print_rec*)             ***/
  61. /***                                                                   ***/
  62. /***    Dict_Status Dict_Find(Dictionary*, Item*)                      ***/
  63. /***    Dict_Status Dict_Next(Dictionary*, Item*)                      ***/
  64. /***    Dict_Status Dict_Prev(Dictionary*, Item*)                      ***/
  65. /***    Dict_Status Dict_Insert(Dictionary*, Item*)                    ***/
  66. /***    Dict_Status Dict_Delete(Dictionary*, Item**)                   ***/
  67. /***                                                                   ***/
  68. /***    Item* DICT_CURR_ITEM(Dict*)                                    ***/
  69. /*************************************************************************/
  70.  
  71. typedef enum {
  72.     SUCCESS,
  73.     ITEM_ALREADY_PRESENT,
  74.     ITEM_NOT_FOUND,
  75.     FIRST_ITEM,
  76.     LAST_ITEM,
  77.     EMPTY_DICTIONARY,
  78.     NULL_ITEM
  79. } Dict_Status;
  80.  
  81. #define DICT_CURR_ITEM(pDict)  ( (pDict)->root->item )
  82.  
  83. #define DICT_EMPTY(pDict)      ( (pDict)->root == NULL )
  84.  
  85. Dictionary*
  86. Dict_New(                    /* returns a new dictionary node          */
  87.     int (*cmp_rec)           /* pointer to item comparison function    */
  88.         (void *, void *),
  89.     TreeNode* (*splay)       /* pointer to a splay function            */
  90.         (TreeNode *, void *, cmp_rec_func),
  91.  
  92.     void (*print_rec)        /* pointer to one line item print routine */
  93.         (void *) );
  94.  
  95. Dict_Status
  96. Dict_Find(
  97.     Dictionary* dp,     /* Dictionary to be searched. */
  98.     void* item);        /* Item searched for. */
  99.  
  100. Dict_Status
  101. Dict_Next(
  102.     Dictionary* dp,     /* Dictionary to be searched. */
  103.     void* item);        /* A Key item.  Advance to successor of item in dp. */
  104.  
  105. Dict_Status
  106. Dict_Prev(
  107.     Dictionary* dp,     /* Dictionary to be searched. */
  108.     void* item);        /* A Key item.  Retreat to predecessor of item in dp. */
  109.  
  110. Dict_Status
  111. Dict_Insert(            /* insert the given item into the tree */
  112.     Dictionary* dp,     /* the modified dictionary */
  113.     void* item);        /* the item to be inserted */
  114.  
  115. Dict_Status
  116. Dict_Delete(            /* delete the given item into from the tree */
  117.     Dictionary* dp,     /* the modified dictionary */
  118.     void** pItem);      /* IN: points to the (key) item to be deleted */
  119.                         /* OUT: points to the item just deleted */
  120.