-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataStructure.h
More file actions
185 lines (160 loc) · 3.07 KB
/
DataStructure.h
File metadata and controls
185 lines (160 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <stdio.h>
enum STATUS
{
GOOD = 0,
ERROR = -1,
FATAL = -2
};
enum BOOL
{
TRUE = 1,
FALSE = 0
};
enum TYPE
{
Complex,
Matrix,
LinkNode,
LinkList,
HashTable,
TreeNode,
BiTree,
Path,
Vertex,
Edge,
Graph,
Stack,
Queue,
BitArray,
String,
Set
};
typedef char *MESSAGE;
typedef struct RETURN_VAL
{
STATUS s;
MESSAGE msg;
} RETURN_VAL;
RETURN_VAL LAST_RET;
#define RETRES(ret) \
LAST_RET = ret; \
if (ret.s == STATUS.ERROR) \
{ \
printf("ERROR:%s", LAST_RET.msg); \
} \
else if (ret.s == STATUS.FATAL) \
{ \
printf("FATAL:%s", LAST_RET.msg); \
exit(-2); \
}
typedef struct Complex
{
TYPE t = TYPE::Complex;
double real;
double imag;
} Complex;
typedef struct Matrix
{
TYPE t = TYPE::Matrix;
char sparse = BOOL::FALSE; //TRUE:CSR FALSE:dense
int LinNum = 0;
int ColNum = 0;
int *offset;
int *colIdx;
double *data = NULL;
} Matrix;
typedef struct LinkNode
{
static const TYPE t = TYPE::LinkNode;
struct LinkNode *before;
struct LinkNode *next;
void *data;
} LinkNode;
typedef struct LinkList
{
static const TYPE t = TYPE::LinkList;
int length = 0;
LinkNode *head;
} LinkList;
typedef struct HashTable
{
static const TYPE t = TYPE::HashTable;
int length = 0;
LinkList *data;
} HashTable;
typedef struct TreeNode
{
static const TYPE t = TYPE::TreeNode;
void *value;
char LTag = -1;
char RTag = -1;
double weight = 0;
struct TreeNode *Parent = NULL;
struct TreeNode *LChild = NULL;
struct TreeNode *RChild = NULL;
} TreeNode;
typedef struct BiTree
{
static const TYPE t = TYPE::BiTree;
int nodeNum = 0;
TreeNode *root = NULL;
} BiTree;
typedef struct Path
{
static const TYPE t = TYPE::Path;
int length = 0;
LinkList *data;
} Path;
typedef struct Edge Edge;
typedef struct Vertex
{
static const TYPE t = TYPE::Vertex;
int ID;
double weight = 0;
Edge **incidenceE;
} Vertex;
typedef struct Edge
{
static const TYPE t = TYPE::Edge;
int ID;
double weight = 0;
Vertex *incidenceV[2] = {NULL};
} Edge;
typedef struct Graph
{
static const TYPE t = TYPE::Graph;
Vertex *verts = NULL;
Edge *edges = NULL;
} Graph;
typedef struct Stack
{
static const TYPE t = TYPE::Stack;
int length = 0;
void *data;
} Stack;
typedef struct Queue
{
static const TYPE t = TYPE::Queue;
int length = 0;
int capacity = 0;
int startIdx = -1;
void *data;
} Queue;
typedef struct BitArray
{
static const TYPE t = TYPE::BitArray;
unsigned long long len;
unsigned char *data;
} BitArray;
typedef struct String
{
static const TYPE t = TYPE::String;
int length = 0;
char *data;
} String;
typedef struct Set{
static const TYPE t = TYPE::Set;
int length;
BiTree* data;
} Set;
//EOF