Skip to main content

SubgraphMerge

Struct SubgraphMerge 

Source
pub struct SubgraphMerge<K>
where K: Key,
{ /* private fields */ }
Expand description

Datastructure for merging subgraphs while maintaining topological sort order.

Maintains a global topo-sorted Vec of all operators. Each subgraph (merged group) occupies a contiguous range in this Vec. Merging two groups combines their ranges and re-sorts the affected window so groups remain contiguous and correctly ordered.

Implementations§

Source§

impl<K> SubgraphMerge<K>
where K: Key,

Source

pub fn new<PredsIter>( keys: impl IntoIterator<Item = K>, preds_fn: impl FnMut(K) -> PredsIter, enemies_iter: impl IntoIterator<Item = (K, K)>, ) -> Result<Self, Vec<K>>
where PredsIter: IntoIterator<Item = K>,

Creates a new SubgraphMerge from nodes and their predecessor edges.

enemies specifies pairs of nodes that must never be placed in the same subgraph. These are checked in O(1) during Self::try_merge and maintained as representatives change.

Returns Err with a cycle if the input graph is not a DAG.

Source

pub fn find(&mut self, k: K) -> K

Find the representative of the subgraph containing k.

Source

pub fn same_set(&mut self, u: K, v: K) -> bool

Returns true if u and v are in the same subgraph.

Source

pub fn subgraphs(&self) -> impl Iterator<Item = &[K]>

Iterates all subgraph representatives with their topo-sorted operator slices, in topological order (by position in toposort_node).

Source

pub fn try_merge(&mut self, u: K, v: K) -> bool

Attempts to merge the subgraphs containing u and v. Returns false if merging would create a cycle in the subgraph DAG, or if the merge is forbidden by a no-merge constraint.

Auto Trait Implementations§

§

impl<K> Freeze for SubgraphMerge<K>

§

impl<K> RefUnwindSafe for SubgraphMerge<K>
where K: RefUnwindSafe,

§

impl<K> Send for SubgraphMerge<K>
where K: Send,

§

impl<K> Sync for SubgraphMerge<K>
where K: Sync,

§

impl<K> Unpin for SubgraphMerge<K>
where K: Unpin,

§

impl<K> UnsafeUnpin for SubgraphMerge<K>

§

impl<K> UnwindSafe for SubgraphMerge<K>
where K: 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.