Fixes test 4
This commit is contained in:
parent
7d4ecdaba6
commit
06b028bfb2
@ -25,6 +25,11 @@ double timeToProcessRequest(int position, int destination) {
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int diskMovement(int position, int destination) {
|
||||||
|
int distance = destination - position;
|
||||||
|
return abs(distance);
|
||||||
|
}
|
||||||
|
|
||||||
// Your simulated disk is of size 10000, numbered from 0 to 9999.
|
// Your simulated disk is of size 10000, numbered from 0 to 9999.
|
||||||
|
|
||||||
// In first come first the time the request comes in is irrelevant
|
// In first come first the time the request comes in is irrelevant
|
||||||
@ -34,7 +39,7 @@ void fcfs(int start) {
|
|||||||
DiskRequest request = dequeue(queue);
|
DiskRequest request = dequeue(queue);
|
||||||
while (seekTime < request.time) { seekTime++; }
|
while (seekTime < request.time) { seekTime++; }
|
||||||
seekTime += timeToProcessRequest(position, request.position);
|
seekTime += timeToProcessRequest(position, request.position);
|
||||||
movement += abs(position - request.position);
|
movement += diskMovement(position, request.position);
|
||||||
position = request.position;
|
position = request.position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,18 +52,24 @@ void cscan(int start) {
|
|||||||
if (request == NULL) {
|
if (request == NULL) {
|
||||||
seekTime++;
|
seekTime++;
|
||||||
} else {
|
} else {
|
||||||
// There is a bug here, will need to revisit
|
|
||||||
if (request->position < position) {
|
if (request->position < position) {
|
||||||
//seekTime += timeToProcessRequest(position, 9999);
|
seekTime += timeToProcessRequest(position, 9999);
|
||||||
//seekTime += timeToProcessRequest(9999, 0);
|
movement += diskMovement(position, 9999);
|
||||||
//movement += abs(position - 9999);
|
// Special case for when we are at the end of the disk, wrap around to the beginning
|
||||||
//movement += abs(9999 - 0);
|
seekTime += timeToProcessRequest(9999, 10000); // 10000 is the beginning of the disk
|
||||||
|
movement += diskMovement(9999, 10000);
|
||||||
position = 0;
|
position = 0;
|
||||||
|
// Rescan for closest, so we can efficiently handle requests
|
||||||
|
request = findClosest(queue, position, seekTime);
|
||||||
}
|
}
|
||||||
seekTime += timeToProcessRequest(position, request->position);
|
seekTime += timeToProcessRequest(position, request->position);
|
||||||
movement += abs(position - request->position);
|
movement += diskMovement(position, request->position);
|
||||||
position = request->position;
|
position = request->position;
|
||||||
}
|
}
|
||||||
|
if (request != NULL) {
|
||||||
|
delete(queue, *request);
|
||||||
|
}
|
||||||
|
//printf("Movement: %i Time:%.1lf\n", movement, seekTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user