1 /* basics.c */
2
3 #include "../DSTree.h"
4
5 #define MYTRACE 0
6 #define MYDEBUG 0
7
8 /*--------------------------------------------------------------------*/
9 /*
10 -----------------------------------------------
11 purpose -- create and return a new DSTree object
12
13 created -- 96mar10, cca
14 -----------------------------------------------
15 */
16 DSTree *
DSTree_new(void)17 DSTree_new (
18 void
19 ) {
20 DSTree *dstree ;
21
22 #if MYTRACE > 0
23 fprintf(stdout, "\n just inside DSTree_new()") ;
24 fflush(stdout) ;
25 #endif
26
27 ALLOCATE(dstree, struct _DSTree, 1) ;
28
29 DSTree_setDefaultFields(dstree) ;
30
31 #if MYTRACE > 0
32 fprintf(stdout, "\n leaving DSTree_new()") ;
33 fflush(stdout) ;
34 #endif
35
36 return(dstree) ; }
37
38 /*--------------------------------------------------------------------*/
39 /*
40 ------------------------------------------------------
41 purpose -- set the default fields for the DSTree object
42
43 created -- 96mar10, cca
44 ------------------------------------------------------
45 */
46 void
DSTree_setDefaultFields(DSTree * dstree)47 DSTree_setDefaultFields (
48 DSTree *dstree
49 ) {
50
51 #if MYTRACE > 0
52 fprintf(stdout, "\n just inside DSTree_setDefaultFields(%)", g) ;
53 fflush(stdout) ;
54 #endif
55
56 if ( dstree == NULL ) {
57 fprintf(stderr, "\n fatal error in DSTree_setDefaultFields(%p)"
58 "\n dstree is NULL\n", dstree) ;
59 exit(-1) ;
60 }
61 dstree->tree = NULL ;
62 dstree->mapIV = NULL ;
63
64 #if MYTRACE > 0
65 fprintf(stdout, "\n leaving DSTree_setDefaultFields(%)", dstree) ;
66 fflush(stdout) ;
67 #endif
68
69 return ; }
70
71 /*--------------------------------------------------------------------*/
72 /*
73 --------------------------------
74 purpose -- clear the data fields
75
76 created -- 96mar10, cca
77 --------------------------------
78 */
79 void
DSTree_clearData(DSTree * dstree)80 DSTree_clearData (
81 DSTree *dstree
82 ) {
83 #if MYTRACE > 0
84 fprintf(stdout, "\n just inside DSTree_clearData(%)", dstree) ;
85 fflush(stdout) ;
86 #endif
87
88 if ( dstree == NULL ) {
89 fprintf(stderr, "\n fatal error in DSTree_clearData(%p)"
90 "\n dstree is NULL\n", dstree) ;
91 exit(-1) ;
92 }
93
94 if ( dstree->tree != NULL ) {
95 Tree_clearData(dstree->tree) ;
96 Tree_free(dstree->tree) ;
97 }
98 if ( dstree->mapIV != NULL ) {
99 IV_free(dstree->mapIV) ;
100 }
101 DSTree_setDefaultFields(dstree) ;
102
103 #if MYTRACE > 0
104 fprintf(stdout, "\n leaving DSTree_clearData(%)", dstree) ;
105 fflush(stdout) ;
106 #endif
107
108 return ; }
109
110 /*--------------------------------------------------------------------*/
111 /*
112 --------------------------------
113 purpose -- free the DSTree object
114
115 created -- 96mar10, cca
116 --------------------------------
117 */
118 void
DSTree_free(DSTree * dstree)119 DSTree_free (
120 DSTree *dstree
121 ) {
122 #if MYTRACE > 0
123 fprintf(stdout, "\n just inside DSTree_free(%)", dstree) ;
124 fflush(stdout) ;
125 #endif
126
127 if ( dstree == NULL ) {
128 fprintf(stderr, "\n fatal error in DSTree_free(%p)"
129 "\n dstree is NULL\n", dstree) ;
130 exit(-1) ;
131 }
132
133 DSTree_clearData(dstree) ;
134 FREE(dstree) ;
135
136 #if MYTRACE > 0
137 fprintf(stdout, "\n leaving DSTree_free(%)", dstree) ;
138 fflush(stdout) ;
139 #endif
140
141 return ; }
142
143 /*--------------------------------------------------------------------*/
144