Struct Bitmap

Source
pub struct Bitmap { /* private fields */ }
Expand description

A generic bitmap, understood by hwloc.

The Bitmap represents a set of objects, typically OS processors – which may actually be hardware threads (represented by CpuSet, which is a type alias for Bitmap – or memory nodes (represented by NodeSet, which is also a typedef for Bitmap).

Both CpuSet and NodeSet are always indexed by OS physical number.

A Bitmap may be of infinite size.

Implementations§

Source§

impl Bitmap

Source

pub fn new() -> Bitmap

Creates an empty Bitmap.

Examples:

use hwloc::Bitmap;

let bitmap = Bitmap::new();
assert_eq!("", format!("{}", bitmap));
assert_eq!(true, bitmap.is_empty());
Source

pub fn full() -> Bitmap

Creates a full Bitmap.

Examples:

use hwloc::Bitmap;

let bitmap = Bitmap::full();
assert_eq!("0-", format!("{}", bitmap));
assert_eq!(false, bitmap.is_empty());
Source

pub fn from(id: u32) -> Bitmap

Creates a new HwlocBitmap (either CpuSet or NodeSet) and sets one index right away.

Examples:

use hwloc::Bitmap;

let bitmap = Bitmap::from(1);
assert_eq!("1", format!("{}", bitmap));
assert_eq!(false, bitmap.is_empty());
Source

pub fn from_range(begin: u32, end: i32) -> Bitmap

Creates a new Bitmap with the given range.

Examples:

use hwloc::Bitmap;

let bitmap = Bitmap::from_range(0, 5);
assert_eq!("0-5", format!("{}", bitmap));
Source

pub fn from_raw(bitmap: *mut IntHwlocBitmap, manage: bool) -> Bitmap

Wraps the given hwloc bitmap pointer into its Bitmap representation.

This function is not meant to be used directly, it rather serves as the conversion factory when dealing with hwloc-internal structures.

Source

pub fn as_ptr(&self) -> *const IntHwlocBitmap

Returns the containted hwloc bitmap pointer for interaction with hwloc.

Source

pub fn set(&mut self, id: u32)

Set index id in this Bitmap.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.set(4);
assert_eq!("4", format!("{}", bitmap));
Source

pub fn set_range(&mut self, begin: u32, end: i32)

Add indexes from begin to end in this Bitmap.

If end is -1, the range is infinite.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.set_range(3, 5);
assert_eq!("3-5", format!("{}", bitmap));

bitmap.set_range(2, -1);
assert_eq!("2-", format!("{}", bitmap));
Source

pub fn unset(&mut self, id: u32)

Remove index id from the Bitmap.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::from_range(1,3);
bitmap.unset(1);
assert_eq!("2-3", format!("{}", bitmap));
Source

pub fn unset_range(&mut self, begin: u32, end: i32)

Remove indexes from begin to end in this Bitmap.

If end is -1, the range is infinite.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::from_range(1,5);
bitmap.unset_range(4,6);
assert_eq!("1-3", format!("{}", bitmap));

bitmap.unset_range(2,-1);
assert_eq!("1", format!("{}", bitmap));
Source

pub fn weight(&self) -> i32

The number of indexes that are in the bitmap.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::from_range(1,5);
assert_eq!(5, bitmap.weight());
bitmap.unset(3);
assert_eq!(4, bitmap.weight());
Source

pub fn clear(&mut self)

Clears the Bitmap.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::from_range(1,5);
assert_eq!(5, bitmap.weight());
assert_eq!(false, bitmap.is_empty());

bitmap.clear();
assert_eq!(0, bitmap.weight());
assert_eq!(true, bitmap.is_empty());
Source

pub fn is_empty(&self) -> bool

Checks if this Bitmap has indexes set.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::new();
assert_eq!(true, bitmap.is_empty());

bitmap.set(3);
assert_eq!(false, bitmap.is_empty());

bitmap.clear();
assert_eq!(true, bitmap.is_empty());
Source

pub fn is_set(&self, id: u32) -> bool

Check if the field with the given id is set.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::new();
assert_eq!(false, bitmap.is_set(2));

bitmap.set(2);
assert_eq!(true, bitmap.is_set(2));
Source

pub fn singlify(&mut self)

Keep a single index among those set in the bitmap.

May be useful before binding so that the process does not have a chance of migrating between multiple logical CPUs in the original mask.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.set_range(0, 127);
assert_eq!(128, bitmap.weight());

bitmap.invert();
assert_eq!(-1, bitmap.weight());

bitmap.singlify();
assert_eq!(1, bitmap.weight());

assert_eq!(128, bitmap.first());
assert_eq!(128, bitmap.last());
Source

pub fn invert(&mut self)

Inverts the current Bitmap.

Examples:

use hwloc::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.set(3);

assert_eq!("3", format!("{}", bitmap));
assert_eq!("0-2,4-", format!("{}", !bitmap));
Source

pub fn first(&self) -> i32

Compute the first index (least significant bit) in this Bitmap.

Returns -1 if no index is set.

Examples:

use hwloc::Bitmap;

let bitmap = Bitmap::from_range(4,10);
assert_eq!(4, bitmap.first());
Source

pub fn last(&self) -> i32

Compute the last index (most significant bit) in this Bitmap.

Returns -1 if no index is bitmap, or if the index bitmap is infinite.

Examples:

use hwloc::Bitmap;

let bitmap = Bitmap::from_range(4,10);
assert_eq!(10, bitmap.last());
Source

pub fn is_full(&self) -> bool

Test whether this Bitmap is completely full.

Examples:

use hwloc::Bitmap;

let empty_bitmap = Bitmap::new();
assert_eq!(false, empty_bitmap.is_full());

let full_bitmap = Bitmap::full();
assert_eq!(true, full_bitmap.is_full());

Trait Implementations§

Source§

impl Clone for Bitmap

Source§

fn clone(&self) -> Bitmap

Returns a copy 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 Debug for Bitmap

Source§

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

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

impl Default for Bitmap

Source§

fn default() -> Self

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

impl Display for Bitmap

Source§

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

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

impl Drop for Bitmap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromIterator<u32> for Bitmap

Source§

fn from_iter<I: IntoIterator<Item = u32>>(iter: I) -> Bitmap

Creates a value from an iterator. Read more
Source§

impl IntoIterator for Bitmap

Source§

type Item = u32

The type of the elements being iterated over.
Source§

type IntoIter = BitmapIntoIterator

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 Not for Bitmap

Source§

fn not(self) -> Bitmap

Returns a new bitmap which contains the negated values of the current one.

Source§

type Output = Bitmap

The resulting type after applying the ! operator.
Source§

impl PartialEq for Bitmap

Source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl Freeze for Bitmap

§

impl RefUnwindSafe for Bitmap

§

impl !Send for Bitmap

§

impl !Sync for Bitmap

§

impl Unpin for Bitmap

§

impl UnwindSafe for Bitmap

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.