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