-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_impedges.c
121 lines (108 loc) · 3.8 KB
/
create_impedges.c
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
/**
>HEADER
Copyright (c) 2004 Haixu Tang [email protected]
This file is part of the RepGraph package.
RepGraph is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RepGraph is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RepGraph. If not, see <http://www.gnu.org/licenses/>.
<HEADER
**/
#include <stdinc.h>
#include <extvab.h>
#include <extfunc.h>
int create_impedges(EDGE **impedges, EDGE *edge, NODES **vertex_new, int num_vertex_new, NODES **vertex, int *num_imp);
NODES *initiate_node(NODES *node1, NODES *node);
EDGE *initiate_edge(EDGE *edge1, EDGE *edge);
int create_impedges(EDGE **impedges, EDGE *edge, NODES **vertex_new, int num_vertex_new, NODES **vertex, int *num_imp)
{
int i, j, k, l, m, n;
NODES *begin, *end;
EDGE *edge1, *edge2, *bal_edge;
bal_edge = edge -> bal_edge;
/*
printf("edge %d bal_edge %d\n", edge -> multip, bal_edge -> multip);
*/
edge1 = initiate_edge(edge1, edge);
if(edge -> begin -> visit > 0) {
begin = vertex_new[edge -> begin -> visit - 1];
} else {
begin = initiate_node(begin, edge -> begin);
vertex_new[num_vertex_new ++] = begin;
edge -> begin -> visit = num_vertex_new;
}
begin -> nextedge[begin -> num_nextedge ++] = edge1;
edge1 -> begin = begin;
if(edge -> end -> visit > 0) {
end = vertex_new[edge -> end -> visit - 1];
} else {
end = initiate_node(end, edge -> end);
vertex_new[num_vertex_new ++] = end;
edge -> end -> visit = num_vertex_new;
}
end -> lastedge[end -> num_lastedge ++] = edge1;
edge1 -> end = end;
impedges[*num_imp] = edge1;
(*num_imp) ++;
edge -> visit = 1;
if(edge == bal_edge) {
edge1 -> bal_edge = edge1;
edge1 -> begin -> bal_node = edge1 -> end;
edge1 -> end -> bal_node = edge1 -> begin;
} else {
edge2 = initiate_edge(edge2, bal_edge);
if(bal_edge -> begin -> visit > 0) {
begin = vertex_new[bal_edge -> begin -> visit - 1];
} else {
begin = initiate_node(begin, bal_edge -> begin);
vertex_new[num_vertex_new ++] = begin;
bal_edge -> begin -> visit = num_vertex_new;
}
begin -> nextedge[begin -> num_nextedge ++] = edge2;
edge2 -> begin = begin;
if(bal_edge -> end -> visit > 0) {
end = vertex_new[bal_edge -> end -> visit - 1];
} else {
end = initiate_node(end, bal_edge -> end);
vertex_new[num_vertex_new ++] = end;
bal_edge -> end -> visit = num_vertex_new;
}
end -> lastedge[end -> num_lastedge ++] = edge2;
edge2 -> end = end;
impedges[*num_imp] = edge2;
(*num_imp) ++;
bal_edge -> visit = 1;
edge1 -> bal_edge = edge2;
edge2 -> bal_edge = edge1;
edge1 -> begin -> bal_node = edge2 -> end;
edge1 -> end -> bal_node = edge2 -> begin;
edge2 -> begin -> bal_node = edge1 -> end;
edge2 -> end -> bal_node = edge1 -> begin;
}
return(num_vertex_new);
}
EDGE *initiate_edge(EDGE *edge1, EDGE *edge)
{
int i;
edge1 = (EDGE *) ckalloc(1 * sizeof(EDGE));
edge1 -> length = edge -> length;
edge1 -> multip = edge -> multip;
edge1 -> readinterval = (READINTERVAL *) ckalloc(edge1 -> multip * sizeof(READINTERVAL));
for(i = 0; i < edge1 -> multip; i ++) {
edge1 -> readinterval[i] = edge -> readinterval[i];
}
return(edge1);
}
NODES *initiate_node(NODES *node1, NODES *node)
{
node1 = (NODES *) ckalloc(1 * sizeof(NODES));
node1 -> lastedge = (EDGE **) ckalloc((MAX_BRA + node -> num_lastedge) * sizeof(EDGE *));
node1 -> nextedge = (EDGE **) ckalloc((MAX_BRA + node -> num_nextedge) * sizeof(EDGE *));
return(node1);
}