use crate::ifds_resident_types::{
ResidentIfdsHostScratch, ResidentIfdsParallelHostScratch, ResidentPreparedIfdsCsr,
};
use vyre_primitives::graph::csr_forward_or_changed::{
csr_forward_or_changed_parallel, csr_forward_or_changed_parallel_batch_global,
};
use vyre_primitives::graph::program_graph::ProgramGraphShape;
pub(super) fn ensure_resident_single_query_programs<R>(
prepared: &ResidentPreparedIfdsCsr<R>,
host_scratch: &mut ResidentIfdsHostScratch,
max_iterations: u32,
) -> Result<(), String> {
let _ = max_iterations;
if host_scratch.step_program_node_count != prepared.node_count
|| host_scratch.step_program_edge_count != prepared.shape.edge_count
|| host_scratch.step_program.is_none()
{
host_scratch.step_program_node_count = prepared.node_count;
host_scratch.step_program_edge_count = prepared.shape.edge_count;
host_scratch.step_program = Some(csr_forward_or_changed_parallel(
ProgramGraphShape::new(prepared.node_count, prepared.shape.edge_count),
"frontier",
"changed",
u32::MAX,
));
}
Ok(())
}
pub(super) fn ensure_resident_parallel_step_programs<R>(
prepared: &ResidentPreparedIfdsCsr<R>,
host_scratch: &mut ResidentIfdsParallelHostScratch,
query_count: u32,
_changed_slots: u32,
_max_iterations: usize,
) -> Result<(), String> {
if host_scratch.step_program_node_count != prepared.node_count
|| host_scratch.step_program_edge_count != prepared.shape.edge_count
|| host_scratch.step_program_query_count != query_count
|| host_scratch.step_program_changed_slots != 1
{
host_scratch.step_programs.clear();
host_scratch.step_program_node_count = prepared.node_count;
host_scratch.step_program_edge_count = prepared.shape.edge_count;
host_scratch.step_program_query_count = query_count;
host_scratch.step_program_changed_slots = 1;
}
if host_scratch.step_programs.is_empty() {
host_scratch
.step_programs
.push(csr_forward_or_changed_parallel_batch_global(
ProgramGraphShape::new(prepared.node_count, prepared.shape.edge_count),
"frontiers",
"changed",
u32::MAX,
query_count,
));
}
Ok(())
}