rusty_mos::utils::bitmap

Struct Bitmap

Source
pub struct Bitmap<const COUNT: usize> {
    bitmap: [u8; COUNT],
    used: usize,
    pointer: usize,
}
Expand description

The bitmap itself. Contains the map and assistant field.

The used maintains the count of bit used to speed up the empty or full judgement.

The algorithm of searching the next empty bit is as follows:

We maintain a pointer, the search will from the pointer one-by-one.

§Generic

The const CCOUNT marks the count of bit maintains. The bitmap can hold (CCOUNT * 8) bits.

Fields§

§bitmap: [u8; COUNT]

The bitmap itself.

§used: usize

Used bits count.

§pointer: usize

Search pointer.

Implementations§

Source§

impl<const COUNT: usize> Bitmap<COUNT>

Source

pub const fn new() -> Self

Create a new bitmap and initialize the field as zero.

Source

pub fn empty(&self) -> bool

Judge whether the bitmap is empty.

Source

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

To see whether the index is not used.

Source

pub fn alloc(&mut self) -> Option<usize>

Alloc a new bit if available. A None will be returned if no bit rest.

Source

pub fn free(&mut self, index: usize)

Free the specified bit. Double free is not allowed.

Trait Implementations§

Source§

impl<const COUNT: usize> Debug for Bitmap<COUNT>

Source§

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

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

impl<const COUNT: usize> Default for Bitmap<COUNT>

Source§

fn default() -> Self

Default constructions.

Auto Trait Implementations§

§

impl<const COUNT: usize> Freeze for Bitmap<COUNT>

§

impl<const COUNT: usize> RefUnwindSafe for Bitmap<COUNT>

§

impl<const COUNT: usize> Send for Bitmap<COUNT>

§

impl<const COUNT: usize> Sync for Bitmap<COUNT>

§

impl<const COUNT: usize> Unpin for Bitmap<COUNT>

§

impl<const COUNT: usize> UnwindSafe for Bitmap<COUNT>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.