Struct AtomicFixedVecBuilder

Source
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>
where T: Storable<u64> + Copy + ToPrimitive,

Source

pub fn new() -> Self

Creates a new builder with the default BitWidth::Minimal strategy.

Source

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:

§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.

Source

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>

Source§

fn clone(&self) -> AtomicFixedVecBuilder<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Storable<u64>> Debug for AtomicFixedVecBuilder<T>

Source§

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

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

impl<T> Default for AtomicFixedVecBuilder<T>
where T: Storable<u64>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V