9
9
* @author [Daemon19](https://github.com/Daemon19)
10
10
*/
11
11
12
- #include < iomanip > // / For formatting process results output
13
- #include < cassert> // / For testing the round-robin algorithm
14
- #include < string > // / For converting int type to string
15
- #include < iostream> // / For outputting process execution results
16
- #include < queue> // / Container for process execution turn
17
- #include < set> // / Container for processes that have arrived
18
- #include < utility > // / So I can use std::pair
19
- #include < vector > // / Container for processes that will be executed
20
- #include < algorithm > // / So I can use std::sort
12
+ #include < algorithm > // / So I can use std::sort
13
+ #include < cassert> // / For testing the round-robin algorithm
14
+ #include < iomanip > // / For formatting process results output
15
+ #include < iostream> // / For outputting process execution results
16
+ #include < queue> // / Container for process execution turn
17
+ #include < set> // / Container for processes that have arrived
18
+ #include < string > // / For converting int type to string
19
+ #include < utility > // / So I can use std::pair
20
+ #include < vector > // / Container for processes that will be executed
21
21
22
22
/* *
23
23
* @brief Represent a process to be executed.
@@ -32,8 +32,10 @@ struct Process {
32
32
* @brief Represent the result of a process execution.
33
33
*/
34
34
struct ProcessResult : public Process {
35
- uint32_t completion_time; // /< The time at which the process execution is finished
36
- uint32_t turn_around_time; // /< The turn around time required for the process to complete
35
+ uint32_t completion_time; // /< The time at which the process execution is
36
+ // /< finished
37
+ uint32_t turn_around_time; // /< The turn around time required for the
38
+ // /< process to complete
37
39
uint32_t waiting_time; // /< Process waiting time before execution
38
40
39
41
/* *
@@ -95,7 +97,6 @@ std::ostream& operator<<(std::ostream& ostream,
95
97
*/
96
98
static void Test ();
97
99
98
-
99
100
/* *
100
101
* @brief Comparator function for sorting processes.
101
102
*
@@ -170,10 +171,10 @@ std::vector<ProcessResult> RRExecute(const std::vector<Process>& processes,
170
171
171
172
// The time of the first process execution will be the lowest process AT
172
173
uint32_t time_elapsed =
173
- std::min_element (processes.begin (), processes.end (), CompareAT)->arrival_time ;
174
+ std::min_element (processes.begin (), processes.end (), CompareAT)
175
+ ->arrival_time ;
174
176
175
- CheckArriveProcess (processes, &arrived_processes, &schedule,
176
- time_elapsed);
177
+ CheckArriveProcess (processes, &arrived_processes, &schedule, time_elapsed);
177
178
178
179
while (!schedule.empty ()) {
179
180
std::pair<Process, BTLeft> current = schedule.front ();
@@ -184,14 +185,14 @@ std::vector<ProcessResult> RRExecute(const std::vector<Process>& processes,
184
185
// quantum/slice
185
186
uint32_t elapsed =
186
187
(current.second > time_slice) ? time_slice : current.second ;
187
- current.second -= elapsed;
188
- time_elapsed += elapsed;
188
+ current.second -= elapsed;
189
+ time_elapsed += elapsed;
189
190
190
- CheckArriveProcess (processes, &arrived_processes, &schedule,
191
- time_elapsed);
191
+ CheckArriveProcess (processes, &arrived_processes, &schedule,
192
+ time_elapsed);
192
193
193
194
if (current.second > 0 ) {
194
- schedule.push (current);
195
+ schedule.push (current);
195
196
continue ;
196
197
}
197
198
// Generate process result based on the completion time (time
@@ -204,7 +205,7 @@ std::vector<ProcessResult> RRExecute(const std::vector<Process>& processes,
204
205
205
206
std::ostream& operator <<(std::ostream& ostream,
206
207
const std::vector<ProcessResult>& results) {
207
- auto PrintCell = [&](const std::string & str) {
208
+ auto PrintCell = [&](const std::string& str) {
208
209
ostream << std::setw (17 ) << std::left << str;
209
210
};
210
211
@@ -232,7 +233,7 @@ std::ostream& operator<<(std::ostream& ostream,
232
233
return ostream;
233
234
}
234
235
235
- void CheckArriveProcess (const std::vector<Process> & processes,
236
+ void CheckArriveProcess (const std::vector<Process>& processes,
236
237
std::set<uint32_t >* arrived_process,
237
238
std::queue<std::pair<Process, BTLeft>>* schedule,
238
239
uint32_t time_elapsed) {
0 commit comments