From 0337f975ec27a970840b15a7db945a3943f500a8 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a5e5182..e15ad0a 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,12 @@ where Self { value: bit_map } } + pub fn one_shot(index: usize) -> Self { + 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 {