56 lines
1.3 KiB
Julia
Raw Normal View History

2023-08-25 19:27:24 +02:00
"""
push_operation!(graph::DAG, operation::Operation)
2023-08-25 19:27:24 +02:00
Apply a new operation to the graph.
See also: [`DAG`](@ref), [`pop_operation!`](@ref)
"""
function push_operation!(graph::DAG, operation::Operation)
2023-08-25 10:48:22 +02:00
# 1.: Add the operation to the DAG
push!(graph.operationsToApply, operation)
2023-08-25 10:48:22 +02:00
return nothing
end
2023-08-25 19:27:24 +02:00
"""
pop_operation!(graph::DAG)
Revert the latest applied operation on the graph.
See also: [`DAG`](@ref), [`push_operation!`](@ref)
"""
function pop_operation!(graph::DAG)
2023-08-25 10:48:22 +02:00
# 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
return nothing
end
2023-08-25 19:27:24 +02:00
"""
can_pop(graph::DAG)
Return `true` if [`pop_operation!`](@ref) is possible, `false` otherwise.
"""
2023-08-25 10:48:22 +02:00
can_pop(graph::DAG) =
!isempty(graph.operationsToApply) || !isempty(graph.appliedOperations)
2023-08-25 19:27:24 +02:00
"""
reset_graph!(graph::DAG)
Reset the graph to its initial state with no operations applied.
"""
function reset_graph!(graph::DAG)
2023-08-25 10:48:22 +02:00
while (can_pop(graph))
pop_operation!(graph)
end
2023-08-25 10:48:22 +02:00
return nothing
end