Skip to main content

SharedUniversal

Struct SharedUniversal 

Source
pub struct SharedUniversal<T: Copy + Eq + 'static> { /* private fields */ }

Implementations§

Source§

impl<T: Copy + Eq + 'static> SharedUniversal<T>

Source

pub fn create( base: impl AsRef<Path>, capacity: usize, ) -> Result<Self, UniversalError>

Create a new container. Starts in Vec strategy at (generation=0, version=0).

Source

pub fn open( base: impl AsRef<Path>, capacity: usize, ) -> Result<Self, UniversalError>

Open an existing container. Reads the active (generation, version, strategy) from the state header and opens the matching backing file.

Source

pub fn strategy(&self) -> Strategy

The strategy currently active in shared state. May differ from the locally-held backing if another writer just migrated; the next op call will re-open transparently.

Source

pub fn strategy_version(&self) -> u32

The shared strategy version. Bumps on every migration; wraps to 0 at u32::MAX with the generation counter incrementing.

Source

pub fn strategy_generation(&self) -> u16

The shared generation counter. Bumps each time version wraps from u32::MAX back to 0. Together with version it forms the true monotonic migration counter.

Source

pub fn insert(&self, value: T) -> Result<(), UniversalError>
where T: Hash,

Insert value. For Vec strategy this is push_back; for Map strategy this is insert(value, ()).

Source

pub fn contains(&self, value: &T) -> Result<bool, UniversalError>
where T: Hash,

Membership check. Bumps the contains counter so the local policy can observe contains-heavy workloads.

Source

pub fn len(&self) -> Result<usize, UniversalError>

Number of live entries.

Source

pub fn is_empty(&self) -> Result<bool, UniversalError>

Source

pub fn clear(&self) -> Result<(), UniversalError>

Reset the universal to empty: clears whichever backing is currently live (Vec or Map). Does not change the strategy. Useful for steady-state benches that need to reset accumulated state between iterations. Not thread-safe with concurrent insert/remove from other threads.

Source

pub fn snapshot(&self) -> Result<Vec<T>, UniversalError>

Snapshot all live values into a Vec<T>. Best-effort under concurrent writers.

Source

pub fn op_histogram(&self) -> (u64, u64)

Operation counts since creation. The writer’s policy code reads these to decide when to migrate.

Source

pub fn migrate_to(&self, target: Strategy) -> Result<(), UniversalError>
where T: Hash,

Force a migration to target. Snapshots the current backing, creates a new backing file at version+1, restores the snapshot, then publishes the new (version, strategy) via Release CAS.

§Concurrency

Single-writer ONLY. Two processes calling migrate_to concurrently will both build new backings and race on the CAS; the loser orphans its backing file. Use ap-uvj’s voting protocol to coordinate when multiple writers are involved.

Source

pub fn maybe_migrate_by_policy( &self, contains_to_insert_ratio: f64, min_total_ops: u64, ) -> Result<Option<Strategy>, UniversalError>
where T: Hash,

Local-policy migration trigger. If the observed contains ops outnumber insert ops by at least contains_to_insert_ratio, AND total ops exceed min_total_ops, migrate Vec → Map. If the inverse holds, migrate Map → Vec.

Returns Ok(Some(new_strategy)) if a migration happened, Ok(None) if no policy threshold was crossed.

Trait Implementations§

Source§

impl<T: Copy + Eq + Send + Sync + 'static> AdaptiveInstance for SharedUniversal<T>

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

fn apply_migration(&self, new_tag: u32)

Called by the sidecar when the policy returns a new strategy tag. Default implementation: just set the tag on the header. Primitives that need heavier migration (data-layout swap) override this to perform the swap before (or after) updating the tag.
Source§

impl<T: Copy + Eq + Send + 'static> Send for SharedUniversal<T>

Source§

impl<T: Copy + Eq + Sync + 'static> Sync for SharedUniversal<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SharedUniversal<T>

§

impl<T> !RefUnwindSafe for SharedUniversal<T>

§

impl<T> !UnwindSafe for SharedUniversal<T>

§

impl<T> Unpin for SharedUniversal<T>
where RwLock<RawRwLock, (u32, u16, Backing<T>)>: Unpin, PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for SharedUniversal<T>
where RwLock<RawRwLock, (u32, u16, Backing<T>)>: UnsafeUnpin, PhantomData<T>: UnsafeUnpin,

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