aboutsummaryrefslogtreecommitdiff
path: root/src/linked_hash_set.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/linked_hash_set.rs')
-rw-r--r--src/linked_hash_set.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/linked_hash_set.rs b/src/linked_hash_set.rs
index f55f6c5..5a89875 100644
--- a/src/linked_hash_set.rs
+++ b/src/linked_hash_set.rs
@@ -202,11 +202,20 @@ where
other.is_subset(self)
}
+ /// Inserts the given value into the set.
+ ///
+ /// If the set did not have this value present, inserts it at the *back* of the internal linked
+ /// list and returns true, otherwise it moves the existing value to the *back* of the internal
+ /// linked list and returns false.
#[inline]
pub fn insert(&mut self, value: T) -> bool {
self.map.insert(value, ()).is_none()
}
+ /// Adds the given value to the set, replacing the existing value.
+ ///
+ /// If a previous value existed, returns the replaced value. In this case, the value's position
+ /// in the internal linked list is *not* changed.
#[inline]
pub fn replace(&mut self, value: T) -> Option<T> {
match self.map.entry(value) {
@@ -288,6 +297,14 @@ where
linked_hash_map::RawEntryMut::Vacant(_) => false,
}
}
+
+ #[inline]
+ pub fn retain_with_order<F>(&mut self, mut f: F)
+ where
+ F: FnMut(&T) -> bool,
+ {
+ self.map.retain_with_order(|k, _| f(k));
+ }
}
impl<T: Hash + Eq + Clone, S: BuildHasher + Clone> Clone for LinkedHashSet<T, S> {