-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.cpp
77 lines (53 loc) · 1.95 KB
/
build.cpp
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
/**
* Builds and save a Graph represented by
* a RePair WaveletTree. It loads a graph from
* Crawls/<graphname>/<graphname>.plain and use
* a fixed sampling rate for the RRR bitsequence
* on the wavelettree.
* */
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <BitSequenceBuilder.h>
#include <Mapper.h>
#include "RePairWaveletTreeBuilder.h"
#include "GraphSequence.h"
using namespace std;
int main (int argc, char **argv)
{
if(argc != 3) {
cout << "usage: " << argv[0] << " <graphname> <rrr_sample_rate>" << endl;
return 0;
}
string graphname(argv[1]);
uint sample_rate = transform(string(argv[2]));
printf(" [MSG] Building adjacency list\n");
string inputfile("Crawls/"+graphname+"/"+graphname+".plain");
ifstream ifs (inputfile.c_str(), ifstream::in);
uint nodes = loadValue<uint>(ifs); //First Int is the number of nodes
uint **adjacencyList = new uint*[nodes];
for(uint i = 0; i < nodes; ++i){
uint d = loadValue<uint>(ifs);
adjacencyList[i] = new uint[d+1];
adjacencyList[i][0] = d; //Outdegree before the neighbors
for(uint j = 1; j <= d; ++j){
uint v = loadValue<uint>(ifs); //The neighbors
adjacencyList[i][j] = v;
}
}
ifs.close();
printf(" [MSG] Building graph...\n");
BitSequenceBuilder *bsb = new BitSequenceBuilderRRR(sample_rate);
Mapper *mp = new MapperNone();
SequenceBuilder *sb = new RePairWaveletTreeBuilder(bsb, mp, true);
GraphSequence *graph = new GraphSequence(adjacencyList, nodes, sb, true);
size_t size = graph->getSize();
printf(" [SIZ] Total Size [bytes]: %u\n", size);
printf(" [SIZ] Total Size [MB]: %.2f\n", size/1024.0/1024);
printf(" [SIZ] Bits/Edge: %.2f\n", size*8.0/graph->edgesCount());
string outputfile("Crawls/"+graphname+"/"+graphname+".repair"+argv[2]);
ofstream ofs (outputfile.c_str(), ofstream::out);
graph->save(ofs);
}