Skip to content

Commit

Permalink
Merge pull request #3 from demoray/add-vacuum-to-shrink-to
Browse files Browse the repository at this point in the history
Add calling `vacuum` to shrink_to and shrink_to_fit
  • Loading branch information
randomairborne authored Jul 15, 2024
2 parents 88458bb + e69e4fa commit 2af3ca6
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,18 @@ impl<K: PartialEq + Eq + Hash, V> ExpiringMap<K, V> {
self.inner.reserve(addtional);
}

/// Shrink the internal map to the minimum allowable size
/// in accordance with the resize policy
/// Remove all of the expired entries and shrink the map to the minimum
/// allowable size in accordance with the resize policy
pub fn shrink_to_fit(&mut self) {
self.vacuum();
self.inner.shrink_to_fit();
}

/// Shrink the internal map to the minimum of the
/// minimum allowable size and the `min_capacity`
/// in accordance with the resize policy
/// Remove all of the expired entries and shrink the map to the minimum of
/// the minimum allowable size and the `min_capacity` in accordance with the
/// resize policy
pub fn shrink_to(&mut self, min_capacity: usize) {
self.vacuum();
self.inner.shrink_to(min_capacity);
}
}
Expand Down Expand Up @@ -311,6 +313,18 @@ impl<K: PartialEq + Eq + Hash> ExpiringSet<K> {
.filter(|(_, v)| v.not_expired())
.map(|v| v.0)
}

/// Shrink the set to the minimum allowable size in accordance with the
/// resize policy
pub fn shrink_to_fit(&mut self) {
self.0.shrink_to_fit();
}

/// Shrink the set to the minimum of the minimum allowable size and the
/// `min_capacity` in accordance with the resize policy
pub fn shrink_to(&mut self, min_capacity: usize) {
self.0.shrink_to(min_capacity);
}
}

impl<K: PartialEq + Eq + Hash, V> Default for ExpiringMap<K, V> {
Expand Down

0 comments on commit 2af3ca6

Please sign in to comment.