Skip to content

Commit

Permalink
Merge pull request #12 from florian1345/v0.1.5-preparation
Browse files Browse the repository at this point in the history
v0.1.5 Preparation
  • Loading branch information
florian1345 committed Dec 30, 2021
2 parents 79514b6 + 7f29c27 commit f0e4b59
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# v0.1

## v0.1.5

* Allowed `mutate` to take an `FnOnce` instead of an `Fn`
* Implemented `Debug` for `LruCache` when `K` and `V` also implement `Debug`
* Significant restructuring with performance improvements for most methods

## v0.1.4

* Exposed an `entry_size` method to compute the requirement of entries
* Fixed `reserve` and `try_reserve` not handling errors correctly
* Improved documentation

## v0.1.3

* Implemented `Send` and `Sync` for `LruCache`
* Minor performance improvement for cloning and reallocating
* Fixed typo in documentation

## v0.1.2

* Fixed documentation errors

## v0.1.1

* Fixed documentation errors
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "lru-mem"
description = "An LRU cache implementation bounded by memory."
version = "0.1.4"
version = "0.1.5"
authors = [ "florian1345 <florian1345@gmx.de>" ]
edition = "2021"
documentation = "https://docs.rs/lru-mem/"
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use hashbrown::hash_map::DefaultHashBuilder;
use hashbrown::raw::RawTable;

use std::borrow::Borrow;
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, BuildHasher};
use std::hint;
use std::mem::{self, MaybeUninit};
Expand Down Expand Up @@ -214,6 +215,9 @@ pub struct LruCache<K, V, S = DefaultHashBuilder> {
// use one dummy entry to act as both. It has to be ensured that we never
// iterate over this seal, so the edge case in which the cache is empty has
// to be considered in every situation where we iterate over the elements.

// This system is inspired by the lru-crate: https://crates.io/crates/lru

seal: *mut Entry<K, V>,
current_size: usize,
max_size: usize,
Expand Down Expand Up @@ -1468,6 +1472,12 @@ impl<K, V, S> Drop for LruCache<K, V, S> {
}
}

impl<K: Debug, V: Debug, S> Debug for LruCache<K, V, S> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_map().entries(self.iter()).finish()
}
}

// Since the LruCache contains raw pointers, it is not automatically marked as
// Send and Sync. We will provide manual implementations as well as arguments
// why that is ok.
Expand Down

0 comments on commit f0e4b59

Please sign in to comment.