Fixes test 4

This commit is contained in:
Isaac Shoebottom 2023-12-02 21:31:15 -04:00
parent 7d4ecdaba6
commit 06b028bfb2

View File

@ -25,6 +25,11 @@ double timeToProcessRequest(int position, int destination) {
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.
// In first come first the time the request comes in is irrelevant
@ -34,7 +39,7 @@ void fcfs(int start) {
DiskRequest request = dequeue(queue);
while (seekTime < request.time) { seekTime++; }
seekTime += timeToProcessRequest(position, request.position);
movement += abs(position - request.position);
movement += diskMovement(position, request.position);
position = request.position;
}
}
@ -47,18 +52,24 @@ void cscan(int start) {
if (request == NULL) {
seekTime++;
} else {
// There is a bug here, will need to revisit
if (request->position < position) {
//seekTime += timeToProcessRequest(position, 9999);
//seekTime += timeToProcessRequest(9999, 0);
//movement += abs(position - 9999);
//movement += abs(9999 - 0);
seekTime += timeToProcessRequest(position, 9999);
movement += diskMovement(position, 9999);
// Special case for when we are at the end of the disk, wrap around to the beginning
seekTime += timeToProcessRequest(9999, 10000); // 10000 is the beginning of the disk
movement += diskMovement(9999, 10000);
position = 0;
// Rescan for closest, so we can efficiently handle requests
request = findClosest(queue, position, seekTime);
}
seekTime += timeToProcessRequest(position, request->position);
movement += abs(position - request->position);
movement += diskMovement(position, request->position);
position = request->position;
}
if (request != NULL) {
delete(queue, *request);
}
//printf("Movement: %i Time:%.1lf\n", movement, seekTime);
}
}