COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
renamer.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3#include <fstream>
4#include <sstream>
5#include <vector>
6#include <algorithm>
7#include <chrono>
8#include <functional>
9#include <cmath>
10#include <boost/algorithm/string.hpp>
11#include <map>
12#include <tuple>
13#include <cstdlib>
14#include <cstdio>
15#include <limits>
16#include <omp.h>
17
18using namespace std;
19
20int main(int argc, char* argv[])
21{
22 if(argc < 2)
23 {
24 cout << "Usage: ./renamer <input>" << endl;
25 return 0;
26 }
27 ifstream input1(argv[1], ifstream::in);
28 map<string, int> vertexmap;
29 int vertexid = 0;
30
31 string name = "Renamed_";
32 name += string(argv[1]);
33 ofstream out(name);
34
35 string locline;
36 int numlines = 0;
37 while(getline(input1,locline))
38 {
39 std::tuple<int64_t, int64_t, string> triple; // the third entry is a float, but that doesn't matter here
40 vector<string> strs;
41 boost::split(strs, locline, boost::is_any_of("\t "));
42
43 auto ret = vertexmap.insert(make_pair(strs[0], vertexid));
44 if (ret.second) // successfully inserted
45 ++vertexid;
46
47 // map::insert returns a pair, with its member pair::first set to an
48 // iterator pointing to either the newly inserted element or to the element with an equivalent key in the map
49
50 get<0>(triple) = ret.first->second;
51
52 ret = vertexmap.insert(make_pair(strs[1], vertexid));
53 if (ret.second) ++vertexid;
54
55 get<1>(triple) = ret.first->second;
56 get<2>(triple) = strs[2];
57 numlines++;
58
59 out << get<0>(triple) << "\t" << get<1>(triple) << "\t" << get<2>(triple) << "\n";
60 }
61 out.close();
62 string dictname = "Vertex_Dict_";
63 dictname += string(argv[1]);
64 ofstream dictout(dictname);
65 int max = 0;
66 for (auto it = vertexmap.begin(); it != vertexmap.end(); ++it)
67 {
68 max = std::max(max, it->second);
69 dictout << it->second << "\t" << it ->first << endl;
70 }
71 cout << (max+1) << "\t" << (max+1) << "\t" << numlines << endl;
72 dictout.close();
73}
int main()
Definition Driver.cpp:12
uint32_t numlines
map< string, int > vertexmap