Add entries to ExecutionQueue only once

This commit is contained in:
Grigorii Kirgizov 2019-07-10 13:50:46 +03:00 committed by Fedor Isakov
parent 2dba8890f3
commit f7ea5f7a0d
1 changed files with 8 additions and 3 deletions

View File

@ -41,6 +41,7 @@ internal class ExecutionQueue(
lhs, rhs -> journalIndex.compare(lhs.pos, rhs.pos)
}
private val seen: MutableSet<ExecPos> = HashSet()
fun run(controller: Controller, state: ProcessingStateImpl): FeedbackStatus.NORMAL {
if (execQueue.isNotEmpty()) {
@ -103,16 +104,20 @@ internal class ExecutionQueue(
fun offerAll(occs: Iterable<Occurrence>): Boolean =
execQueue.addAll(occs.mapNotNull { occ ->
journalIndex.activatingChunkOf(Id(occ))?.let { chunk ->
ExecPos(chunk.toPos(), occ)
ExecPos(chunk.toPos(), occ).let {
if (seen.add(it)) it else null
}
}
})
fun offer(posInJournal: MatchJournal.Pos, activeOcc: Occurrence): Boolean =
execQueue.offer(ExecPos(posInJournal, activeOcc))
ExecPos(posInJournal, activeOcc).let {
if (seen.add(it)) execQueue.offer(it) else false
}
// special case when position in trace corresponds to position of activated occurrence
fun offer(posInJournal: MatchJournal.Pos): Boolean =
execQueue.offer(ExecPos(posInJournal, posInJournal.occ))
offer(posInJournal, posInJournal.occ)
fun isEmpty(): Boolean = execQueue.isEmpty()