-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrioridad.cc
More file actions
executable file
·62 lines (48 loc) · 1.36 KB
/
Prioridad.cc
File metadata and controls
executable file
·62 lines (48 loc) · 1.36 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
#include "Prioridad.hh"
using namespace std;
// Constructoras
Prioridad::Prioridad() {
send_data.first = send_data.second = 0;
}
// Modificadoras
void Prioridad::add_proceso(const Proceso& p) {
proc_age.emplace_back(p.consultar_PID());
procesos.emplace(p.consultar_PID(), p);
}
void Prioridad::send_proceso(int &num, Cluster &c) {
if (not proc_age.empty()) {
auto it = proc_age.begin();
int max_size = proc_age.size();
int index = 0;
while(not (num == 0 or index == max_size)) {
if (c.add_proc_ep(procesos.at(*it))) {
++send_data.first;
procesos.erase(*it);
it = proc_age.erase(it);
--num;
}
else {
proc_age.emplace_back(*it);
it = proc_age.erase(it);
++send_data.second;
}
++index;
}
}
}
// Consultoras
bool Prioridad::empty() const {
return (procesos.size() == 0);
}
bool Prioridad::existe_proceso(int ID) const {
return (not procesos.empty() and procesos.count(ID) != 0);
}
// Lectura y escritura
void Prioridad::print_procesos() const {
for (int id : proc_age) {
procesos.at(id).imprimir_proceso();
}
}
void Prioridad::enviados_rechazados() const{
cout << send_data.first << " " << send_data.second << endl;
}