Struct ShortQueue

Source
pub struct ShortQueue<T, const N: usize>
where T: Cmov + Pod,
{ /* private fields */ }
Expand description

Implements a queue with a fixed maximum size. The queue access pattern and size are oblivious.

There are two trivial efficient ways to implement this for short queues:

  1. Use oblivious compaction:
  • Push: n (2 + log n)
  • Pop: n
  • Iter: n
  1. Use timestamps:
  • Push: n
  • Pop: n
  • Iter: n (1 + log^2 n)

This implementation uses timestamps (2.), as we only need push and pop for the unsorted map.

§Invariants

  • highest_timestamp is the timestamp of the most recently added element
  • lowest_timestamp is the timestamp of the oldest element added, or just non-zero if the queue is empty
  • size is the number of elements with non-zero timestamps
  • an element in elements is valid if its timestamp is non-zero, in which case the timestamp is unique and in the range [lowest_timestamp, highest_timestamp]

Implementations§

Source§

impl<T, const N: usize> ShortQueue<T, N>
where T: Cmov + Pod + Default,

Source

pub fn new() -> Self

Creates a new empty ShortQueue with maximum size N.

Source

pub fn maybe_push(&mut self, real: bool, element: T)

Pushes element into the queue if real is true.

Source

pub fn maybe_pop(&mut self, real: bool, out: &mut T)

Pops an element from the queue into out if real is true.

Trait Implementations§

Source§

impl<T, const N: usize> Debug for ShortQueue<T, N>
where T: Cmov + Pod + Debug,

Source§

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

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

impl<T, const N: usize> Default for ShortQueue<T, N>
where T: Cmov + Pod + Default,

Source§

fn default() -> Self

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

impl<T, const N: usize> Length for ShortQueue<T, N>
where T: Cmov + Pod + Default,

Source§

fn len(&self) -> usize

Returns the length of the indexable.

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for ShortQueue<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for ShortQueue<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for ShortQueue<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for ShortQueue<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for ShortQueue<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for ShortQueue<T, N>
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> 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.
Source§

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

Source§

fn vzip(self) -> V