<commit_before>package rescala.parrp

import rescala.graph._
import rescala.propagation.Turn

import scala.language.implicitConversions

object ParRPStruct extends LevelStruct {
  override type Spore[R] = ParRPSporeP[_, R]

  override def bud[P, R](initialValue: Pulse[P], transient: Boolean, initialIncoming: Set[R]): SporeP[P, R] = {
    val lock = new TurnLock
    new ParRPSporeP[P, R](initialValue, transient, lock, initialIncoming)
  }

  class ParRPSporeP[P, R](current: Pulse[P], transient: Boolean, val lock: TurnLock, initialIncoming: Set[R]) extends LevelSporeImpl[P, R](current, transient, initialIncoming) {
    override def set(value: Pulse[P])(implicit turn: Turn[_]): Unit = {
      assert(turn match {
        case pessimistic: ParRP =>
          val wlo: Option[Key] = Option(lock).map(_.getOwner)
          assert(wlo.fold(true)(_ eq pessimistic.key),
            s"buffer owned by $owner, controlled by $lock with owner ${wlo.get}" +
              s" was written by $turn who locks with ${pessimistic.key}, by now the owner is ${lock.getOwner}")
          true
        case _ =>
          throw new IllegalStateException(s"parrp buffer used with wrong turn")
      })
      super.set(value)
    }
  }
}<commit_msg>move parrp spore to outer scope<commit_after>package rescala.parrp

import rescala.graph._
import rescala.propagation.Turn

import scala.language.implicitConversions

object ParRPStruct extends LevelStruct {
  override type Spore[R] = ParRPSporeP[_, R]

  override def bud[P, R](initialValue: Pulse[P], transient: Boolean, initialIncoming: Set[R]): SporeP[P, R] = {
    val lock = new TurnLock
    new ParRPSporeP[P, R](initialValue, transient, lock, initialIncoming)
  }


}


class ParRPSporeP[P, R](current: Pulse[P], transient: Boolean, val lock: TurnLock, initialIncoming: Set[R]) extends LevelSporeImpl[P, R](current, transient, initialIncoming) {
  override def set(value: Pulse[P])(implicit turn: Turn[_]): Unit = {
    assert(turn match {
      case pessimistic: ParRP =>
        val wlo: Option[Key] = Option(lock).map(_.getOwner)
        assert(wlo.fold(true)(_ eq pessimistic.key),
          s"buffer owned by $owner, controlled by $lock with owner ${wlo.get}" +
            s" was written by $turn who locks with ${pessimistic.key}, by now the owner is ${lock.getOwner}")
        true
      case _ =>
        throw new IllegalStateException(s"parrp buffer used with wrong turn")
    })
    super.set(value)
  }
}
{'fraction_non_alphanumeric': 0.11712078080520537, 'fraction_numerical': 0.0, 'mean_word_length': 3.6857142857142855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6640834', 'n_tokens_mistral': 803, 'n_tokens_neox': 778, 'n_words': 223}