forked from tien-huynh/NemoMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mapping.cpp
99 lines (82 loc) · 1.96 KB
/
Mapping.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Filename: Mapping.cpp
Description: Implementation of a class representing the mapping of vertices between two graphs
******NOTE******: no longer needed with current implementation
Author: Tien Huynh
*/
#include "Mapping.h"
ParaMODAImpl::Mapping::Mapping()
{
this->Id = -1;
}
ParaMODAImpl::Mapping::Mapping(const Mapping & mapping)
{
this->Id = mapping.Id;
this->SubGraphEdgeCount = mapping.SubGraphEdgeCount;
this->Function = mapping.Function;
}
ParaMODAImpl::Mapping::Mapping(tsl::hopscotch_map<int, int> function)
{
this->Id = -1;
this->Function = function;
}
ParaMODAImpl::Mapping::~Mapping()
{
}
//Overload equal operator for comparing Mapping objects
// all <key,value> pairs must be the same in both objects
bool ParaMODAImpl::Mapping::operator==(const Mapping & other) const
{
if (this->Id >= 0 || other.Id >= 0)
return this->Id == other.Id;
if (this->Function.size() != other.Function.size())
return false;
for (auto const& itr : this->Function)
{
try
{
if (itr.second != other.getFunction().at(itr.first))
return false;
}
catch (out_of_range)
{
return false;
}
}
return true;
}
string ParaMODAImpl::Mapping::GetMappedNodes()
{
string result = "";
if (this->Function.size())
{
tsl::hopscotch_map<int, int>::iterator itr = this->Function.begin();
result += to_string((itr++)->second);
for (; itr != this->Function.end(); itr++)
{
result += '-' + to_string(itr->second);
}
}
return result;
}
//overload output operators
ostream & ParaMODAImpl::operator<<(ostream & outStream, const Mapping & data)
{
string h = "";
string g = "";
if (data.getFunction().size())
{
h += "[";
g += " => [";
for (auto const& itr : data.getFunction())
{
h += to_string(itr.first) + '-';
g += to_string(itr.second) + '-';
}
h.pop_back();
h += "]";
g.pop_back();
g += "]\n";
}
outStream << h << g;
return outStream;
}