2023-08-21 12:54:45 +02:00
|
|
|
# user interface on the DAG
|
|
|
|
|
|
|
|
# applies a new operation to the end of the graph
|
|
|
|
function push_operation!(graph::DAG, operation::Operation)
|
|
|
|
# 1.: Add the operation to the DAG
|
|
|
|
push!(graph.operationsToApply, operation)
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
# reverts the latest applied operation, essentially like a ctrl+z for
|
|
|
|
function pop_operation!(graph::DAG)
|
|
|
|
# 1.: Remove the operation from the appliedChain of the DAG
|
|
|
|
if !isempty(graph.operationsToApply)
|
|
|
|
pop!(graph.operationsToApply)
|
|
|
|
elseif !isempty(graph.appliedOperations)
|
|
|
|
appliedOp = pop!(graph.appliedOperations)
|
|
|
|
revert_operation!(graph, appliedOp)
|
|
|
|
else
|
|
|
|
error("No more operations to pop!")
|
|
|
|
end
|
2023-08-24 15:11:54 +02:00
|
|
|
|
2023-08-21 12:54:45 +02:00
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
can_pop(graph::DAG) = !isempty(graph.operationsToApply) || !isempty(graph.appliedOperations)
|
|
|
|
|
|
|
|
# reset the graph to its initial state with no operations applied
|
|
|
|
function reset_graph!(graph::DAG)
|
|
|
|
while (can_pop(graph))
|
|
|
|
pop_operation!(graph)
|
|
|
|
end
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|