<commit_before>package is.hail.utils

import is.hail.check._
import is.hail.variant.Locus
import org.json4s.JValue
import org.json4s.JsonAST.JObject

import scala.collection.mutable
import scala.math.Ordering.Implicits._
import scala.util.parsing.combinator.JavaTokenParsers


// interval inclusive of start, exclusive of end: [start, end)
case class Interval[T](start: T, end: T)(implicit ev: Ordering[T]) extends Ordered[Interval[T]] {

  import ev._

  require(start < end, s"invalid interval: $this: start is not before end")

  def contains(position: T): Boolean = position >= start && position < end

  def overlaps(other: Interval[T]): Boolean = this.contains(other.start) || other.contains(this.start)

  def isEmpty: Boolean = start == end

  def compare(that: Interval[T]): Int = {
    var c = ev.compare(start, that.start)
    if (c != 0)
      return c

    ev.compare(end, that.end)
  }

  def toJSON(f: (T) => JValue): JValue = JObject("start" -> f(start), "end" -> f(end))
}

object Interval {
  def gen[T: Ordering](tgen: Gen[T]): Gen[Interval[T]] =
    Gen.zip(tgen, tgen)
      .filter { case (x, y) => x != y }
      .map { case (x, y) =>
        if (x < y)
          Interval(x, y)
        else
          Interval(y, x)
      }
}

case class IntervalTree[T: Ordering](root: Option[IntervalTreeNode[T]]) extends Traversable[Interval[T]] with Serializable {
  def contains(position: T): Boolean = root.exists(_.contains(position))

  def overlaps(interval: Interval[T]): Boolean = root.exists(_.overlaps(interval))

  def query(position: T): Set[Interval[T]] = {
    val b = Set.newBuilder[Interval[T]]
    root.foreach(_.query(b, position))
    b.result()
  }

  def foreach[U](f: (Interval[T]) => U) {
    root.foreach(_.foreach(f))<commit_msg>fixed interval type export to match import parser (#1538)<commit_after>package is.hail.utils

import is.hail.check._
import is.hail.variant.Locus
import org.json4s.JValue
import org.json4s.JsonAST.JObject

import scala.collection.mutable
import scala.math.Ordering.Implicits._
import scala.util.parsing.combinator.JavaTokenParsers


// interval inclusive of start, exclusive of end: [start, end)
case class Interval[T](start: T, end: T)(implicit ev: Ordering[T]) extends Ordered[Interval[T]] {

  import ev._

  require(start < end, s"invalid interval: $this: start is not before end")

  def contains(position: T): Boolean = position >= start && position < end

  def overlaps(other: Interval[T]): Boolean = this.contains(other.start) || other.contains(this.start)

  def isEmpty: Boolean = start == end

  def compare(that: Interval[T]): Int = {
    var c = ev.compare(start, that.start)
    if (c != 0)
      return c

    ev.compare(end, that.end)
  }

  def toJSON(f: (T) => JValue): JValue = JObject("start" -> f(start), "end" -> f(end))

  override def toString: String = start + "-" + end
}

object Interval {
  def gen[T: Ordering](tgen: Gen[T]): Gen[Interval[T]] =
    Gen.zip(tgen, tgen)
      .filter { case (x, y) => x != y }
      .map { case (x, y) =>
        if (x < y)
          Interval(x, y)
        else
          Interval(y, x)
      }
}

case class IntervalTree[T: Ordering](root: Option[IntervalTreeNode[T]]) extends Traversable[Interval[T]] with Serializable {
  def contains(position: T): Boolean = root.exists(_.contains(position))

  def overlaps(interval: Interval[T]): Boolean = root.exists(_.overlaps(interval))

  def query(position: T): Set[Interval[T]] = {
    val b = Set.newBuilder[Interval[T]]
    root.foreach(_.query(b, position))
    b.result()
  }

  def foreach[U](f: (Interval[T]) => U) {
    root.foreach(_.foreach(f))
{'fraction_non_alphanumeric': 0.1522758620689655, 'fraction_numerical': 0.002758620689655172, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '7383896', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1223, 'n_words': 315}