Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(data_structures): add methods to SparseStack #7305

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/oxc_data_structures/src/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ impl<T> SparseStack<T> {
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`).
///
/// Capacity is always at least 1. Stack is never empty.
Expand All @@ -209,4 +215,16 @@ impl<T> SparseStack<T> {
pub fn filled_capacity(&self) -> usize {
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