@@ -58,64 +58,77 @@ template <typename captype, typename tcaptype, typename flowtype>
5858 flow = 0 ;
5959}
6060
61- template <typename captype, typename tcaptype, typename flowtype>
62- void Graph<captype,tcaptype,flowtype>::reallocate_nodes(int num)
63- {
64- int node_num_max = (int )(node_max - nodes);
65- node* nodes_old = nodes;
66-
67- node_num_max += node_num_max / 2 ;
68- if (node_num_max < node_num + num) node_num_max = node_num + num;
69- nodes = (node*) realloc (nodes_old, node_num_max*sizeof (node));
70- if (!nodes) { if (error_function) (*error_function)(" Not enough memory!" ); exit (1 ); }
71-
72- node_last = nodes + node_num;
73- node_max = nodes + node_num_max;
74-
75- if (nodes != nodes_old)
76- {
77- node* i;
78- arc* a;
79- for (i=nodes; i<node_last; i++)
80- {
81- if (i->next ) i->next = (node*) ((char *)i->next + (((char *) nodes) - ((char *) nodes_old)));
82- }
83- for (a=arcs; a<arc_last; a++)
84- {
85- a->head = (node*) ((char *)a->head + (((char *) nodes) - ((char *) nodes_old)));
86- }
87- }
61+ template <typename captype, typename tcaptype, typename flowtype>
62+ void Graph<captype, tcaptype, flowtype>::reallocate_nodes(int num) {
63+ int node_num_max = (int )(node_max - nodes);
64+ size_t nodes_old = (size_t )nodes;
65+
66+ node_num_max += node_num_max / 2 ;
67+ if (node_num_max < node_num + num) node_num_max = node_num + num;
68+
69+ nodes = (node*)realloc (nodes, node_num_max * sizeof (node));
70+
71+ if (!nodes) {
72+ if (error_function) (*error_function)(" Not enough memory!" );
73+ exit (1 );
74+ }
75+
76+ node_last = nodes + node_num;
77+ node_max = nodes + node_num_max;
78+
79+ if ((size_t )nodes != nodes_old) {
80+ node* i;
81+ arc* a;
82+ for (i = nodes; i < node_last; i++) {
83+ if (i->next )
84+ i->next =
85+ (node*)((size_t )i->next +
86+ (((size_t )nodes) - ((size_t )nodes_old)));
87+ }
88+ for (a = arcs; a < arc_last; a++) {
89+ a->head = (node*)((size_t )a->head +
90+ (((size_t )nodes) - ((size_t )nodes_old)));
91+ }
92+ }
8893}
8994
90- template <typename captype, typename tcaptype, typename flowtype>
91- void Graph<captype,tcaptype,flowtype>::reallocate_arcs()
92- {
93- int arc_num_max = (int )(arc_max - arcs);
94- int arc_num = (int )(arc_last - arcs);
95- arc* arcs_old = arcs;
96-
97- arc_num_max += arc_num_max / 2 ; if (arc_num_max & 1 ) arc_num_max ++;
98- arcs = (arc*) realloc (arcs_old, arc_num_max*sizeof (arc));
99- if (!arcs) { if (error_function) (*error_function)(" Not enough memory!" ); exit (1 ); }
100-
101- arc_last = arcs + arc_num;
102- arc_max = arcs + arc_num_max;
103-
104- if (arcs != arcs_old)
105- {
106- node* i;
107- arc* a;
108- for (i=nodes; i<node_last; i++)
109- {
110- if (i->first ) i->first = (arc*) ((char *)i->first + (((char *) arcs) - ((char *) arcs_old)));
111- if (i->parent && i->parent != ORPHAN && i->parent != TERMINAL) i->parent = (arc*) ((char *)i->parent + (((char *) arcs) - ((char *) arcs_old)));
112- }
113- for (a=arcs; a<arc_last; a++)
114- {
115- if (a->next ) a->next = (arc*) ((char *)a->next + (((char *) arcs) - ((char *) arcs_old)));
116- a->sister = (arc*) ((char *)a->sister + (((char *) arcs) - ((char *) arcs_old)));
117- }
118- }
95+ template <typename captype, typename tcaptype, typename flowtype>
96+ void Graph<captype, tcaptype, flowtype>::reallocate_arcs() {
97+ int arc_num_max = (int )(arc_max - arcs);
98+ int arc_num = (int )(arc_last - arcs);
99+ size_t arcs_old = (size_t )arcs;
100+
101+ arc_num_max += arc_num_max / 2 ;
102+ if (arc_num_max & 1 ) arc_num_max++;
103+ arcs = (arc*)realloc (arcs, arc_num_max * sizeof (arc));
104+ if (!arcs) {
105+ if (error_function) (*error_function)(" Not enough memory!" );
106+ exit (1 );
107+ }
108+
109+ arc_last = arcs + arc_num;
110+ arc_max = arcs + arc_num_max;
111+
112+ if ((size_t )arcs != arcs_old) {
113+ node* i;
114+ arc* a;
115+ for (i = nodes; i < node_last; i++) {
116+ if (i->first )
117+ i->first = (arc*)((size_t )i->first +
118+ (((size_t )arcs) - ((size_t )arcs_old)));
119+ if (i->parent && i->parent != ORPHAN &&
120+ i->parent != TERMINAL)
121+ i->parent = (arc*)((size_t )i->parent +
122+ (((size_t )arcs) - ((size_t )arcs_old)));
123+ }
124+ for (a = arcs; a < arc_last; a++) {
125+ if (a->next )
126+ a->next = (arc*)((size_t )a->next +
127+ (((size_t )arcs) - ((size_t )arcs_old)));
128+ a->sister = (arc*)((size_t )a->sister +
129+ (((size_t )arcs) - ((size_t )arcs_old)));
130+ }
131+ }
119132}
120133
121134#include " instances.inc"
0 commit comments