Struct rolling_set::RollingSet
source · Implementations§
source§impl<T> RollingSet<T>where
T: Eq + Hash,
impl<T> RollingSet<T>where
T: Eq + Hash,
pub fn new(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
pub fn insert(&mut self, element: T)
pub fn remove(&mut self, element: &T) -> bool
pub fn contains(&self, element: &T) -> bool
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Examples found in repository?
src/lib.rs (line 43)
36 37 38 39 40 41 42 43 44 45 46 47 48
pub fn insert(&mut self, element: T) {
self.i += 1;
let v = Arc::new(element);
self.i_val_ordered.insert(self.i, v.clone());
// Here v is guaranteed to be unique
self.val_i.insert(v, self.i);
if self.len() > self.cap {
let first = self.i_val_ordered.first_key_value().unwrap().0;
let v = self.i_val_ordered.get(&first).unwrap();
self.val_i.remove(v);
}
}Trait Implementations§
source§impl<T: Clone + Hash + Eq> Clone for RollingSet<T>
impl<T: Clone + Hash + Eq> Clone for RollingSet<T>
source§fn clone(&self) -> RollingSet<T>
fn clone(&self) -> RollingSet<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<T: PartialEq + Hash + Eq> PartialEq<RollingSet<T>> for RollingSet<T>
impl<T: PartialEq + Hash + Eq> PartialEq<RollingSet<T>> for RollingSet<T>
source§fn eq(&self, other: &RollingSet<T>) -> bool
fn eq(&self, other: &RollingSet<T>) -> bool
This method tests for
self and other values to be equal, and is used
by ==.