Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@ abstract class AbstractAutomaton(
clearExecutionStatesInternal(mutableSetOf())
}

private fun clearExecutionStatesInternal(visited: MutableSet<Automaton>) {
protected fun clearExecutionStatesInternal(visited: MutableSet<Automaton>) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я думаю, будет менее хрупко и более понятно, если оставить одну публичную функцию fun clearExecutionStates(visited: MutableSet<Automaton>) и убрать clearExecutionStatesInternal() и clearExecutionStatesFromOutside(), а во всех местах, где очищение вызывается снаружи, просто передать visitedStates=emptySet()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Чтобы понизить вероятность будущих ошибок, связанных с рекурсией, советую оставить именно fun clearExecutionStates(visited: MutableSet<Automaton>), а не fun clearExecutionStates(visited: MutableSet<Automaton> = mutableSetOf())

if (!visited.add(this)) return
vertices.forEach { v ->
v.executionStates.clear()
clearNestedAutomaton(v, visited)
}
}

internal fun clearExecutionStatesFromOutside(visited: MutableSet<Automaton>) = clearExecutionStatesInternal(visited)

protected open fun clearNestedAutomaton(vertex: AutomatonVertex, visited: MutableSet<Automaton>) {
if (vertex is BuildingBlock) {
val sub = vertex.subAutomaton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class RecursiveAutomaton(
override fun clearNestedAutomaton(vertex: AutomatonVertex, visited: MutableSet<Automaton>) {
if (vertex is RecursiveAutomatonBox) {
val sub = vertex.subAutomaton
if (sub !== this) (sub as? AbstractAutomaton)?.clearExecutionStates()
if (sub !== this) (sub as? AbstractAutomaton)?.clearExecutionStatesFromOutside(visited)
}
}

Expand Down