Struct PrioGraph

Source
pub struct PrioGraph<Id: TransactionId, Rk: ResourceKey, Tl: TopLevelId<Id>, Pfn: Fn(&Id, &GraphNode<Id>) -> Tl> { /* private fields */ }
Expand description

A directed acyclic graph where edges are only present between nodes if that node is the next-highest priority node for a particular resource. Resources can be either read or write locked with write locks being exclusive. Transactions are inserted into the graph and then popped in time-priority order. Between conflicting transactions, the first to be inserted will always have higher priority.

Implementations§

Source§

impl<Id: TransactionId, Rk: ResourceKey, Tl: TopLevelId<Id>, Pfn: Fn(&Id, &GraphNode<Id>) -> Tl> PrioGraph<Id, Rk, Tl, Pfn>

Source

pub fn natural_batches( iter: impl IntoIterator<Item = (Id, impl IntoIterator<Item = (Rk, AccessKind)>)>, top_level_prioritization_fn: Pfn, ) -> Vec<Vec<Id>>

Drains all transactions from the primary queue into a batch. Then, for each transaction in the batch, unblock transactions it was blocking. If any of those transactions are now unblocked, add them to the main queue. Repeat until the main queue is empty.

Source

pub fn new(top_level_prioritization_fn: Pfn) -> Self

Create a new priority graph.

Source

pub fn clear(&mut self)

Clear the graph.

Source

pub fn make_natural_batches(&mut self) -> Vec<Vec<Id>>

Make natural batches from the transactions already inserted into the graph. Drains all transactions from the primary queue into a batch. Then, for each transaction in the batch, unblock transactions it was blocking. If any of those transactions are now unblocked, add them to the main queue. Repeat until the main queue is empty.

Source

pub fn insert_transaction( &mut self, id: Id, tx: impl IntoIterator<Item = (Rk, AccessKind)>, )

Insert a transaction into the graph with the given Id. Transactions should be inserted in priority order.

Source

pub fn is_empty(&self) -> bool

Returns true if the main queue is empty.

Source

pub fn pop_and_unblock(&mut self) -> Option<(Id, Vec<Id>)>

Combination of pop and unblock. Returns None if the queue is empty. Returns the Id of the popped node, and the set of unblocked Ids.

Source

pub fn pop(&mut self) -> Option<Id>

Pop the highest priority node id from the main queue. Returns None if the queue is empty.

Source

pub fn unblock(&mut self, id: &Id) -> Vec<Id>

This will unblock transactions that were blocked by this transaction. Returns the set of Ids that were unblocked.

Panics: - Node does not exist. - If the node.blocked_by_count != 0

Source

pub fn is_blocked(&self, id: Id) -> bool

Returns whether the given Id is at the top level of the graph, i.e. not blocked. If the node does not exist, returns false.

Auto Trait Implementations§

§

impl<Id, Rk, Tl, Pfn> Freeze for PrioGraph<Id, Rk, Tl, Pfn>
where Pfn: Freeze,

§

impl<Id, Rk, Tl, Pfn> RefUnwindSafe for PrioGraph<Id, Rk, Tl, Pfn>

§

impl<Id, Rk, Tl, Pfn> Send for PrioGraph<Id, Rk, Tl, Pfn>
where Pfn: Send, Tl: Send, Rk: Send, Id: Send,

§

impl<Id, Rk, Tl, Pfn> Sync for PrioGraph<Id, Rk, Tl, Pfn>
where Pfn: Sync, Tl: Sync, Rk: Sync, Id: Sync,

§

impl<Id, Rk, Tl, Pfn> Unpin for PrioGraph<Id, Rk, Tl, Pfn>
where Pfn: Unpin, Tl: Unpin, Rk: Unpin, Id: Unpin,

§

impl<Id, Rk, Tl, Pfn> UnwindSafe for PrioGraph<Id, Rk, Tl, Pfn>
where Pfn: UnwindSafe, Rk: UnwindSafe, Id: UnwindSafe, Tl: 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.