Skip to content

Commit

Permalink
Merge pull request #16 from LukasKalbertodt/add-clear
Browse files Browse the repository at this point in the history
Add `StableVec::clear()` and update dependencies
  • Loading branch information
LukasKalbertodt authored Jun 11, 2018
2 parents 9eac7cf + 30b91e8 commit 7d14ba4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- `StableVec::insert_into_hole()`
- `StableVec::grow()`
- `StableVec::clear()`

### Changed
- The `Drop` impl now uses the `mem::needs_drop()` optimization hint to avoid
unnecessary overhead.
- Updated `bit-vec` from `0.4` to `0.5`

## [0.2.0] - 2017-09-17
### Added
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ maintenance = { status = "actively-developed" }


[dependencies]
bit-vec = "0.4.4"
bit-vec = "0.5.0"

[dev-dependencies]
quickcheck = "0.4"
quickcheck = "0.6.2"
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,27 @@ impl<T> StableVec<T> {
self.used_count == 0
}

/// Removes all elements from this collection.
///
/// After calling this, `num_elements()` will return 0. However, no memory
/// is deallocated, so the capacity stays as it was before.
///
/// # Example
///
/// ```
/// # use stable_vec::StableVec;
/// let mut sv = StableVec::from(&['a', 'b']);
///
/// sv.clear();
/// assert_eq!(sv.num_elements(), 0);
/// assert!(sv.capacity() >= 2);
/// ```
pub fn clear(&mut self) {
self.data.clear();
self.deleted.truncate(0);
self.used_count = 0;
}

/// Returns the number of elements the stable-vector can hold without
/// reallocating.
pub fn capacity(&self) -> usize {
Expand Down

0 comments on commit 7d14ba4

Please sign in to comment.