-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnit.h
More file actions
121 lines (88 loc) · 2.53 KB
/
Copy pathUnit.h
File metadata and controls
121 lines (88 loc) · 2.53 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef UNIT_H
#define UNIT_H
#include<vector>
#include "Point.h"
#include<algorithm>
using namespace std;
class Unit{
public:
vector<Point*> Hosts;
vector<Point*> Points;
int Count;
Unit(Point* host){
Hosts.push_back(host);
Points = host->Parents;
Points.push_back(host);
std::sort(Points.begin(),Points.end(),SortByIDDesc);
Count = Points.size();
}
Unit(Unit* u1, Unit* u2){
vector<Point*>::iterator it1 = u1->Points.begin();
vector<Point*>::iterator it2 = u2->Points.begin();
Hosts = u1->Hosts;
Hosts.insert(Hosts.end(),u2->Hosts.begin(),u2->Hosts.end());
std::sort(Hosts.begin(),Hosts.end(),SortByIDAsc);
while(it1!= u1->Points.end() && it2 != u2->Points.end()){
if((*it1)->ID != (*it2)->ID){
if((*it1)->ID > (*it2)->ID){
Points.push_back(*it1);
it1++;
}else{
Points.push_back(*it2);
it2++;
}
}else{
Points.push_back(*it1);
it1++;
it2++;
}
}
while(it1!= u1->Points.end()){
Points.push_back(*it1);
it1++;
}
while(it2!= u2->Points.end()){
Points.push_back(*it2);
it2++;
}
Count = Points.size();
}
bool PointInUnit(vector<Point*> points){
bool exits = true;
for(vector<Point*>::iterator it = points.begin(); it != points.end(); it ++) {
if(exits)
exits = std::find(Points.begin(), Points.end(), *it) != Points.end();
}
return exits;
}
void printUnitGroup(){
cout<<" print UnitGroup:";
for(vector<Point*>::iterator it1 = Hosts.begin(); it1 != Hosts.end(); it1 ++) {
cout<<"Hosts name = "<<(*it1)->name<<" ";
}
cout<<endl;
}
bool equal(Unit *a)
{
bool flag = true;
flag = Count==a->Count;
if(flag){
flag = PointInUnit(a->Points);
}
return flag;
}
};
bool SortByCount( Unit*v1, Unit *v2)
{
bool flag = true;
if(v1->Count == v2->Count)
{
Point* point1 = v1->Hosts.front();
Point* point2 = v2->Hosts.front();
flag = point1->ID>point2->ID;
}else{
flag = v1->Count > v2->Count;
}
return flag;
}
#endif