Trait bitmap_allocator::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,
        size: usize,
        align_log2: usize,
    ) -> Option<usize>;
    fn next(&self, key: usize) -> Option<usize>;
    fn dealloc(&mut self, key: usize);
    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, size: usize, align_log2: usize) -> Option<usize>

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

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)

Free an allocated bit.

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

Object Safety§

This trait is not object safe.

Implementors§

source§

impl BitAlloc for BitAlloc16

source§

const CAP: usize = 16usize

source§

const DEFAULT: Self = _

source§

impl<T: BitAlloc> BitAlloc for BitAllocCascade16<T>

source§

const CAP: usize = _

source§

const DEFAULT: Self = _