use crate::{LinearMap, VecMap};
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct VecSet<T: Eq> {
pub(crate) map: VecMap<T, ()>,
}
impl<T: Eq> VecSet<T> {
pub fn new() -> Self {
VecSet { map: VecMap::new() }
}
pub fn with_capacity(capacity: usize) -> Self {
VecSet {
map: VecMap::with_capacity(capacity),
}
}
pub const unsafe fn from_map_unchecked(map: VecMap<T, ()>) -> VecSet<T> {
VecSet { map }
}
pub fn len(&self) -> usize {
self.map.len()
}
pub fn is_empty(&self) -> bool {
self.map.is_empty()
}
pub fn insert(&mut self, value: T) -> bool {
self.map.insert(value, ()).is_some()
}
pub fn remove(&mut self, value: &T) -> Option<T> {
self.map.remove_entry(&value).map(|(t, _)| t)
}
pub fn contains(&self, value: &T) -> bool {
self.map.contains_key(value)
}
pub fn into_vec(self) -> Vec<T> {
self.map.into_inner().into_iter().map(|(t, _)| t).collect()
}
}