Trait BitAlloc

Source
pub trait BitAlloc: Default {
    const CAP: usize;
    const DEFAULT: Self;

    // Required methods
    fn alloc(&mut self) -> Option<usize>;
    fn alloc_contiguous(
        &mut self,
        base: Option<usize>,
        size: usize,
        align_log2: usize,
    ) -> Option<usize>;
    fn next(&self, key: usize) -> Option<usize>;
    fn dealloc(&mut self, key: usize) -> bool;
    fn dealloc_contiguous(&mut self, base: usize, size: usize) -> bool;
    fn insert(&mut self, range: Range<usize>);
    fn remove(&mut self, range: Range<usize>);
    fn any(&self) -> bool;
    fn is_empty(&self) -> bool;
    fn test(&self, key: usize) -> bool;
}
Expand description

Allocator of a bitmap, able to allocate / free bits.

Required Associated Constants§

Source

const CAP: usize

The bitmap has a total of CAP bits, numbered from 0 to CAP-1 inclusively.

Source

const DEFAULT: Self

The default value. Workaround for const fn new() -> Self.

Required Methods§

Source

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

Allocate a free bit.

Source

fn alloc_contiguous( &mut self, base: Option<usize>, size: usize, align_log2: usize, ) -> Option<usize>

Allocate a free block with a given size, and return the first bit position.

If base is not None, the allocator will try to allocate the block at the given base.

Source

fn next(&self, key: usize) -> Option<usize>

Find a index not less than a given key, where the bit is free.

Source

fn dealloc(&mut self, key: usize) -> bool

Free an allocated bit.

Returns true if successful, false if the bit is already free.

Source

fn dealloc_contiguous(&mut self, base: usize, size: usize) -> bool

Free a contiguous block of bits.

Returns true if successful, false if the bits in the range are already free.

Source

fn insert(&mut self, range: Range<usize>)

Mark bits in the range as unallocated (available)

Source

fn remove(&mut self, range: Range<usize>)

Reverse of insert

Source

fn any(&self) -> bool

👎Deprecated: use !self.is_empty() instead

Whether there are free bits remaining

Source

fn is_empty(&self) -> bool

Returns true if no bits is available.

Source

fn test(&self, key: usize) -> bool

Whether a specific bit is free

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§