use crate::*;
impl<T: Obj> Set<T> {
pub fn new() -> Self {
Self(Default::default())
}
pub fn contains(&self, t: T) -> bool {
self.0.call_ref_unchecked(|s| {
s.contains(&t)
})
}
pub fn insert(&mut self, t: T) {
self.0.mutate(|s| {
s.insert(t);
});
}
pub fn try_insert(&mut self, t: T) -> Result<(), ()> {
if self.contains(t) {
return Err(());
}
self.0.mutate(|s| {
s.insert(t);
});
Ok(())
}
pub fn remove(&mut self, t: T) {
self.0.mutate(|s| {
s.remove(&t);
});
}
pub fn len(self) -> Int {
Int::from(self.0.call_ref_unchecked(|s| s.len()))
}
pub fn is_empty(self) -> bool {
self.0.call_ref_unchecked(|s| s.is_empty())
}
}