pub struct AtomicFixedVecBuilder<T: Storable<u64>> { /* private fields */ }
Expand description
A builder for creating an AtomicFixedVec
from a slice of integers.
This builder analyzes a slice to determine the bit_width
based on
the selected BitWidth
strategy and then constructs the thread-safe vector.
§Example
use compressed_intvec::prelude::*;
use compressed_intvec::fixed::{AtomicFixedVec, UAtomicFixedVec, BitWidth};
let data: &[u32] = &[10, 20, 30, 40, 50];
// The builder can infer the minimal bit width (6 bits for 50).
let vec: UAtomicFixedVec<u32> = AtomicFixedVec::builder()
.build(data)
.unwrap();
assert_eq!(vec.bit_width(), 6);
// Or a specific strategy can be chosen.
let vec_pow2: UAtomicFixedVec<u32> = AtomicFixedVec::builder()
.bit_width(BitWidth::PowerOfTwo)
.build(data)
.unwrap();
assert_eq!(vec_pow2.bit_width(), 8);
// You can also specify an explicit bit width.
let vec_explicit: UAtomicFixedVec<u32> = AtomicFixedVec::builder()
.bit_width(BitWidth::Explicit(10))
.build(data)
.unwrap();
assert_eq!(vec_explicit.bit_width(), 10);
Implementations§
Source§impl<T> AtomicFixedVecBuilder<T>
impl<T> AtomicFixedVecBuilder<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder with the default BitWidth::Minimal
strategy.
Sourcepub fn bit_width(self, strategy: BitWidth) -> Self
pub fn bit_width(self, strategy: BitWidth) -> Self
Sets the strategy for determining the number of bits for each element.
This can be one of:
BitWidth::Minimal
: Automatically determines the minimal bit width needed.BitWidth::PowerOfTwo
: Rounds up to the next power of two.BitWidth::Explicit
: Uses the specified number of bits explicitly.
§Note
Choosing BitWidth::Minimal
and BitWidth::PowerOfTwo
introduces a one-time overhead
at construction time to find the maximum value in the input slice.
§Performance
Choosing BitWidth::PowerOfTwo
allows for true atomic operations on the vector, resulting in
better performance for concurrent access patterns. However, it may use more space than necessary.
Sourcepub fn build(self, input: &[T]) -> Result<AtomicFixedVec<T>, Error>
pub fn build(self, input: &[T]) -> Result<AtomicFixedVec<T>, Error>
Builds the AtomicFixedVec
from a slice of data.
This method consumes the builder and returns a new AtomicFixedVec
.
The initial data is populated using non-atomic writes, as the vector
is not yet shared during construction.
§Errors
Returns an Error
if a value in the input is too large for the
specified bit_width
, or if the parameters are invalid.
Trait Implementations§
Source§impl<T: Clone + Storable<u64>> Clone for AtomicFixedVecBuilder<T>
impl<T: Clone + Storable<u64>> Clone for AtomicFixedVecBuilder<T>
Source§fn clone(&self) -> AtomicFixedVecBuilder<T>
fn clone(&self) -> AtomicFixedVecBuilder<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for AtomicFixedVecBuilder<T>
impl<T> RefUnwindSafe for AtomicFixedVecBuilder<T>where
T: RefUnwindSafe,
impl<T> Send for AtomicFixedVecBuilder<T>where
T: Send,
impl<T> Sync for AtomicFixedVecBuilder<T>where
T: Sync,
impl<T> Unpin for AtomicFixedVecBuilder<T>where
T: Unpin,
impl<T> UnwindSafe for AtomicFixedVecBuilder<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more