-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathselectionrule.cpp
77 lines (58 loc) · 1.12 KB
/
selectionrule.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
#include "selectionrule.hpp"
using namespace std;
void HighestLevelRule::gap(int h) {
highest = h - 1;
updateHighest();
}
void HighestLevelRule::updateHighest(void) {
int s = highest;
highest = -1;
for (int i = s; i >= 0; --i) {
if (hq[i].size() > 0) {
highest = i;
break;
}
}
}
bool HighestLevelRule::empty(void) {
return highest < 0;
}
int HighestLevelRule::next(void) {
if (empty()) throw EmptyQueueException();
int u = hq[highest].front();
hq[highest].pop();
deactivate(u);
updateHighest();
return u;
}
void HighestLevelRule::add(int u, int height, int excess) {
if (isActive(u)) return;
if (height >= N) return;
if (excess == 0) return;
hq[height].push(u);
if (height > highest) highest = height;
}
void FIFORule::gap(int h) {
}
int FIFORule::next(void) {
int u;
if (!q.empty()) {
u = q.front();
q.pop();
deactivate(u);
}
else {
throw EmptyQueueException();
}
return u;
}
void FIFORule::add(int u, int height, int excess) {
if (isActive(u)) return;
if (height >= N) return;
if (excess == 0) return;
activate(u);
q.push(u);
}
bool FIFORule::empty(void) {
return q.empty();
}