Skip to main content

Resizable

Struct Resizable 

Source
pub struct Resizable<Q> { /* private fields */ }
Expand description

A dynamically resizable wrapper around a BoundedCollection.

This type implements an algorithm that allows any BoundedCollection to be dynamically resized while preserving some of its properties.

§Progress Guarantees:

  • Lock Freedom: if the wrapped collection is lock-free, all corresponding operations on Resizable are also lock-free.
  • Obstruction Freedom: if the wrapped collection exposes obstruction-free methods, all corresponding operations on Resizable are also obstruction-free.

Resizable::resize is blocking both on allocator and stale readers and writers.

§Ordering and Consistency Guarantees:

  • Relaxed FIFO: if the wrapped collection has FIFO ordering, Resizable has k-FIFO ordering with asymmetric delay and rank error.
  • Linearizability: if the wrapped collection is linearizable, all operations on Resizable are also linearizable with respect to its relaxed FIFO specification.
  • Empty-Linearizability: if the wrapped collection is linearizale, all operations on Resizable are empty-linearizable with respect to the wrapped collections specification.

If no call to resize happens, or in steady-state, Resizable has strict FIFO ordering and is strictly linearizable, given the same holds for the wrapped collection.

For more intormation on rank error and delay consult the crate level documentation.

Implementations§

Source§

impl<Q> Resizable<Q>

Source

pub fn from_parts(left: Q, right: Q) -> Self

Constructs a new Resizable from two raw BoundedCollection objects.

Source§

impl<Q> Resizable<Q>

Source

pub fn with_capacity(size: usize) -> Resizable<Q>

Constructs a new Resizable with capacity size.

Source

pub fn new() -> Self

Constructs a new Resizable

Source§

impl<Q> Resizable<Q>

Source

pub fn resize(&self, size: usize) -> bool

Attempts to resize the capacity of the collection to size slots.

Note: This method may block (on the allocator) or fail spuriously. Further a growth event may not be considered finished in regards of an other resize being possible until some time after the call to resize.

Returns true if the resize was successfull, or false if it failed. Failure can occur due to thread contention, incomplete migration of the previous resize, i.e. staleness of the datastructure, or other implementation-specific/spurious conditions.

Source§

impl<Q> Resizable<Q>

Source

pub fn into_parts(self) -> [Box<Q>; 2]

Deconstructs a Resizable into its components.

Returns the left and right raw collections currently used by this object.

Source

pub fn parts_mut(&mut self) -> [&mut Q; 2]

returns mutable references to both wrapped collections.

Source

pub fn into_current(self) -> Box<Q>

Deconstructs a Resizable into its currently active component.

Returns the raw collection currently used by this object.

Source

pub fn current_mut(&mut self) -> &mut Q

Returns a mutable reference to the currently active raw collection.

Source§

impl<Q> Resizable<Q>

Source

pub fn pop_mut(&mut self) -> Option<Q::Item>

Attempts to pop an item from the collection.

This method cicumvents the logic synchronization of Resizable::try_pop.

Source

pub fn push_mut(&mut self, item: Q::Item) -> Result<(), Q::Item>

Attmepts to push an item into the collection.

This method cicumvents the synchronization logic of Resizable::try_push.

Source

pub fn clear(&mut self)

Clears the collection.

Source

pub fn migrate(&mut self)

Migrates all remaining stale items in the old queue into the currently active queue, while ensuring enough capacity.

A subsequent call to Self::resize will succeed.

Source

pub fn drain(&mut self) -> Drain<'_, Q, impl Iterator<Item = &mut Q>> ⓘ

Drains all remaining items in the collection. Returns an iterator over the drained items.

All remaining items are dropped if the Drain is dropped.

Trait Implementations§

Source§

impl<Q> BoundedCollection for Resizable<Q>

Source§

type Item = <Q as BoundedCollection>::Item

The item stored in the collection.
Source§

fn try_push(&self, item: Self::Item) -> Result<(), Self::Item>

Attempts to push an item into the collection. Returns the item as an error if the collection is full.
Source§

fn try_pop(&self) -> Option<Self::Item>

Attempts to pop an item from the collection. Returns None if the collection is empty.
Source§

fn capacity(&self) -> usize

Returns the total capacity of the collection.
Source§

fn len(&self) -> usize

Returns the current length of the collection. The returned value may be stale under concurrent access and should not be used for synchronization.
Source§

fn is_empty(&self) -> bool

Indicates whether the collection is empty. The returned value may be stale under concurrent access and should not be used for synchronization.
Source§

fn is_full(&self) -> bool

Indicates whether the collection is full. The returned value may be stale under concurrent access and should not be used for synchronization.
Source§

fn with_capacity(capacity: usize) -> Self

Constructs a new instance of this type with capacity capacity. Read more
Source§

impl<Q: Debug> Debug for Resizable<Q>

Source§

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

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

impl<Q> Default for Resizable<Q>
where Q: Default,

Source§

fn default() -> Self

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

impl<Q> Drop for Resizable<Q>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<Q: BoundedCollection> Extend<<Q as BoundedCollection>::Item> for Resizable<Q>

Available on neither echeneis nor loom nor shuttle.
Source§

fn extend<I: IntoIterator<Item = Q::Item>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Q: BoundedCollection> IntoIterator for Resizable<Q>

Available on neither echeneis nor loom nor shuttle.
Source§

type IntoIter = IntoIter<Q>

Which kind of iterator are we turning this into?
Source§

type Item = <Q as BoundedCollection>::Item

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<Q> !Freeze for Resizable<Q>

§

impl<Q> RefUnwindSafe for Resizable<Q>

§

impl<Q> Send for Resizable<Q>
where [AtomicPtr<Q>; 2]: Send, PhantomData<Box<Q>>: Send,

§

impl<Q> Sync for Resizable<Q>
where [AtomicPtr<Q>; 2]: Sync, PhantomData<Box<Q>>: Sync,

§

impl<Q> Unpin for Resizable<Q>
where [AtomicPtr<Q>; 2]: Unpin, PhantomData<Box<Q>>: Unpin,

§

impl<Q> UnsafeUnpin for Resizable<Q>

§

impl<Q> UnwindSafe for Resizable<Q>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.