A Vec of Bits
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #141 from contain-rs/remove_all

Implement `fn remove_all`; update RELEASES.md

authored by blackson.tngl.sh and committed by

GitHub eec5b3b7 4757f472

+27
+3
RELEASES.md
··· 5 5 6 6 - Minimal Supported Rust Version is now 1.82 7 7 - `fn remove` is implemented 8 + - `fn fill` is implemented 9 + - `fn remove_all` is implemented 10 + - `fn clear` is **deprecated** 8 11 - `fn push_within_capacity` is implemented 9 12 - `.skip(n)` on our iterators is now O(1) instead of O(n) time 10 13 - `fn to_bytes` is optimized with a lookup table
+24
src/lib.rs
··· 1857 1857 result 1858 1858 } 1859 1859 1860 + /// Removes all bits in this vector. 1861 + /// 1862 + /// Note: this method is not named [`clear`] to avoid confusion whenever [`.fill(false)`] 1863 + /// is needed. 1864 + /// 1865 + /// [`clear`]: Self::clear 1866 + /// [`.fill(false)`]: Self::fill 1867 + pub fn remove_all(&mut self) { 1868 + self.storage.clear(); 1869 + self.nbits = 0; 1870 + } 1871 + 1860 1872 /// Appends an element if there is sufficient spare capacity, otherwise an error is returned 1861 1873 /// with the element. 1862 1874 /// ··· 3542 3554 assert_eq!(v.remove(1024), 1024 % 11 < 7); 3543 3555 assert_eq!(v.len(), 1024); 3544 3556 assert_eq!(v.storage().len(), 1024 / 32); 3557 + } 3558 + 3559 + #[test] 3560 + fn test_remove_all() { 3561 + let mut v = BitVec::from_elem(1024, false); 3562 + for _ in 0..1024 { 3563 + let mut v2 = v.clone(); 3564 + v2.remove_all(); 3565 + assert_eq!(v2.len(), 0); 3566 + assert_eq!(v2.get(0), None); 3567 + assert_eq!(v2, BitVec::new()); 3568 + } 3545 3569 } 3546 3570 }