Clock Page Replacement
Clock Page Replacement
Simulate the clock (second-chance) page replacement algorithm.
Function
func ClockSim(frames int, accesses []int) (faults int, final []int)
Rules
framesis the number of physical frames.accessesis the sequence of page numbers.- Use a circular clock hand starting at index 0.
- On hit: set reference bit to 1.
- On miss:
- If the current hand points to an empty frame, use it.
- Otherwise, advance hand while ref bit is 1, clearing each to 0.
- Replace the first frame with ref bit 0.
- After inserting a page, set its ref bit to 1 and advance hand by 1.
Output
Return the number of page faults and the final frame contents. Empty frames should be -1.
Run tests to see results
No issues detected