Skip to content

Commit

Permalink
Add capacity api for CollisionObjectSlab
Browse files Browse the repository at this point in the history
  • Loading branch information
FenQiDian authored and sebcrozet committed Sep 27, 2020
1 parent c6421ed commit f94f032
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit f94f032

Please sign in to comment.