-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
68 lines (51 loc) · 1.38 KB
/
Copy pathparser.h
File metadata and controls
68 lines (51 loc) · 1.38 KB
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
//
// Created by kostas on 4/24/18.
//
#ifndef QMAXRTC_PARSER_H
#define QMAXRTC_PARSER_H
#include "common.h"
#include <set>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
/*
*
* parse a file containing triplets, assume that each line contains three numbers x y z for the triplet xy|z.
* No restriction on the numbers for the leaf labels, 32 bit integers should be OK.
* no triplets of the form xx|z, xy|x, xx|x are allowed in the input => undefined behaviour.
*
*/
void parse(const char* file, vector<triplet>& R, int& n){
ifstream fin;
fin.open(file, ios_base::in);
n = 0;
triplet t;
while(fin >> t.x >> t.y >> t.z){
R.push_back(t);
if(mapInNew.find(t.x) == mapInNew.end()){
mapInNew[t.x] = n++;
}
if(mapInNew.find(t.y) == mapInNew.end()){
mapInNew[t.y] = n++;
}
if(mapInNew.find(t.z) == mapInNew.end()){
mapInNew[t.z] = n++;
}
}
fin.close();
mapNewIn.resize(n);
map<int, int>::iterator it = mapInNew.begin();
while(it!=mapInNew.end()){
mapNewIn[it->second] = it->first;
it++;
}
int i;
for(i=0;i<R.size();i++){
R[i].x = mapInNew[R[i].x];
R[i].y = mapInNew[R[i].y];
if (R[i].x > R[i].y) swap(R[i].x, R[i].y);
R[i].z = mapInNew[R[i].z];
}
}
#endif //QMAXRTC_PARSER_H