Skip to content

Commit

Permalink
[feat] add two constructor, from_raw_bits and one_shot
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Sep 27, 2024
1 parent b4eab5e commit 5b61f01
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ where
}
}

/// Construct a cpumask from a `usize` value.
/// Construct a cpumask from a raw `usize` value.
/// The value must be less than `2^SIZE`, panick if the value is too large.
pub fn from_usize(value: usize) -> Self {
pub fn from_raw_bits(value: usize) -> Self {
assert!(value >> SIZE == 0);

let mut bit_map = Bitmap::new();
Expand All @@ -127,6 +127,15 @@ where
Self { value: bit_map }
}

/// Construct a cpumask with a single bit set at the specified index.
/// The value must be less than `SIZE`, panick if the value is too large.
pub fn one_shot(index: usize) -> Self {
assert!(index < SIZE);
let mut bit_map = Bitmap::new();
bit_map.set(index, true);
Self { value: bit_map }
}

/// Convert this cpumask into a value of the type of its backing store.
#[inline]
pub fn into_value(self) -> <BitsImpl<SIZE> as Bits>::Store {
Expand Down

0 comments on commit 5b61f01

Please sign in to comment.