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

Capacity api for CollisionObjectSlab #351

Merged
merged 1 commit into from
Sep 27, 2020
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
27 changes: 27 additions & 0 deletions src/pipeline/object/collision_object_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ impl<N: RealField, T> CollisionObjectSlab<N, T> {
}
}

/// Constructs a new empty collection with the specified capacity.
pub fn with_capacity(capacity: usize) -> CollisionObjectSlab<N, T> {
CollisionObjectSlab {
objects: Slab::with_capacity(capacity),
}
}

/// Inserts a new collision object into this collection and returns the corresponding handle.
#[inline]
pub fn insert(&mut self, co: CollisionObject<N, T>) -> CollisionObjectSlabHandle {
Expand Down Expand Up @@ -136,6 +143,26 @@ impl<N: RealField, T> CollisionObjectSlab<N, T> {
pub fn len(&self) -> usize {
self.objects.len()
}

/// Return the number of values the slab can store without reallocating.
#[inline]
pub fn capacity(&self) -> usize {
self.objects.capacity()
}

/// Reserve capacity for at least `additional` more values to be stored
/// without allocating.
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.objects.reserve(additional);
}

/// Reserve the minimum capacity required to store exactly `additional`
/// more values.
#[inline]
pub fn reserve_exact(&mut self, additional: usize) {
self.objects.reserve_exact(additional);
}
}

impl<N: RealField, T> Index<CollisionObjectSlabHandle> for CollisionObjectSlab<N, T> {
Expand Down