Skip to content

Commit a3283c0

Browse files
authored
Add FixedBitset::remove (#88)
1 parent 7d5ca01 commit a3283c0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ impl FixedBitSet {
217217
}
218218
}
219219

220+
/// Disable `bit`.
221+
///
222+
/// **Panics** if **bit** is out of bounds.
223+
#[inline]
224+
pub fn remove(&mut self, bit: usize) {
225+
assert!(
226+
bit < self.length,
227+
"remove at index {} exceeds fixbitset size {}",
228+
bit,
229+
self.length
230+
);
231+
let (block, i) = div_rem(bit);
232+
unsafe {
233+
*self.data.get_unchecked_mut(block) &= !(1 << i);
234+
}
235+
}
236+
220237
/// Enable `bit`, and return its previous value.
221238
///
222239
/// **Panics** if **bit** is out of bounds.
@@ -236,6 +253,7 @@ impl FixedBitSet {
236253
prev
237254
}
238255
}
256+
239257
/// Toggle `bit` (inverting its state).
240258
///
241259
/// ***Panics*** if **bit** is out of bounds
@@ -252,6 +270,7 @@ impl FixedBitSet {
252270
*self.data.get_unchecked_mut(block) ^= 1 << i;
253271
}
254272
}
273+
255274
/// **Panics** if **bit** is out of bounds.
256275
#[inline]
257276
pub fn set(&mut self, bit: usize, enabled: bool) {

0 commit comments

Comments
 (0)