11#include < iostream>
22#include < fstream>
33#include < vector>
4+ #include < errno.h>
5+ #include < string.h>
46#include < graph_zeppelin_common.h>
57
68int main (int argc, char **argv) {
7- if (argc != 2 && argc != 3 ) {
9+ if (argc < 3 || argc > 5 ) {
810 std::cout << " Incorrect number of arguments. "
9- " Expected at either one or two but got " << argc-1 << std::endl;
10- std::cout << " Arguments are: text_stream [update_type]" << std::endl;
11- std::cout << " text_stream is the file to parse into binary format" << std::endl;
12- std::cout << " update_type is a flag. If present then stream indicates insertions vs deletions" << std::endl;
11+ " Expected [2-4] but got " << argc-1 << std::endl;
12+ std::cout << " Arguments are: ascii_stream out_file_name [--update_type] [--verbose]" << std::endl;
13+ std::cout << " ascii_stream: The file to parse into binary format" << std::endl;
14+ std::cout << " out_file_name: Where the binary stream will be written" << std::endl;
15+ std::cout << " --update_type: If present then ascii stream indicates insertions vs deletions" << std::endl;
16+ std::cout << " --silent: If present then no warnings are printed when stream corrections are made" << std::endl;
17+ exit (EXIT_FAILURE);
1318 }
1419
1520 std::ifstream txt_file (argv[1 ]);
16- std::ofstream out_file (" binary_stream.data" , std::ios_base::binary);
21+ if (!txt_file) {
22+ std::cerr << " ERROR: could not open input file!" << std::endl;
23+ exit (EXIT_FAILURE);
24+ }
25+ std::ofstream out_file (argv[2 ], std::ios_base::binary | std::ios_base::out);
26+ if (!out_file) {
27+ std::cerr << " ERROR: could not open output file! " << argv[2 ] << " : " << strerror (errno) << std::endl;
28+ exit (EXIT_FAILURE);
29+ }
1730
1831 bool update_type = false ;
19- if (argc == 3 ) {
20- if (std::string (argv[2 ]) == " update_type" )
32+ bool silent = false ;
33+ for (int i = 3 ; i < argc; i++) {
34+ if (std::string (argv[i]) == " --update_type" )
2135 update_type = true ;
36+ else if (std::string (argv[i]) == " --silent" ) {
37+ silent = true ;
38+ }
2239 else {
23- std::cerr << " Did not recognize second argument! Expected 'update_type'" ;
40+ std::cerr << " Did not recognize argument: " << argv[i] << " Expected '-- update_type' or '--silent '" ;
2441 return EXIT_FAILURE;
2542 }
2643 }
@@ -29,6 +46,16 @@ int main(int argc, char **argv) {
2946 edge_id_t num_edges;
3047
3148 txt_file >> num_nodes >> num_edges;
49+
50+ std::cout << " Parsed ascii stream header. . ." << std::endl;
51+ std::cout << " Number of nodes: " << num_nodes << std::endl;
52+ std::cout << " Number of updates: " << num_edges << std::endl;
53+ if (update_type)
54+ std::cout << " Assuming that update format is: upd_type src dst" << std::endl;
55+ else
56+ std::cout << " Assuming that update format is: src dst" << std::endl;
57+
58+
3259 out_file.write ((char *) &num_nodes, sizeof (num_nodes));
3360 out_file.write ((char *) &num_edges, sizeof (num_edges));
3461
@@ -48,14 +75,14 @@ int main(int argc, char **argv) {
4875 txt_file >> src >> dst;
4976
5077 if (src > dst) {
51- if (u != adj_mat[dst][src - dst]) {
78+ if (!silent && u != adj_mat[dst][src - dst]) {
5279 std::cout << " WARNING: update " << u << " " << src << " " << dst;
5380 std::cout << " is double insert or delete before insert. Correcting." << std::endl;
5481 }
5582 u = adj_mat[dst][src - dst];
5683 adj_mat[dst][src - dst] = !adj_mat[dst][src - dst];
5784 } else {
58- if (u != adj_mat[src][dst - src]) {
85+ if (!silent && u != adj_mat[src][dst - src]) {
5986 std::cout << " WARNING: update " << u << " " << src << " " << dst;
6087 std::cout << " is double insert or delete before insert. Correcting." << std::endl;
6188 }
@@ -68,3 +95,4 @@ int main(int argc, char **argv) {
6895 out_file.write ((char *) &dst, sizeof (dst));
6996 }
7097}
98+
0 commit comments