Annotation of mstools/samples/rpc/dict/dict0.h, revision 1.1.1.3

1.1       root        1: /*************************************************************/
                      2: /**                                                         **/
                      3: /**                 Microsoft RPC Examples                  **/
                      4: /**                 Dictionary Application                  **/
1.1.1.2   root        5: /**             Copyright(c) Microsoft Corp. 1992           **/
1.1       root        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: 
1.1.1.3 ! root       14: typedef int (*cmp_rec_func)(void *, void *);
        !            15:                             /* type of a comparison function */
1.1       root       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 {
1.1.1.3 ! root       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 */
1.1       root       28:     TreeNode* (*splay)(TreeNode *, void *, cmp_rec_func);
1.1.1.3 ! root       29:                                     /* pointer to a splay function      */
        !            30:     void (*print_rec)(void *);      /* one line print function          */
1.1       root       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
1.1.1.3 ! root       79: } Dict_Status;
1.1       root       80: 
1.1.1.3 ! root       81: #define DICT_CURR_ITEM(pDict)  ( (pDict)->root->item )
1.1       root       82: 
1.1.1.3 ! root       83: #define DICT_EMPTY(pDict)      ( (pDict)->root == NULL )
1.1       root       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 */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.