Hacker News new | ask | show | jobs
by Epa095 897 days ago
Maybe it's a bit odd that it resets the 'visited' bit on non-related objects (why are they suddenly not visited)?

For me it helped to rather think about 'visited' as a special case of a counter called 'valuation' (or something like that). New objects come in with valuation 1, on cache hits a objects valuation is set to 2, and when the hand moves left it decreases objects valuations until it reaches one that gets valuation 0, then it's evicted immediately. One could easily imagine a modified algorithm where 'valuation' could be increased further than 2 if an object got visited many times (but then eviction would be much slower in some cases).

Then this is all optimized by using a bool instead of an int since we truncate 'valuation' at max 2.

Idk why they choose to call it 'visited' though.

1 comments

What "visited" really denotes is "accessed since the last time the hand reached this node".