Skip to content

Commit b2c9724

Browse files
Remove all malloc and new
1 parent 78a80da commit b2c9724

25 files changed

+18093
-465
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.o
22
bliss
33
*.a
4+
*.lo

bignum.hh

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/*
55
Copyright (c) 2003-2015 Tommi Junttila
66
Released under the GNU Lesser General Public License version 3.
7-
7+
88
This file is part of bliss.
9-
9+
1010
bliss is free software: you can redistribute it and/or modify
1111
it under the terms of the GNU Lesser General Public License as published by
1212
the Free Software Foundation, version 3 of the License.
@@ -28,7 +28,7 @@
2828
#include <cstdio>
2929
#include "defs.hh"
3030

31-
namespace bliss {
31+
namespace bliss_digraphs {
3232

3333
/**
3434
* \brief A very simple class for big integers (or approximation of them).
@@ -100,6 +100,6 @@ public:
100100

101101
#endif
102102

103-
} //namespace bliss
103+
} //namespace bliss_digraphs
104104

105105
#endif

bliss.cc

+34-33
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
/*
1111
Copyright (c) 2003-2015 Tommi Junttila
1212
Released under the GNU Lesser General Public License version 3.
13-
13+
1414
This file is part of bliss.
15-
15+
1616
bliss is free software: you can redistribute it and/or modify
1717
it under the terms of the GNU Lesser General Public License as published by
1818
the Free Software Foundation, version 3 of the License.
@@ -52,13 +52,14 @@ static void
5252
usage(FILE* const fp, const char* argv0)
5353
{
5454
const char* program_name;
55-
55+
5656
program_name = rindex(argv0, '/');
57-
57+
5858
if(program_name) program_name++;
59-
else program_name = argv0;
59+
else program_name = argv0;
6060
if(!program_name or *program_name == 0) program_name = "bliss";
6161

62+
fprintf(fp, "bliss version %s (compiled "__DATE__")\n", bliss_digraphs::version);
6263
fprintf(fp, "Copyright 2003-2015 Tommi Junttila\n");
6364
fprintf(fp,
6465
"\n"
@@ -119,7 +120,7 @@ parse_options(const int argc, const char** argv)
119120
}
120121
else if(strcmp(argv[i], "-version") == 0)
121122
{
122-
fprintf(stdout, "bliss version %s\n", bliss::version);
123+
fprintf(stdout, "bliss version %s\n", bliss_digraphs::version);
123124
exit(0);
124125
}
125126
else if(strcmp(argv[i], "-help") == 0)
@@ -160,7 +161,7 @@ report_aut(void* param, const unsigned int n, const unsigned int* aut)
160161
{
161162
assert(param);
162163
fprintf((FILE*)param, "Generator: ");
163-
bliss::print_permutation((FILE*)param, n, aut, 1);
164+
bliss_digraphs::print_permutation((FILE*)param, n, aut, 1);
164165
fprintf((FILE*)param, "\n");
165166
}
166167

@@ -182,45 +183,45 @@ _fatal(const char* fmt, ...)
182183
int
183184
main(const int argc, const char** argv)
184185
{
185-
bliss::Timer timer;
186-
bliss::AbstractGraph* g = 0;
186+
bliss_digraphs::Timer timer;
187+
bliss_digraphs::AbstractGraph* g = 0;
187188

188189
parse_options(argc, argv);
189-
190+
190191
/* Parse splitting heuristics */
191-
bliss::Digraph::SplittingHeuristic shs_directed = bliss::Digraph::shs_fsm;
192-
bliss::Graph::SplittingHeuristic shs_undirected = bliss::Graph::shs_fsm;
192+
bliss_digraphs::Digraph::SplittingHeuristic shs_directed = bliss_digraphs::Digraph::shs_fsm;
193+
bliss_digraphs::Graph::SplittingHeuristic shs_undirected = bliss_digraphs::Graph::shs_fsm;
193194
if(opt_directed)
194195
{
195196
if(strcmp(opt_splitting_heuristics, "f") == 0)
196-
shs_directed = bliss::Digraph::shs_f;
197+
shs_directed = bliss_digraphs::Digraph::shs_f;
197198
else if(strcmp(opt_splitting_heuristics, "fs") == 0)
198-
shs_directed = bliss::Digraph::shs_fs;
199+
shs_directed = bliss_digraphs::Digraph::shs_fs;
199200
else if(strcmp(opt_splitting_heuristics, "fl") == 0)
200-
shs_directed = bliss::Digraph::shs_fl;
201+
shs_directed = bliss_digraphs::Digraph::shs_fl;
201202
else if(strcmp(opt_splitting_heuristics, "fm") == 0)
202-
shs_directed = bliss::Digraph::shs_fm;
203+
shs_directed = bliss_digraphs::Digraph::shs_fm;
203204
else if(strcmp(opt_splitting_heuristics, "fsm") == 0)
204-
shs_directed = bliss::Digraph::shs_fsm;
205+
shs_directed = bliss_digraphs::Digraph::shs_fsm;
205206
else if(strcmp(opt_splitting_heuristics, "flm") == 0)
206-
shs_directed = bliss::Digraph::shs_flm;
207+
shs_directed = bliss_digraphs::Digraph::shs_flm;
207208
else
208209
_fatal("Illegal option -sh=%s, aborting", opt_splitting_heuristics);
209210
}
210211
else
211212
{
212213
if(strcmp(opt_splitting_heuristics, "f") == 0)
213-
shs_undirected = bliss::Graph::shs_f;
214+
shs_undirected = bliss_digraphs::Graph::shs_f;
214215
else if(strcmp(opt_splitting_heuristics, "fs") == 0)
215-
shs_undirected = bliss::Graph::shs_fs;
216+
shs_undirected = bliss_digraphs::Graph::shs_fs;
216217
else if(strcmp(opt_splitting_heuristics, "fl") == 0)
217-
shs_undirected = bliss::Graph::shs_fl;
218+
shs_undirected = bliss_digraphs::Graph::shs_fl;
218219
else if(strcmp(opt_splitting_heuristics, "fm") == 0)
219-
shs_undirected = bliss::Graph::shs_fm;
220+
shs_undirected = bliss_digraphs::Graph::shs_fm;
220221
else if(strcmp(opt_splitting_heuristics, "fsm") == 0)
221-
shs_undirected = bliss::Graph::shs_fsm;
222+
shs_undirected = bliss_digraphs::Graph::shs_fsm;
222223
else if(strcmp(opt_splitting_heuristics, "flm") == 0)
223-
shs_undirected = bliss::Graph::shs_flm;
224+
shs_undirected = bliss_digraphs::Graph::shs_flm;
224225
else
225226
_fatal("Illegal option -sh=%s, aborting", opt_splitting_heuristics);
226227
}
@@ -238,34 +239,34 @@ main(const int argc, const char** argv)
238239
if(opt_directed)
239240
{
240241
/* Read directed graph in the DIMACS format */
241-
g = bliss::Digraph::read_dimacs(infile);
242+
g = bliss_digraphs::Digraph::read_dimacs(infile);
242243
}
243244
else
244245
{
245246
/* Read undirected graph in the DIMACS format */
246-
g = bliss::Graph::read_dimacs(infile);
247+
g = bliss_digraphs::Graph::read_dimacs(infile);
247248
}
248-
249+
249250
if(infile != stdin)
250251
fclose(infile);
251252

