1 /* basics.c */
2
3 #include "../EGraph.h"
4
5 /*--------------------------------------------------------------------*/
6 /*
7 -----------------------
8 constructor
9
10 created -- 95nov03, cca
11 -----------------------
12 */
13 EGraph *
EGraph_new(void)14 EGraph_new (
15 void
16 ) {
17 EGraph *eg ;
18
19 ALLOCATE(eg, struct _EGraph, 1) ;
20 EGraph_setDefaultFields(eg) ;
21
22 return(eg) ; }
23
24 /*--------------------------------------------------------------------*/
25 /*
26 -----------------------
27 set the default fields
28
29 created -- 95nov03, cca
30 -----------------------
31 */
32 void
EGraph_setDefaultFields(EGraph * eg)33 EGraph_setDefaultFields (
34 EGraph *eg
35 ) {
36 if ( eg == NULL ) {
37 fprintf(stderr, "\n fatal error in Egraph_setDefaultFields(%p)"
38 "\n bad input\n", eg) ;
39 exit(-1) ;
40 }
41 eg->type = 0 ;
42 eg->nelem = 0 ;
43 eg->nvtx = 0 ;
44 eg->adjIVL = NULL ;
45 eg->vwghts = NULL ;
46
47 return ; }
48
49 /*--------------------------------------------------------------------*/
50 /*
51 -----------------------
52 clear the data fields
53
54 created -- 95nov03, cca
55 -----------------------
56 */
57 void
EGraph_clearData(EGraph * eg)58 EGraph_clearData (
59 EGraph *eg
60 ) {
61 if ( eg == NULL ) {
62 fprintf(stderr, "\n fatal error in Egraph_clearData(%p)"
63 "\n bad input\n", eg) ;
64 exit(-1) ;
65 }
66 if ( eg->adjIVL != NULL ) {
67 IVL_free(eg->adjIVL) ;
68 }
69 if ( eg->vwghts != NULL ) {
70 IVfree(eg->vwghts) ;
71 }
72 EGraph_setDefaultFields(eg) ;
73
74 return ; }
75
76 /*--------------------------------------------------------------------*/
77 /*
78 -----------------------
79 destructor
80
81 created -- 95nov03, cca
82 -----------------------
83 */
84 void
EGraph_free(EGraph * eg)85 EGraph_free (
86 EGraph *eg
87 ) {
88 if ( eg == NULL ) {
89 fprintf(stderr, "\n fatal error in Egraph_free(%p)"
90 "\n bad input\n", eg) ;
91 exit(-1) ;
92 }
93 EGraph_clearData(eg) ;
94 FREE(eg) ;
95
96 return ; }
97
98 /*--------------------------------------------------------------------*/
99 /*
100 ----------------------------------------------
101 return the number of bytes taken by the object
102
103 created -- 95nov03, cca
104 ----------------------------------------------
105 */
106 int
EGraph_sizeOf(EGraph * eg)107 EGraph_sizeOf (
108 EGraph *eg
109 ) {
110 int bytes ;
111
112 bytes = sizeof(struct _EGraph) ;
113 if ( eg->adjIVL != NULL ) {
114 bytes += IVL_sizeOf(eg->adjIVL) ;
115 }
116 if ( eg->vwghts != NULL ) {
117 bytes += eg->nvtx * sizeof(int) ;
118 }
119 return(bytes) ; }
120
121 /*--------------------------------------------------------------------*/
122