Skip to content

Commit

Permalink
Add LazyMap::{remove, clear}
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Jan 8, 2024
1 parent 7f159e7 commit ee4323f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ impl<K, V, S, F> LazyMap<K, V, S, F> {
init: f,
}
}

pub fn clear(&mut self) {
self.map.clear();
}
}

impl<K, V, S, F> LazyMap<K, V, S, F>
Expand Down Expand Up @@ -957,6 +961,19 @@ where
}
}

impl<K, V, S, F> LazyMap<K, V, S, F>
where
K: Eq + Hash,
S: BuildHasher,
{
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where
Q: Hash + Equivalent<K> + ?Sized,
{
self.map.remove(key)
}
}

impl<K, V, S, F, Q> core::ops::Index<&Q> for LazyMap<K, V, S, F>
where
K: Eq + Hash,
Expand Down
17 changes: 17 additions & 0 deletions src/unsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ impl<K, V, S, F> LazyMap<K, V, S, F> {
init: f,
}
}

pub fn clear(&mut self) {
self.map.clear();
}
}

impl<K, V, S, F> LazyMap<K, V, S, F>
Expand Down Expand Up @@ -522,6 +526,19 @@ where
}
}

impl<K, V, S, F> LazyMap<K, V, S, F>
where
K: Eq + Hash,
S: BuildHasher,
{
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where
Q: Hash + Equivalent<K> + ?Sized,
{
self.map.remove(key)
}
}

/// Creates a `LazyMap` that fills all values with `V::default()`.
impl<K, V: Default, S: Default> Default for LazyMap<K, V, S> {
fn default() -> Self {
Expand Down

0 comments on commit ee4323f

Please sign in to comment.