Skip to main content

group_by_conflicts

Function group_by_conflicts 

Source
pub fn group_by_conflicts(specs: &[MutationSpec]) -> Vec<Vec<usize>>
Expand description

Partition specs into conflict-free groups using Union-Find.

Specs in the same group may conflict with each other. Specs in different groups are guaranteed to be independent.

§Algorithm

Uses Union-Find to efficiently group specs that transitively conflict:

  • If A conflicts with B, and B conflicts with C, then A, B, C are in same group
  • Groups can be executed sequentially, while different groups can run in parallel

§Returns

Vector of groups, where each group is a vector of spec indices.

§Examples

use ryo_executor::executor::group_by_conflicts;
use ryo_executor::{MutationSpec, MutationTargetSymbol};
use ryo_symbol::SymbolId;

let id1 = SymbolId::parse("1v1").unwrap();
let id2 = SymbolId::parse("2v1").unwrap();

let specs = vec![
    MutationSpec::AddField {
        target: MutationTargetSymbol::ById(id1),
        field_name: "name".into(),
        field_type: "String".into(),
        visibility: Default::default(),
    },
    MutationSpec::AddField {
        target: MutationTargetSymbol::ById(id2),
        field_name: "email".into(),
        field_type: "String".into(),
        visibility: Default::default(),
    },
];

let groups = group_by_conflicts(&specs);
// Two independent groups (different targets)
assert_eq!(groups.len(), 2);