252253
if(!g)
253254
_fatal("Failed to read the graph, aborting");
254-
255+
255256
if(verbose_level >= 2)
256257
{
257258
fprintf(verbstr, "Graph read in %.2f seconds\n", timer.get_duration());
258259
fflush(verbstr);
259260
}
260261

261262

262-
bliss::Stats stats;
263+
bliss_digraphs::Stats stats;
263264

264265
/* Set splitting heuristics and verbose level */
265266
if(opt_directed)
266-
((bliss::Digraph*)g)->set_splitting_heuristic(shs_directed);
267+
((bliss_digraphs::Digraph*)g)->set_splitting_heuristic(shs_directed);
267268
else
268-
((bliss::Graph*)g)->set_splitting_heuristic(shs_undirected);
269+
((bliss_digraphs::Graph*)g)->set_splitting_heuristic(shs_undirected);
269270
g->set_verbose_level(verbose_level);
270271
g->set_verbose_file(verbstr);
271272
g->set_failure_recording(opt_use_failure_recording);
@@ -283,12 +284,12 @@ main(const int argc, const char** argv)
283284
const unsigned int* cl = g->canonical_form(stats, &report_aut, stdout);
284285

285286
fprintf(stdout, "Canonical labeling: ");
286-
bliss::print_permutation(stdout, g->get_nof_vertices(), cl, 1);
287+
bliss_digraphs::print_permutation(stdout, g->get_nof_vertices(), cl, 1);
287288
fprintf(stdout, "\n");
288289

