use crate::fixed_point_graph::FixedPointForwardGraph;
pub(crate) fn retained_graph_bytes(
graph: &FixedPointForwardGraph,
) -> Result<usize, vyre::BackendError> {
let node_tag_bytes = if graph.pg_node_tags_bytes == graph.pg_nodes_bytes {
0
} else {
graph.pg_node_tags_bytes.len()
};
graph
.pg_nodes_bytes
.len()
.checked_add(graph.edge_offsets_bytes.len())
.and_then(|total| total.checked_add(graph.edge_targets_bytes.len()))
.and_then(|total| total.checked_add(graph.edge_kind_mask_bytes.len()))
.and_then(|total| total.checked_add(node_tag_bytes))
.ok_or_else(|| vyre::BackendError::InvalidProgram {
fix: "Fix: weir fixed-point retained graph byte count overflowed usize; shard the graph before resident upload."
.to_string(),
})
}