hamzaremmal/amy

View on GitHub
compiler/src/main/scala/amyc/utils/UniqueCounter.scala

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
package amyc.utils

import scala.collection.mutable

// Generates unique counters for each element of a type K
class UniqueCounter[K] {
  private val elemIds = mutable.Map[K, Int]().withDefaultValue(-1)

  def next(key: K): Int = synchronized {
    elemIds(key) += 1
    elemIds(key)
  }

}