use std::{
marker::PhantomData,
};
use crate::{
hsize,
prelude::*,
};
use super::{
DenseMap, Handles, PropMap, PropStore, PropStoreMut, SparseMap,
};
pub type DenseSet<H> = Set<H, DenseMap<H, ()>>;
pub type SparseSet<H> = Set<H, SparseMap<H, ()>>;
#[derive(Debug, Clone, Empty)]
pub struct Set<H: Handle, M: Empty>{
map: M,
_dummy: PhantomData<H>,
}
impl<H: Handle, M: Empty + PropMap<H, Target = ()>> Set<H, M> {
pub fn contains_handle(&self, handle: H) -> bool {
self.map.contains_handle(handle)
}
}
impl<H: Handle, M: Empty + PropStore<H, Target = ()>> Set<H, M> {
pub fn num_elements(&self) -> hsize {
self.map.num_props()
}
pub fn handles(&self) -> Handles<M::Iter<'_>> {
self.map.handles()
}
pub fn is_empty(&self) -> bool {
self.map.is_empty()
}
}
impl<H: Handle, M: Empty + PropStoreMut<H, Target = ()>> Set<H, M> {
pub fn with_capacity(cap: hsize) -> Self
where
Self: Sized,
{
let mut out = Self::empty();
out.reserve(cap);
out
}
pub fn insert(&mut self, handle: H) -> bool {
self.map.insert(handle, ()).is_some()
}
pub fn remove(&mut self, handle: H) -> bool {
self.map.remove(handle).is_some()
}
pub fn clear(&mut self) {
self.map.clear()
}
pub fn reserve(&mut self, additional: hsize) {
self.map.reserve(additional)
}
}