Skip to content

Commit 9dd8a22

Browse files
committed
Fixes for the usage of bit-vec
1 parent cfb8b54 commit 9dd8a22

2 files changed

Lines changed: 70 additions & 4 deletions

File tree

RELEASES.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Version 0.9.0
88

99
<a id="v0.9.0"></a>
1010

11-
* Minimal Supported Rust Version is 1.82
12-
* Rust edition 2021 is used
13-
* implemented `fn make_empty`
14-
* implemented `fn reset`
11+
- Minimal Supported Rust Version is 1.82
12+
- Rust edition 2021 is used
13+
- implemented `fn make_empty`
14+
- implemented `fn reset`
15+
- added general initialization functions: `fn new_general`, `fn from_bit_vec_general`, `fn with_capacity_general`, `fn from_bytes_general`
1516

1617
Version 0.8.0
1718
========================================================

src/lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,64 @@ impl BitSet<u32> {
261261
}
262262

263263
impl<B: BitBlock> BitSet<B> {
264+
/// Creates a new empty `BitSet`.
265+
///
266+
/// # Examples
267+
///
268+
/// ```
269+
/// use bit_set::BitSet;
270+
///
271+
/// let mut s = <BitSet>::new_general();
272+
/// ```
273+
#[inline]
274+
pub fn new_general() -> Self {
275+
Self::default()
276+
}
277+
278+
/// Creates a new `BitSet` with initially no contents, able to
279+
/// hold `nbits` elements without resizing.
280+
///
281+
/// # Examples
282+
///
283+
/// ```
284+
/// use bit_set::BitSet;
285+
///
286+
/// let mut s = <BitSet>::with_capacity_general(100);
287+
/// assert!(s.capacity() >= 100);
288+
/// ```
289+
#[inline]
290+
pub fn with_capacity_general(nbits: usize) -> Self {
291+
let bit_vec = BitVec::from_elem_general(nbits, false);
292+
Self::from_bit_vec_general(bit_vec)
293+
}
294+
295+
/// Creates a new `BitSet` from the given bit vector.
296+
///
297+
/// # Examples
298+
///
299+
/// ```
300+
/// use bit_vec::BitVec;
301+
/// use bit_set::BitSet;
302+
///
303+
/// let bv: BitVec<u64> = BitVec::from_bytes_general(&[0b01100000]);
304+
/// let s = BitSet::from_bit_vec_general(bv);
305+
///
306+
/// // Print 1, 2 in arbitrary order
307+
/// for x in s.iter() {
308+
/// println!("{}", x);
309+
/// }
310+
/// ```
311+
#[inline]
312+
pub fn from_bit_vec_general(bit_vec: BitVec<B>) -> Self {
313+
BitSet { bit_vec }
314+
}
315+
316+
pub fn from_bytes_general(bytes: &[u8]) -> Self {
317+
BitSet {
318+
bit_vec: BitVec::from_bytes_general(bytes),
319+
}
320+
}
321+
264322
/// Returns the capacity in bits for this bit vector. Inserting any
265323
/// element less than this amount will not trigger a resizing.
266324
///
@@ -840,6 +898,13 @@ impl<B: BitBlock> BitSet<B> {
840898
self.bit_vec.remove_all();
841899
}
842900

901+
/// Clears all bits in this set
902+
#[deprecated(since = "0.9.0", note = "please use `fn make_empty` instead")]
903+
#[inline]
904+
pub fn clear(&mut self) {
905+
self.make_empty();
906+
}
907+
843908
/// Returns `true` if this set contains the specified integer.
844909
#[inline]
845910
pub fn contains(&self, value: usize) -> bool {

0 commit comments

Comments
 (0)