use slotmap::SlotMap;
pub struct Arena<K: slotmap::Key, V> {
inner: SlotMap<K, V>,
}
impl<K: slotmap::Key, V> Default for Arena<K, V> {
fn default() -> Self {
Self { inner: SlotMap::with_key() }
}
}
impl<K: slotmap::Key, V> Arena<K, V> {
pub fn new() -> Self {
Self::default()
}
pub fn insert(&mut self, value: V) -> K {
self.inner.insert(value)
}
pub fn get(&self, id: K) -> Option<&V> {
self.inner.get(id)
}
pub fn get_mut(&mut self, id: K) -> Option<&mut V> {
self.inner.get_mut(id)
}
pub fn remove(&mut self, id: K) -> Option<V> {
self.inner.remove(id)
}
pub fn contains(&self, id: K) -> bool {
self.inner.contains_key(id)
}
pub fn len(&self) -> usize {
self.inner.len()
}
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = (K, &V)> {
self.inner.iter()
}
}