<commit_before>package rescala.propagation

import rescala.graph.ReevaluationResult.{Dynamic, Static}
import rescala.graph.{Committable, Reactive}
import rescala.turns.Turn

trait TurnImpl extends Turn {
  implicit def currentTurn: TurnImpl = this

  protected var toCommit = Set[Committable]()

  val levelQueue = new LevelQueue()

  def evaluate(head: Reactive): Unit = {
    def requeue(changed: Boolean, level: Int, redo: Boolean): Unit =
      if (redo) levelQueue.enqueue(level, changed)(head)
      else if (changed) head.outgoing.get.foreach(levelQueue.enqueue(level, changed))

    head.reevaluate() match {
      case Static(hasChanged) =>
        requeue(hasChanged, -42, redo = false)
      case Dynamic(hasChanged, diff) =>
        diff.removed foreach unregister(head)
        diff.added foreach register(head)
        val newLevel = maximumLevel(diff.novel) + 1
        requeue(hasChanged, newLevel, redo = head.level.get < newLevel)
    }

  }

  def maximumLevel(dependencies: Set[Reactive])(implicit turn: Turn): Int = dependencies.foldLeft(-1)((acc, r) => math.max(acc, r.level.get))

  def register(sink: Reactive)(source: Reactive): Unit = {
    source.outgoing.transform(_ + sink)
  }

  def unregister(sink: Reactive)(source: Reactive): Unit = {
    source.outgoing.transform(_ - sink)
  }

  override def plan(commitable: Committable): Unit = {
    toCommit += commitable
  }
<commit_msg>give constant a name<commit_after>package rescala.propagation

import rescala.graph.ReevaluationResult.{Dynamic, Static}
import rescala.graph.{Committable, Reactive}
import rescala.turns.Turn

trait TurnImpl extends Turn {
  implicit def currentTurn: TurnImpl = this

  protected var toCommit = Set[Committable]()

  val levelQueue = new LevelQueue()

  def evaluate(head: Reactive): Unit = {
    def requeue(changed: Boolean, level: Int, redo: Boolean): Unit =
      if (redo) levelQueue.enqueue(level, changed)(head)
      else if (changed) head.outgoing.get.foreach(levelQueue.enqueue(level, changed))

    head.reevaluate() match {
      case Static(hasChanged) =>
        requeue(hasChanged, level = -42, redo = false)
      case Dynamic(hasChanged, diff) =>
        diff.removed foreach unregister(head)
        diff.added foreach register(head)
        val newLevel = maximumLevel(diff.novel) + 1
        requeue(hasChanged, newLevel, redo = head.level.get < newLevel)
    }

  }

  def maximumLevel(dependencies: Set[Reactive])(implicit turn: Turn): Int = dependencies.foldLeft(-1)((acc, r) => math.max(acc, r.level.get))

  def register(sink: Reactive)(source: Reactive): Unit = {
    source.outgoing.transform(_ + sink)
  }

  def unregister(sink: Reactive)(source: Reactive): Unit = {
    source.outgoing.transform(_ - sink)
  }

  override def plan(commitable: Committable): Unit = {
    toCommit += commitable
  }

{'fraction_non_alphanumeric': 0.11870376893272279, 'fraction_numerical': 0.0028178936245156746, 'mean_word_length': 3.863013698630137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '816489', 'n_tokens_mistral': 909, 'n_tokens_neox': 883, 'n_words': 214}