use serde::{Deserialize, Serialize};
use crate::types::*;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "op")]
pub enum StrategyOp {
Once {
rule: String, },
Exhaust {
rule: String,
#[serde(default)]
order: Order,
#[serde(skip_serializing_if = "Option::is_none")]
measure: Option<String>,
},
While {
rule: String,
pred: String, #[serde(default)]
order: Order,
},
Seq {
strategies: Vec<Box<StrategyOp>>,
},
Choice {
strategies: Vec<Box<StrategyOp>>,
},
Priority {
strategies: Vec<PrioritizedStrategy>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrioritizedStrategy {
pub strategy: Box<StrategyOp>,
pub priority: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub enum Order {
#[default]
#[serde(rename = "topdown")]
TopDown,
#[serde(rename = "bottomup")]
BottomUp,
#[serde(rename = "fair")]
Fair,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StrategyIR {
pub strategy: StrategyOp,
}
#[derive(Debug, Clone)]
pub struct StrategyResult {
pub applied_count: usize,
pub final_graph: crate::graph::GraphRef,
pub patches: Vec<crate::ir::patch::Patch>,
}
pub trait Externs {
fn deg_ge(&self, v: VertexId, k: u32) -> bool;
fn edge_count_nonincreasing(&self, g0: &crate::graph::GraphRef, g1: &crate::graph::GraphRef) -> bool;
fn custom_pred(&self, name: &str, args: &[Value]) -> bool;
}