mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(data_structures): add methods to SparseStack (#7305)
Add methods to `SparseStack` to get the filled entries as a slice, and get their length.
This commit is contained in:
parent
4acf2db82b
commit
d135d3ec48
1 changed files with 18 additions and 0 deletions
|
|
@ -192,6 +192,12 @@ impl<T> SparseStack<T> {
|
||||||
self.has_values.len()
|
self.has_values.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get number of filled entries on the stack.
|
||||||
|
#[inline]
|
||||||
|
pub fn filled_len(&self) -> usize {
|
||||||
|
self.values.len()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get capacity of stack for any entries (either `Some` or `None`).
|
/// Get capacity of stack for any entries (either `Some` or `None`).
|
||||||
///
|
///
|
||||||
/// Capacity is always at least 1. Stack is never empty.
|
/// Capacity is always at least 1. Stack is never empty.
|
||||||
|
|
@ -209,4 +215,16 @@ impl<T> SparseStack<T> {
|
||||||
pub fn filled_capacity(&self) -> usize {
|
pub fn filled_capacity(&self) -> usize {
|
||||||
self.values.capacity()
|
self.values.capacity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get filled entries of stack as a slice `&[T]`.
|
||||||
|
#[inline]
|
||||||
|
pub fn as_slice(&self) -> &[T] {
|
||||||
|
self.values.as_slice()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get filled entries of stack as a mutable slice `&mut [T]`.
|
||||||
|
#[inline]
|
||||||
|
pub fn as_mut_slice(&mut self) -> &mut [T] {
|
||||||
|
self.values.as_mut_slice()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue