Skip to content

Commit 6870e4e

Browse files
John SmithChristien Rioux
authored andcommitted
add peek_lru
1 parent 50bb6ac commit 6870e4e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lru_cache.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ where
262262
pub fn remove_lru(&mut self) -> Option<(K, V)> {
263263
self.map.pop_front()
264264
}
265+
266+
/// Peek at the least recently used entry and return a reference to it.
267+
///
268+
/// If the `LruCache` is empty this will return None.
269+
#[inline]
270+
pub fn peek_lru(&mut self) -> Option<(&K, &V)> {
271+
self.map.front()
272+
}
265273
}
266274

267275
impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Default + Clone> Clone for LruCache<K, V, S> {

0 commit comments

Comments
 (0)