use crate::errors::Result;
use crate::graphs::{Graph, Node};
use crate::inline::data_structures::{
prefix_sums_binary_ascent, prefix_sums_segment_tree, prefix_sums_sqrt_trick, CombineOp,
};
use serde::{Deserialize, Serialize};
pub(super) trait InlineState {
fn assign_input_nodes(&mut self, graph: Graph, nodes: Vec<Node>) -> Result<()>;
fn unassign_nodes(&mut self, graph: Graph) -> Result<()>;
fn recursively_inline_graph(&mut self, graph: Graph) -> Result<Node>;
fn output_graph(&self) -> Graph;
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum DepthOptimizationLevel {
Default,
Extreme,
}
pub(super) type PrefixSumAlgorithm<T> = fn(&[T], &mut dyn CombineOp<T>) -> Result<Vec<T>>;
pub(super) fn pick_prefix_sum_algorithm<T: std::clone::Clone>(
inputs_len: u64,
optimization_level: DepthOptimizationLevel,
) -> PrefixSumAlgorithm<T> {
if matches!(optimization_level, DepthOptimizationLevel::Extreme) {
prefix_sums_binary_ascent
} else {
if inputs_len < 16 {
prefix_sums_sqrt_trick
} else {
prefix_sums_segment_tree
}
}
}