All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.collektive.utils.stack.StackFunctionCall.kt Maven / Gradle / Ivy

The newest version!
package it.unibo.collektive.utils.stack

/**
 * A stack that keeps track of the function calls in the code.
 */
class StackFunctionCall {
    private val stack = ArrayDeque()
    private val occurrences = mutableMapOf()

    /**
     * Pushes a new function call to the stack.
     */
    fun push(name: String) {
        val counter = occurrences[name]?.let { it + 1 } ?: 1
        occurrences[name] = counter
        val candidateToken = "$name.$counter"
        stack.addFirst(candidateToken)
    }

    /**
     * Pops the last function call from the stack.
     */
    fun pop(): String? = stack.removeFirstOrNull()

    override fun toString(): String = stack.joinToString(separator = ",")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy