Skip to content

Commit

Permalink
Add FixedBitset::remove (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
james7132 authored Jan 16, 2023
1 parent 7d5ca01 commit a3283c0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ impl FixedBitSet {
}
}

/// Disable `bit`.
///
/// **Panics** if **bit** is out of bounds.
#[inline]
pub fn remove(&mut self, bit: usize) {
assert!(
bit < self.length,
"remove at index {} exceeds fixbitset size {}",
bit,
self.length
);
let (block, i) = div_rem(bit);
unsafe {
*self.data.get_unchecked_mut(block) &= !(1 << i);
}
}

/// Enable `bit`, and return its previous value.
///
/// **Panics** if **bit** is out of bounds.
Expand All @@ -236,6 +253,7 @@ impl FixedBitSet {
prev
}
}

/// Toggle `bit` (inverting its state).
///
/// ***Panics*** if **bit** is out of bounds
Expand All @@ -252,6 +270,7 @@ impl FixedBitSet {
*self.data.get_unchecked_mut(block) ^= 1 << i;
}
}

/// **Panics** if **bit** is out of bounds.
#[inline]
pub fn set(&mut self, bit: usize, enabled: bool) {
Expand Down

0 comments on commit a3283c0

Please sign in to comment.