Struct prio_graph::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 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 chain_id(&self, id: &Id) -> u64

Returns the minimum chain id for a given node id.

Panics: - Node does not exist.

source

pub fn pop_and_unblock(&mut self) -> Option<(Id, HashSet<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) -> HashSet<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> RefUnwindSafe for PrioGraph<Id, Rk, Tl, Pfn>

§

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

§

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

§

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

§

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

§

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

§

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.