CpuMask

Struct CpuMask 

Source
pub struct CpuMask<const SIZE: usize>
where BitsImpl<SIZE>: Bits,
{ /* private fields */ }
Expand description

A compact array of bits which represents a set of physical CPUs, implemented based on bitmaps::Bitmap.

The type used to store the cpumask will be the minimum unsigned integer type required to fit the number of bits, from u8 to u128. If the size is 1, bool is used. If the size exceeds 128, an array of u128 will be used, sized as appropriately. The maximum supported size is currently 1024, represented by an array [u128; 8].

Implementations§

Source§

impl<const SIZE: usize> CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source

pub fn new() -> Self

Construct a cpumask with every bit set to false.

Source

pub fn full() -> Self

Construct a cpumask with every bit set to true.

Source

pub fn mask(bits: usize) -> Self

Construct a cpumask where every bit with index less than bits is true, and every other bit is false.

Source

pub fn from_value(data: <BitsImpl<SIZE> as Bits>::Store) -> Self

Construct a cpumask from a value of the same type as its backing store.

Source

pub fn from_raw_bits(value: usize) -> Self

Construct a cpumask from a raw usize value. The value must be less than 2^SIZE, panick if the value is too large.

Source

pub fn one_shot(index: usize) -> Self

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.

Source

pub fn into_value(self) -> <BitsImpl<SIZE> as Bits>::Store

Convert this cpumask into a value of the type of its backing store.

Source

pub fn as_value(&self) -> &<BitsImpl<SIZE> as Bits>::Store

Get a reference to this cpumask’s backing store.

Source

pub fn as_bytes(&self) -> &[u8]

Get this cpumask as a slice of bytes.

Source

pub fn len(self) -> usize

Count the number of true bits in the cpumask.

Source

pub fn is_empty(self) -> bool

Test if the cpumask contains only false bits.

Source

pub fn is_full(self) -> bool

Test if the cpumask contains only true bits.

Source

pub fn get(self, index: usize) -> bool

Get the value of the bit at a given index.

Source

pub fn set(&mut self, index: usize, value: bool) -> bool

Set the value of the bit at a given index.

Returns the previous value of the bit.

Source

pub fn first_index(self) -> Option<usize>

Find the index of the first true bit in the cpumask.

Source

pub fn last_index(self) -> Option<usize>

Find the index of the last true bit in the cpumask.

Source

pub fn next_index(self, index: usize) -> Option<usize>

Find the index of the first true bit in the cpumask after index.

Source

pub fn prev_index(self, index: usize) -> Option<usize>

Find the index of the last true bit in the cpumask before index.

Source

pub fn first_false_index(self) -> Option<usize>

Find the index of the first false bit in the cpumask.

Source

pub fn last_false_index(self) -> Option<usize>

Find the index of the last false bit in the cpumask.

Source

pub fn next_false_index(self, index: usize) -> Option<usize>

Find the index of the first false bit in the cpumask after index.

Source

pub fn prev_false_index(self, index: usize) -> Option<usize>

Find the index of the first false bit in the cpumask before index.

Source

pub fn invert(&mut self)

Invert all the bits in the cpumask.

Trait Implementations§

Source§

impl<const SIZE: usize> BitAnd for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = CpuMask<SIZE>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<const SIZE: usize> BitAndAssign for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<const SIZE: usize> BitOr for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = CpuMask<SIZE>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<const SIZE: usize> BitOrAssign for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<const SIZE: usize> BitXor for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = CpuMask<SIZE>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const SIZE: usize> BitXorAssign for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<const SIZE: usize> Clone for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn clone(&self) -> CpuMask<SIZE>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const SIZE: usize> Debug for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const SIZE: usize> Default for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn default() -> CpuMask<SIZE>

Returns the “default value” for a type. Read more
Source§

impl From<[u128; 2]> for CpuMask<256>

Source§

fn from(data: [u128; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 3]> for CpuMask<384>

Source§

fn from(data: [u128; 3]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 4]> for CpuMask<512>

Source§

fn from(data: [u128; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 5]> for CpuMask<640>

Source§

fn from(data: [u128; 5]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 6]> for CpuMask<768>

Source§

fn from(data: [u128; 6]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 7]> for CpuMask<896>

Source§

fn from(data: [u128; 7]) -> Self

Converts to this type from the input type.
Source§

impl From<[u128; 8]> for CpuMask<1024>

Source§

fn from(data: [u128; 8]) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<1024>> for [u128; 8]

Source§

fn from(cpumask: CpuMask<1024>) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<256>> for [u128; 2]

Source§

fn from(cpumask: CpuMask<256>) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<384>> for [u128; 3]

Source§

fn from(cpumask: CpuMask<384>) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<512>> for [u128; 4]

Source§

fn from(cpumask: CpuMask<512>) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<640>> for [u128; 5]

Source§

fn from(cpumask: CpuMask<640>) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<768>> for [u128; 6]

Source§

fn from(cpumask: CpuMask<768>) -> Self

Converts to this type from the input type.
Source§

impl From<CpuMask<896>> for [u128; 7]

Source§

fn from(cpumask: CpuMask<896>) -> Self

Converts to this type from the input type.
Source§

impl<const SIZE: usize> Hash for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits, <BitsImpl<SIZE> as Bits>::Store: Hash,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, const SIZE: usize> IntoIterator for &'a CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, SIZE>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const SIZE: usize> Not for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

type Output = CpuMask<SIZE>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<const SIZE: usize> Ord for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits, <BitsImpl<SIZE> as Bits>::Store: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const SIZE: usize> PartialEq for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

fn eq(&self, other: &CpuMask<SIZE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const SIZE: usize> PartialOrd for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits, <BitsImpl<SIZE> as Bits>::Store: PartialOrd,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const SIZE: usize> Copy for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

impl<const SIZE: usize> Eq for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Source§

impl<const SIZE: usize> StructuralPartialEq for CpuMask<SIZE>
where BitsImpl<SIZE>: Bits,

Auto Trait Implementations§

§

impl<const SIZE: usize> !Freeze for CpuMask<SIZE>

§

impl<const SIZE: usize> !RefUnwindSafe for CpuMask<SIZE>

§

impl<const SIZE: usize> !Send for CpuMask<SIZE>

§

impl<const SIZE: usize> !Sync for CpuMask<SIZE>

§

impl<const SIZE: usize> !Unpin for CpuMask<SIZE>

§

impl<const SIZE: usize> !UnwindSafe for CpuMask<SIZE>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.