Trait segvec::MemConfig

source ·
pub trait MemConfig {
    // Required methods
    fn new() -> Self;
    fn debug_assert_config();
    fn capacity(&self, segments: usize) -> usize;
    fn segment_size(&self, segment: usize) -> usize;
    fn segment_and_offset(&self, index: usize) -> (usize, usize);

    // Provided method
    fn update_capacity(&mut self, _segments: usize) { ... }
}
Expand description

Configures the sizes of segments and how to index entries. Linear, Proportional and Exponential implement this trait.

Required Methods§

source

fn new() -> Self

source

fn debug_assert_config()

Called by ctors to assert that the configuration is valid.

Some MemConfig implementations may put constraints on (const generic) parameters. Currently it is impossible to assert these at compile time in stable rust. In debug builds we check these constraints when a SegVec uses some config. The three shipped MemConfig implementations check here that the ‘FACTOR’ is not zero.

source

fn capacity(&self, segments: usize) -> usize

Takes the number of allocated segments, returns the total capacity.

source

fn segment_size(&self, segment: usize) -> usize

Returns the size of the nth segment (starting at 0).

source

fn segment_and_offset(&self, index: usize) -> (usize, usize)

Translates a flat index into (segment, offset)

Provided Methods§

source

fn update_capacity(&mut self, _segments: usize)

Updates the capacity to the given number of segments.

Implementors§

source§

impl<const FACTOR: usize> MemConfig for Exponential<FACTOR>

source§

impl<const FACTOR: usize> MemConfig for Linear<FACTOR>

source§

impl<const FACTOR: usize> MemConfig for Proportional<FACTOR>