289290
if(opt_output_can_file)
290291
{
291-
bliss::AbstractGraph* cf = g->permute(cl);
292+
bliss_digraphs::AbstractGraph* cf = g->permute(cl);
292293
FILE* const fp = fopen(opt_output_can_file, "w");
293294
if(!fp)
294295
_fatal("Cannot open '%s' for outputting the canonical form, aborting", opt_output_can_file);

bliss_C.cc

+39-22
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,59 @@ extern "C" {
2525
along with bliss. If not, see <http://www.gnu.org/licenses/>.
2626
*/
2727

28-
struct bliss_graph_struct {
29-
bliss::Graph* g;
28+
struct bliss_digraphs_graph_struct {
29+
bliss_digraphs::Graph* g;
3030
};
3131

3232
extern "C"
33-
BlissGraph *bliss_new(const unsigned int n)
33+
BlissGraph *bliss_digraphs_new(const unsigned int n)
3434
{
35-
BlissGraph *graph = new bliss_graph_struct;
35+
BlissGraph *graph = new bliss_digraphs_graph_struct;
3636
assert(graph);
37-
graph->g = new bliss::Graph(n);
37+
graph->g = new bliss_digraphs::Graph(n);
3838
assert(graph->g);
3939
return graph;
4040
}
4141

4242
extern "C"
43-
BlissGraph *bliss_read_dimacs(FILE *fp)
43+
BlissGraph *bliss_digraphs_read_dimacs(FILE *fp)
4444
{
45-
bliss::Graph *g = bliss::Graph::read_dimacs(fp);
45+
bliss_digraphs::Graph *g = bliss_digraphs::Graph::read_dimacs(fp);
4646
if(!g)
4747
return 0;
48-
BlissGraph *graph = new bliss_graph_struct;
48+
BlissGraph *graph = new bliss_digraphs_graph_struct;
4949
assert(graph);
5050
graph->g = g;
5151
return graph;
5252
}
5353

5454
extern "C"
55-
void bliss_write_dimacs(BlissGraph *graph, FILE *fp)
55+
void bliss_digraphs_write_dimacs(BlissGraph *graph, FILE *fp)
5656
{
5757
assert(graph);
5858
assert(graph->g);
5959
graph->g->write_dimacs(fp);
6060
}
6161

6262
extern "C"
63-
void bliss_release(BlissGraph *graph)
63+
void bliss_digraphs_clear(BlissGraph *graph)
64+
{
65+
assert(graph);
66+
assert(graph->g);
67+
graph->g->clear();
68+
}
69+
70+
extern "C"
71+
void bliss_digraphs_change_color(BlissGraph* graph, const unsigned int vertex, const unsigned int color)
72+
{
73+
assert(graph);
74+
assert(graph->g);
75+
graph->g->change_color(vertex, color);
76+
}
77+
78+
79+
extern "C"
80+
void bliss_digraphs_release(BlissGraph *graph)
6481
{
6582
assert(graph);
6683
assert(graph->g);
@@ -69,39 +86,39 @@ void bliss_release(BlissGraph *graph)
6986
}
7087

7188
extern "C"
72-
void bliss_write_dot(BlissGraph *graph, FILE *fp)
89+
void bliss_digraphs_write_dot(BlissGraph *graph, FILE *fp)
7390
{
7491
assert(graph);
7592
assert(graph->g);
7693
graph->g->write_dot(fp);
7794
}
7895

7996
extern "C"
80-
unsigned int bliss_get_nof_vertices(BlissGraph *graph)
97+
unsigned int bliss_digraphs_get_nof_vertices(BlissGraph *graph)
8198
{
8299
assert(graph);
83100
assert(graph->g);
84101
return graph->g->get_nof_vertices();
85102
}
86103

87104
extern "C"
88-
unsigned int bliss_add_vertex(BlissGraph *graph, unsigned int l)
105+
unsigned int bliss_digraphs_add_vertex(BlissGraph *graph, unsigned int l)
89106
{
90107
assert(graph);
91108
assert(graph->g);
92109
return graph->g->add_vertex(l);
93110
}
94111

95112
extern "C"
96-
void bliss_add_edge(BlissGraph *graph, unsigned int v1, unsigned int v2)
113+
void bliss_digraphs_add_edge(BlissGraph *graph, unsigned int v1, unsigned int v2)
97114
{
98115
assert(graph);
99116
assert(graph->g);
100117
graph->g->add_edge(v1, v2);
101118
}
102119

103120
extern "C"
104-
int bliss_cmp(BlissGraph *graph1, BlissGraph *graph2)
121+
int bliss_digraphs_cmp(BlissGraph *graph1, BlissGraph *graph2)
105122
{
106123
assert(graph1);
107124
assert(graph1->g);
@@ -111,35 +128,35 @@ int bliss_cmp(BlissGraph *graph1, BlissGraph *graph2)
111128
}
112129

113130
extern "C"
114-
unsigned int bliss_hash(BlissGraph *graph)
131+
unsigned int bliss_digraphs_hash(BlissGraph *graph)
115132
{
116133
assert(graph);
117134
assert(graph->g);
118135
return graph->g->get_hash();
119136
}
120137

121138
extern "C"
122-
BlissGraph *bliss_permute(BlissGraph *graph, const unsigned int *perm)
139+
BlissGraph *bliss_digraphs_permute(BlissGraph *graph, const unsigned int *perm)
123140
{
124141
assert(graph);
125142
assert(graph->g);
126143
assert(graph->g->get_nof_vertices() == 0 || perm);
127-
BlissGraph *permuted_graph = new bliss_graph_struct;
144+
BlissGraph *permuted_graph = new bliss_digraphs_graph_struct;
128145
assert(permuted_graph);
129146
permuted_graph->g = graph->g->permute(perm);
130147
return permuted_graph;
131148
}
132149

133150
extern "C"
134151
void
135-
bliss_find_automorphisms(BlissGraph *graph,
152+
bliss_digraphs_find_automorphisms(BlissGraph *graph,
136153
void (*hook)(void *user_param,
137154
unsigned int n,
138155
const unsigned int *aut),
139156
void *hook_user_param,
140157
BlissStats *stats)
141158
{
142-
bliss::Stats s;
159+
bliss_digraphs::Stats s;
143160
assert(graph);
144161
assert(graph->g);
145162
graph->g->find_automorphisms(s, hook, hook_user_param);
@@ -159,14 +176,14 @@ bliss_find_automorphisms(BlissGraph *graph,
159176

160177
extern "C"
161178
const unsigned int *
162-
bliss_find_canonical_labeling(BlissGraph *graph,
179+
bliss_digraphs_find_canonical_labeling(BlissGraph *graph,
163180
void (*hook)(void *user_param,
164181
unsigned int n,
165182
const unsigned int *aut),
166183
void *hook_user_param,
167184
BlissStats *stats)
168185
{
169-
bliss::Stats s;
186+
bliss_digraphs::Stats s;
170187
const unsigned int *canonical_labeling = 0;
171188
assert(graph);
172189
assert(graph->g);

0 commit comments

Comments
 (0)