From 5b61f0136d140a529ba2ab609e47beb41dc4f1c4 Mon Sep 17 00:00:00 2001 From: hky1999 <976929993@qq.com> Date: Fri, 27 Sep 2024 21:41:08 +0800 Subject: [PATCH] [feat] add two constructor, from_raw_bits and one_shot --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a5e5182..4ff1b9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(); @@ -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) -> as Bits>::Store {