<commit_before>package rescala.propagation.turns

import scala.collection.immutable.HashMap

final class TurnState[A](@volatile var default: A,
                         @volatile private var values: Map[Turn, A],
                         @volatile var commitStrategy: (A, A) => A,
                         val lock: TurnLock) {

  def cl(implicit turn: Turn): Unit = assert(turn.checkLock(lock), "accessed state without holding lock")

  def transform(f: (A) => A)(implicit turn: Turn): Unit = { cl; set(f(get)) }
  def transform(f: PartialFunction[A, A])(implicit turn: Turn): Boolean = {
    cl
    if (f.isDefinedAt(get)) { transform(f: A => A); true }
    else false
  }
  def set(value: A)(implicit turn: Turn): Unit = { cl; values = values.updated(turn, value) }
  def get(implicit turn: Turn): A = { cl; values.getOrElse(turn, default) }
  def release(implicit turn: Turn): Unit = { cl; values -= turn }
  def commit(implicit turn: Turn): Unit = {
    cl
    default = commitStrategy(default, get)
    release
  }
}

object TurnState {
  def apply[A](default: A, commitStrategy: (A, A) => A, lock: TurnLock): TurnState[A] = new TurnState[A](default, HashMap[Turn, A](), commitStrategy, lock)
}
<commit_msg>uncomment assertion for TurnState held locks<commit_after>package rescala.propagation.turns

import scala.collection.immutable.HashMap

final class TurnState[A](@volatile var default: A,
                         @volatile private var values: Map[Turn, A],
                         @volatile var commitStrategy: (A, A) => A,
                         val lock: TurnLock) {

  def cl(implicit turn: Turn): Unit = () //assert(turn.checkLock(lock), "accessed state without holding lock")

  def transform(f: (A) => A)(implicit turn: Turn): Unit = { cl; set(f(get)) }
  def transform(f: PartialFunction[A, A])(implicit turn: Turn): Boolean = {
    cl
    if (f.isDefinedAt(get)) { transform(f: A => A); true }
    else false
  }
  def set(value: A)(implicit turn: Turn): Unit = { cl; values = values.updated(turn, value) }
  def get(implicit turn: Turn): A = { cl; values.getOrElse(turn, default) }
  def release(implicit turn: Turn): Unit = { cl; values -= turn }
  def commit(implicit turn: Turn): Unit = {
    cl
    default = commitStrategy(default, get)
    release
  }
}

object TurnState {
  def apply[A](default: A, commitStrategy: (A, A) => A, lock: TurnLock): TurnState[A] = new TurnState[A](default, HashMap[Turn, A](), commitStrategy, lock)
}

{'fraction_non_alphanumeric': 0.14053614947197401, 'fraction_numerical': 0.0, 'mean_word_length': 3.298429319371728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7145734', 'n_tokens_mistral': 789, 'n_tokens_neox': 771, 'n_words': 235}