use crate::{AllocationGroupId, AllocationRegistry};
pub struct GroupStack {
slots: Vec<AllocationGroupId>,
}
impl GroupStack {
pub const fn new() -> Self {
Self { slots: Vec::new() }
}
pub fn current(&self) -> AllocationGroupId {
if self.slots.is_empty() {
AllocationGroupId::ROOT
} else {
self.slots
.last()
.cloned()
.expect("self.slots cannot be empty")
}
}
pub fn push(&mut self, group: AllocationGroupId) {
if self.slots.len() == self.slots.capacity() {
AllocationRegistry::untracked(|| {
self.slots.reserve(64);
});
}
self.slots.push(group);
}
pub fn pop(&mut self) -> AllocationGroupId {
self.slots
.pop()
.expect("pop should not be callable when group stack is empty")
}
}