Closed wxmwy closed 3 years ago
Yeah, I think I see a problem, good catch! I made a little picture to walk through how the code should work: let me know if this makes sense.
The LRU flags correspond to branches in the tree structure, with a zero meaning 'go left' and a one meaning 'go right'.
It appears decoding the LRU for 6 and 7 are also correct.
To move a slot to the MRU, we want to set all of the flags along the path the opposite way. The easiest rule to do this is that: any bits that are ? in the top casez should be passed through (lru_flags) unaltered to update_flags, and any bits that are 1 or 0 in the top should be set to the opposite in update_flags, so:
In each case, it appears I mentally swapped bits 4 and 5 when updating the lru_flags, probably because I was visualizing walking the tree in my head and wrote the bits in traversal order rather than in strict horizontal order.
Thanks!
Yes, I understand now. Thank you for your reply.