contain-rs / linked-hash-map

A HashMap wrapper that holds key-value pairs in insertion order
https://contain-rs.github.io/linked-hash-map/linked_hash_map/
Apache License 2.0
169 stars 60 forks source link

Add `mark_lru` to change order of keys #79

Closed koivunej closed 2 years ago

koivunej commented 7 years ago

Hi there,

When using linked-hash-map as a cache I'd like to mark possibly no-longer needed nodes as least recently used so that they will be the first to go. I will be making a simpler PR to lru-cache if this gets accepted.

Two commits, first renames the existing fn attach(..) to fn attach_next(..) which I think is suitable as the second commit adds an fn attach_prev(..) which will be invoked by mark_lru(..) together with fn detach(..).

Naming: the current API has pop_front and front for the last element in the list and lru is not exactly a term for linked-hash-map. I'm not sure which would be more suitable name, move_front, set_front, assign_front or perhaps mark_front?