-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
98 lines (78 loc) · 2.07 KB
/
Copy pathutil.cpp
File metadata and controls
98 lines (78 loc) · 2.07 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <memory>
#include <tuple>
#include "node.h"
#include "record.h"
#include "edge.h"
void split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
std::vector<std::string> splitDomain(std::string domain) {
std::vector<std::string> zones;
zones = split(domain, '.');
std::reverse(zones.begin(), zones.end());
return zones;
}
std::string concatDomain(std::vector<std::string> domain) {
std::string s;
for (std::vector<std::string>::const_iterator i = domain.begin(); i != domain.end(); ++i) {
s += *i;
s += "|";
}
s = s.substr(0, s.size() - 1);
return s;
}
int compareFunc(std::string a, std::string b, int index) {
int len;
// std::cout << "We are comparing " << a << " and " << b << " from index " << index << std::endl;
len = std::min(a.length(), b.length());
int j = 0;
for (int i = index; i < len; i++) {
if (a[i] == b[i]) {
j++;
continue;
} else {
if (j > 0) {
// std::cout << "Returning " << j + index << std::endl;
return j + index;
} else {
return 0;
}
}
}
return len;
}
std::tuple<int, int> findBestMatch(std::vector<std::unique_ptr<Edge>> const &v, std::string l, int index) {
int pos = -1;
int currMax = 0;
for (std::vector<std::unique_ptr<Edge>>::const_iterator it = v.begin(); it != v.end(); it++) {
std::string currLabel = (*it)->getLabel();
int comp = compareFunc(currLabel, l, index);
if (comp > currMax) {
currMax = comp;
// std::cout << "currmax is " << currMax << std::endl;
pos = it - v.begin();
}
}
// std::cout << "I'm returning " << pos << std::endl;
return std::make_tuple(currMax, pos);
}
//std::string longestCommonSubstring(std::vector<std::unique_ptr<Edge>> const &v) {
//
//}