package edu.knowitall.srlie

import edu.knowitall.collection.immutable.Interval
import scala.util.control.Exception
import edu.knowitall.tool.parse.graph.DependencyNode
import edu.knowitall.tool.srl.Role
import edu.knowitall.tool.srl.Frame
import edu.knowitall.tool.parse.graph.DependencyGraph
import edu.knowitall.tool.srl.Roles
import edu.knowitall.collection.immutable.graph.Graph.Edge
import edu.knowitall.collection.immutable.graph.DirectedEdge
import edu.knowitall.collection.immutable.graph.Direction
import edu.knowitall.tool.srl.Roles.R
import edu.knowitall.tool.srl.FrameHierarchy
import edu.knowitall.collection.immutable.graph.UpEdge
import edu.knowitall.collection.immutable.graph.Graph
import edu.knowitall.srlie.SrlExtraction._
import scala.collection.immutable.SortedSet
import edu.knowitall.tool.tokenize.Token
import edu.knowitall.tool.tokenize.Tokenizer

case class SrlExtraction(relation: Relation, arg1: Argument, arg2s: Seq[Argument], context: Option[Context], negated: Boolean) {
  def rel = relation

  def relationArgument = {
    if (this.active) {
      this.arg2s.find(arg2 => arg2.role == Roles.A1 || arg2.role == Roles.A2)
    }
    else if (this.passive) {
      this.arg2s.find(_.role == Roles.A2)
    }
    else {
      None
    }
  }

  def intervals = (arg1.interval +: relation.intervals) ++ arg2s.map(_.interval)

  def tokens = relation.tokens ++ arg1.tokens ++ arg2s.flatMap(_.tokens)

  private val bePresentVerbs = Set("am", "are", "is")
  private val bePastVerbs = Set("was", "were")
  private val beVerbs = bePastVerbs ++ bePresentVerbs
  def transformations(transformations: Transformation*): Seq[SrlExtraction] = {
    def passiveDobj = {
      for {
        a1 <- arg2s.find(_.role == Roles.A1).toSeq
        a2 <- arg2s.find(_.role == Roles.A2)

        if a1.tokens.exists(token => token.isNoun || token.isPronoun)
        if a2.tokens.exists(token => token.isNoun || token.isPronoun)

        a0 = arg1
        if a0.role == Roles.A0
        if !this.context.isDefined
      } yield {
        // val a0New = new Argument("[by] " + a0.text, a0.tokens, a0.interval, a0.role)
        val arg2s = /* a0New +: */ this.arg2s.filterNot(_ == a1)

        val inferred =
          if (this.rel.tokens.exists(token => token.text == "has" || token.text == "have")) {
            "[been]"
          }
          else if (arg1.plural) {
            "[were]"
          }
          else {
            "[was]"
          }

        val (before, after) = this.rel.tokens.filter { token =>
          !beVerbs.contains(token.text)
        }.span(node => node.postag == "MD" || node.text == "has" || node.text == "have")
        val text = Iterable(before.iterator.map(_.text), Iterable(inferred), after.iterator.map(_.text)).flatten.mkString(" ")
        val rel = new Relation(text, this.rel.sense, this.rel.tokens, this.rel.intervals)

        SrlExtraction(rel, a1, arg2s, context, negated)
      }
    }

    if (transformations.contains(PassiveDobj)) {
      passiveDobj
    } else {
      Seq.empty
    }
  }

  def triplize(includeDobj: Boolean = true): Seq[SrlExtraction] = {
    val relArg = if (includeDobj) this.relationArgument else None

    val filteredArg2s = (arg2s filterNot (arg2 => relArg.exists(_ == arg2)))
    val tripleExtrs = if (filteredArg2s.isEmpty) {
      Seq(this)
    } else {
      val extrs = relArg match {
        case Some(relArg) => arg2s.map { arg2 =>
          val rel =
            if (arg2 == relArg) {
              relation
            } else {
              val tokens = (relation.tokens ++ relArg.tokens).sortBy(_.tokenInterval)
              val text = relation.text + " " + relArg.tokens.iterator.map(_.text).mkString(" ")
              relation.copy(text = text, tokens = tokens, intervals = relation.intervals :+ relArg.interval)
            }
          new SrlExtraction(rel, this.arg1, Seq(arg2), context, negated)
        }
        case None => filteredArg2s.map { arg2 =>
          new SrlExtraction(rel, this.arg1, Seq(arg2), context, negated)
        }
      }

      // don't include dobj if we create any intransitives
      if (extrs exists (_.intransitive)) {
        this.triplize(false)
      }
      else {
        extrs
      }
    }

    tripleExtrs.filter { extr =>
      // filter extractions where the rel overlaps the arg2
      extr.arg2s.forall(arg2 => extr.rel.intervals.forall(relInterval => !(arg2.interval intersects relInterval)))
    }.flatMap { extr =>
      // move preposition to relation if it leads the arg2
      extr.arg2s match {
        case Seq(arg2) if arg2.hasLeadingPreposition =>
          // since we are removing text and tokens from the arg2,
          // we might violate a requirement that the text and the
          // number of tokens is non empty.
          Exception.catching(classOf[Exception]).opt(arg2.withoutLeadingPreposition).map { newArg2 =>
            val leadingPreposition = arg2.leadingPrepositionToken.get
            val newRel = extr.rel.copy(
              text = extr.rel.text + " " + leadingPreposition.text,
              tokens = extr.rel.tokens :+ leadingPreposition,
              intervals = extr.rel.intervals :+ Interval.singleton(arg2.interval.start)
            )
            extr.copy(relation = newRel, arg2s = Seq(newArg2))
          }
        case _ => Some(extr)
      }
      // make sure the arg2 still contains tokens
    }.filter { extr =>
      extr.arg2s.forall(!_.tokens.isEmpty)
    }
  }

  def basicTripleString = {
    Iterable(arg1.text, relation.text, arg2s.iterator.map(_.text).mkString("; ")).mkString("(", "; ", ")")
  }
  override def toString = {
    val parts = Iterable(arg1.toString, relation.toString, arg2s.iterator.map(_.toString).mkString("; "))
    val prefix = context match {
      case Some(context) => context.text + ":"
      case None => ""
    }
    prefix + parts.mkString("(", "; ", ")")
  }

  def intransitive = arg2s.isEmpty

  // an extraction is active if A0 is the first A*
  def active = !intransitive && this.arg1.role == Roles.A0

  // an extraction is active if it's not passive
  def passive = !intransitive && !active
}

object SrlExtraction {
  case class Sense(name: String, id: String)

  sealed abstract class Transformation
  case object PassiveDobj extends Transformation

  def create(relation: Relation, arguments: Seq[Argument], context: Option[Context], negated: Boolean) = {
    val arg1 = arguments.find(arg => (arg.role.label matches "A\\d+") && (relation.intervals.forall(interval => arg.interval leftOf interval))).getOrElse {
      throw new IllegalArgumentException("Extraction has no arg1.")
    }

    // look for potential arguments that are right of the relation
    val rightArg2s = arguments.filter { arg =>
      relation.intervals.forall(interval => arg.interval rightOf interval)
    } ++ arguments.filter { arg =>
      !relation.intervals.forall(interval => arg.interval rightOf interval) &&
        (arg.role == Roles.AM_TMP || arg.role == Roles.AM_LOC)
    }

    val arg2s =
      // if we didn't find any, use any prime arguments that were found
      if (rightArg2s.isEmpty) {
        arguments.filter(arg => arg != arg1 && (arg.role.label matches "A\\d+"))
      }
      else {
        rightArg2s
      }

    new SrlExtraction(relation, arg1, arg2s, context, negated)
  }

  abstract class Part {
    def text: String
    def tokens: Seq[DependencyNode]

    def tokenSpan: Interval

    require(!text.isEmpty, "Extraction part text may not be empty.")
    require(!tokens.isEmpty, "Extraction part tokens may not be empty.")
    //   require(tokens.sorted == tokens)
  }

  abstract class MultiPart extends Part {
    def intervals: Seq[Interval]
    def span = Interval.span(intervals)

    def tokenIntervals = intervals
    def tokenSpan = span

    override def hashCode = intervals.hashCode * 39 + tokens.hashCode
    def canEqual(that: Any): Boolean = that.isInstanceOf[MultiPart]
    override def equals(that: Any): Boolean = that match {
      case that: MultiPart => (
          that.canEqual(this)
              && this.text == that.text
              && this.tokens == that.tokens
              && this.intervals == that.intervals
          )
      case _ => false
    }
  }

  abstract class SinglePart extends Part {
    def interval: Interval

    def tokenInterval = interval
    def tokenSpan = tokenInterval
    def offsets = Interval.open(
      this.tokens.head.offsets.start,
      this.tokens.last.offsets.end
    )
  }

  class Context(val text: String, val tokens: Seq[DependencyNode], val intervals: Seq[Interval]) extends MultiPart {
    override def toString = text

    override def canEqual(that: Any): Boolean = that.isInstanceOf[Context]
    override def equals(that: Any): Boolean = that match {
      case that: Context => (
        that.canEqual(this)
        && this.text == that.text
        && this.tokens == that.tokens
        && this.intervals == that.intervals
      )
      case _ => false
    }

    override def hashCode(): Int = {
      val state = Seq(text, tokens, intervals)
      state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
    }
  }

  abstract class Argument extends SinglePart {
    def text: String
    def tokens: Seq[DependencyNode]
    def interval: Interval
    def role: Role

    override def toString = text

    def plural = tokens.exists { token =>
      token.isPluralNoun
    }

    def hasLeadingPreposition: Boolean = {
      leadingPrepositionToken.isDefined
    }

    def leadingPrepositionToken: Option[DependencyNode] = {
      tokens.headOption.filter { head =>
        head.postag == "IN" || head.postag == "TO"
      }
    }

    def withoutLeadingPreposition: Argument = {
      if (!leadingPrepositionToken.isDefined) {
        this
      } else {
        new SimpleArgument(tokens.drop(1), Interval.open(interval.start + 1, interval.end), role)
      }
    }
  }

  abstract class SemanticArgument extends Argument

  case class SimpleArgument(val text: String, val tokens: Seq[DependencyNode], val interval: Interval, val role: Role) extends Argument {
    def this(tokens: Seq[DependencyNode], interval: Interval, role: Role) =
      this(Tokenizer.originalText(tokens).trim, tokens, interval, role)
    override def toString = text
  }

  case class TemporalArgument(val text: String, val tokens: Seq[DependencyNode], val interval: Interval, val role: Role)
      extends SemanticArgument {

    def this(tokens: Seq[DependencyNode], interval: Interval, role: Role) =
      this(Tokenizer.originalText(tokens).trim, tokens, interval, role)

    override def toString = "T:" + super.toString

    override def withoutLeadingPreposition: TemporalArgument = {
      if (!leadingPrepositionToken.isDefined) {
        this
      } else {
        new TemporalArgument(tokens.drop(1), Interval.open(interval.start + 1, interval.end), role)
      }
    }
  }

  case class LocationArgument(val text: String, val tokens: Seq[DependencyNode], val interval: Interval, val role: Role)
      extends SemanticArgument {

    def this(tokens: Seq[DependencyNode], interval: Interval, role: Role) =
      this(Tokenizer.originalText(tokens).trim, tokens, interval, role)

    override def toString = "L:" + super.toString

    override def withoutLeadingPreposition: LocationArgument = {
      if (!leadingPrepositionToken.isDefined) {
        this
      } else {
        new LocationArgument(tokens.drop(1), Interval.open(interval.start + 1, interval.end), role)
      }
    }
  }

  case class Relation(text: String, sense: Option[Sense], tokens: Seq[DependencyNode], intervals: Seq[Interval]) extends MultiPart {
    // make sure all the intervals are disjoint
    try {
      require(intervals.forall(x => !intervals.exists(y => x != y && (x intersects y))))
    } catch {
      case e: Exception =>
        System.out.println("Panic on line: " + text)
    }

    override def toString = text

    override def canEqual(that: Any): Boolean = that.isInstanceOf[Relation]
    override def equals(that: Any): Boolean = that match {
      case that: Relation => (
        that.canEqual(this)
        && this.text == that.text
        && this.sense == that.sense
        && this.tokens == that.tokens
        && this.intervals == that.intervals
      )
      case _ => false
    }

    def concat(other: Relation) = {
      Relation(this.text + " " + other.text, None, this.tokens ++ other.tokens, this.intervals ++ other.intervals)
    }

    override def hashCode(): Int = {
      val state = Seq(text, sense, tokens, intervals)
      state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
    }
  }

  object Relation {
    val expansionLabels = Set("advmod", "neg", "aux", "cop", "auxpass", "prt", "acomp")
  }

  def contiguousAdjacent(graph: DependencyGraph, node: DependencyNode, cond: DirectedEdge[DependencyNode] => Boolean, until: Set[DependencyNode]) = {
    def takeAdjacent(interval: Interval, nodes: List[DependencyNode], pool: List[DependencyNode]): List[DependencyNode] = pool match {
      // can we add the top node?
      case head :: tail if (head.indices borders interval) && !until.contains(head) =>
        takeAdjacent(interval union head.indices, head :: nodes, tail)
      // otherwise abort
      case _ => nodes
    }

    val inferiors = graph.graph.connected(node, dedge => cond(dedge) && !(until contains dedge.end))
    val span = Interval.span(inferiors.map(_.indices))
    val contiguous = graph.nodes.drop(span.start).take(span.length).toList.sorted

    // split into nodes left and right of node
    val lefts = contiguous.takeWhile(_ != node).reverse
    val rights = contiguous.dropWhile(_ != node).drop(1)

    // take adjacent nodes from each list
    val withLefts = takeAdjacent(node.indices, List(node), lefts)
    val expanded = takeAdjacent(node.indices, withLefts, rights).sortBy(_.indices)

    // only take items that are inferiors
    expanded.slice(expanded.indexWhere(inferiors contains _), 1 + expanded.lastIndexWhere(inferiors contains _))
  }

  /** Find all nodes in a components next to the node.
    *
    * @param  node  components will be found adjacent to this node
    * @param  labels  components may be connected by edges with any of these labels
    * @param  without  components may not include any of these nodes
    */
  def components(graph: DependencyGraph, node: DependencyNode, labels: Set[String], without: Set[DependencyNode], nested: Boolean) = {
    // nodes across an allowed label to a subcomponent
    val across = graph.graph.neighbors(node, (dedge: DirectedEdge[_]) => dedge.dir match {
      case Direction.Down if labels.contains(dedge.edge.label) => true
      case _ => false
    })

    across.flatMap { start =>
      // get inferiors without passing back to node
      val inferiors = graph.graph.inferiors(
        start,
        (e: Graph.Edge[DependencyNode]) =>
          // don't cross a conjunction that goes back an across node
          !((e.label startsWith "conj") && (across contains e.dest)) &&
            // make sure we don't cycle out of the component
            e.dest != node &&
            // make sure we don't descend into another component
            // i.e. "John M. Synge who came to us with his play direct
            // from the Aran Islands , where the material for most of
            // his later works was gathered" if nested is false
            (nested || !labels.contains(e.label))
      )

      // make sure none of the without nodes are in the component
      if (without.forall(!inferiors.contains(_))) {
        val span = Interval.span(inferiors.map(_.indices).toSeq)
        Some(graph.nodes.filter(node => span.superset(node.indices)).toList)
      } else {
        None
      }
    }
  }

  val componentEdgeLabels = Set("rcmod", "infmod", "partmod", "ref", "prepc_of", "advcl")
  val forbiddenEdgeLabel = Set("appos", "punct", "cc") ++ componentEdgeLabels
  def fromFrame(dgraph: DependencyGraph)(frame: Frame): Option[SrlExtraction] = {
    val argsNotBoundaries = frame.arguments.filterNot { arg =>
      arg.role match {
        case Roles.AM_MNR => true
        case Roles.AM_MOD => true
        case Roles.AM_NEG => true
        case Roles.AM_ADV => true
        case _: Roles.C => true
        case _ => false
      }
    }

    // context information
    val negated = frame.arguments.find(_.role == Roles.AM_NEG).isDefined

    val boundaries = argsNotBoundaries.map(_.node).toSet + frame.relation.node

    val args = argsNotBoundaries.filterNot { arg =>
      arg.role match {
        case _: Roles.R => true
        case _ => false
      }
    }

    val rel = {
      // sometimes we need detached tokens: "John shouts profanities out loud."
      val nodes = dgraph.graph.inferiors(frame.relation.node, edge => (Relation.expansionLabels contains edge.label) && !(boundaries contains edge.dest))
      val additionalNodes =
        // sometimes we need to go up a pcomp
        dgraph.graph.predecessors(frame.relation.node, edge => edge.label == "pcomp" && nodes.exists { node => node.tokenInterval borders edge.source.tokenInterval })
      val remoteNodes = (
        // expand to certain nodes connected by a conj edge
        (dgraph.graph.superiors(frame.relation.node, edge => edge.label == "conj") - frame.relation.node) flatMap (node => dgraph.graph.inferiors(node, edge => edge.label == "aux" && edge.dest.text == "to") - node)
      ).filter(_.index < frame.relation.node.index)
      val nodeSeq = (remoteNodes ++ nodes ++ additionalNodes).toSeq.sorted

      /** create a minimal spanning set of the supplied intervals.
        *
        * @returns  a sorted minimal spanning set
        */
      def minimal(intervals: Iterable[Interval]): List[Interval] = {
        val set = collection.immutable.SortedSet.empty[Int] ++ intervals.flatten
        set.foldLeft(List.empty[Interval]) {
          case (list, i) =>
            val singleton = Interval.singleton(i)
            list match {
              case Nil => List(singleton)
              case x :: xs if x borders singleton => (x union singleton) :: xs
              case xs => singleton :: xs
            }
        }.reverse
      }

      val intervals = minimal(nodeSeq.map(_.tokenInterval))
      val text = nodeSeq.iterator.map(_.text).mkString(" ")
      Relation(text, Some(Sense(frame.relation.name, frame.relation.sense)), nodeSeq, intervals)
    }

    val mappedArgs = args.map { arg =>
      val immediateNodes =
        // expand along certain contiguous nodes
        contiguousAdjacent(dgraph, arg.node, dedge => dedge.dir == Direction.Down && !(forbiddenEdgeLabel contains dedge.edge.label), boundaries)

      val componentNodes: Set[List[DependencyNode]] =
        if (immediateNodes.exists(_.isProperNoun)) {
          Set.empty
        }
        else {
          components(dgraph, arg.node, componentEdgeLabels, boundaries, false)
        }

      val nodeSpan = Interval.span(immediateNodes.map(_.tokenInterval) ++ componentNodes.map(_.tokenInterval))
      val nodes = dgraph.nodes.slice(nodeSpan.start, nodeSpan.end)

      val nodeSeq = nodes.toSeq
      arg.role match {
        case Roles.AM_TMP => new TemporalArgument(nodeSeq, Interval.span(nodes.map(_.indices)), arg.role)
        case Roles.AM_LOC => new LocationArgument(nodeSeq, Interval.span(nodes.map(_.indices)), arg.role)
        case _ => new SimpleArgument(nodeSeq, Interval.span(nodes.map(_.indices)), arg.role)
      }
    }

    Exception.catching(classOf[IllegalArgumentException]) opt SrlExtraction.create(rel, mappedArgs, None, negated)
  }

  def fromFrameHierarchy(dgraph: DependencyGraph)(frameh: FrameHierarchy): Seq[SrlExtraction] = {
    def rec(frameh: FrameHierarchy): Seq[SrlExtraction] = {
      if (frameh.children.isEmpty) {
        SrlExtraction.fromFrame(dgraph)(frameh.frame).toSeq
      }
      else {
        SrlExtraction.fromFrame(dgraph)(frameh.frame) match {
          case Some(extr) =>
            val context = {
              extr.context match {
                case Some(context) =>
                  val intervals = SortedSet.empty[Interval] ++ extr.rel.intervals + extr.arg1.interval
                  val tokens = (Set.empty[DependencyNode] ++ extr.arg1.tokens ++ extr.rel.tokens).toSeq.sortBy(_.tokenInterval)
                  new Context(tokens.iterator.map(_.string).mkString(" "), tokens, intervals.toSeq)
                case None =>
                  val intervals = extr.rel.intervals :+ extr.arg1.interval
                  val tokens = extr.arg1.tokens ++ extr.rel.tokens
                  new Context(tokens.iterator.map(_.string).mkString(" "), tokens, intervals)
              }
            }
            val subextrs = frameh.children flatMap rec

            // triplize to include dobj in rel
            val relation = extr.relationArgument match {
              case Some(arg) if subextrs.forall(_.arg2s.forall(arg2 => !(arg2.interval intersects arg.interval))) &&
                (arg.interval borders extr.relation.span) => extr.relation.copy(tokens = (arg.tokens ++ extr.relation.tokens).sorted, text = extr.relation.text + " " + arg.text)
              case _ => extr.relation
            }

            extr +: (subextrs flatMap { subextr =>
              Exception.catching(classOf[IllegalArgumentException]) opt
                {
                  val combinedContext = subextr.context match {
                    case Some(subcontext) =>
                      val intervals = (context.intervals ++ subcontext.intervals).toSet.toSeq.sorted
                      val tokens = (context.tokens ++ subcontext.tokens).toSet
                      val sortedToken = tokens.toSeq.sortBy(_.tokenInterval)
                      new Context(sortedToken.iterator.map(_.string).mkString(" "), sortedToken, intervals)
                    case None => context
                  }
                  if (extr.arg1 == subextr.arg1) {
                    // combine the relations to make a more informative relation phrase
                    SrlExtraction(relation concat subextr.relation, subextr.arg1, subextr.arg2s, Some(combinedContext), extr.negated || subextr.negated)
                  }
                  else {
                    // the nested extraction has a different arg1
                    SrlExtraction(subextr.relation, subextr.arg1, subextr.arg2s, Some(combinedContext), subextr.negated)
                  }
                }
            })
          case None => Seq.empty
        }
      }
    }

    rec(frameh)
  }
}

{'repo_name': 'allenai/openie-standalone', 'stars': '306', 'repo_language': 'Scala', 'file_name': 'publish.sh', 'mime_type': 'text/x-shellscript', 'hash': -3889524108818456221, 'source_dataset': 'data'}


/*
  ==============================================================================

   This file is part of the juce_core module of the JUCE library.
   Copyright (c) 2015 - ROLI Ltd.

   Permission to use, copy, modify, and/or distribute this software for any purpose with
   or without fee is hereby granted, provided that the above copyright notice and this
   permission notice appear in all copies.

   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
   TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
   NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
   DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
   IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

   ------------------------------------------------------------------------------

   NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
   All other JUCE modules are covered by a dual GPL/commercial license, so if you are
   using any other modules, be sure to check that you also comply with their license.

   For more details, visit www.juce.com

  ==============================================================================
*/

#ifndef JUCE_BYTEORDER_H_INCLUDED
#define JUCE_BYTEORDER_H_INCLUDED

//==============================================================================
/** Contains static methods for converting the byte order between different
    endiannesses.
*/
class JUCE_API  ByteOrder
{
public:
    //==============================================================================
    /** Swaps the upper and lower bytes of a 16-bit integer. */
    static uint16 swap (uint16 value) noexcept;

    /** Reverses the order of the 4 bytes in a 32-bit integer. */
    static uint32 swap (uint32 value) noexcept;

    /** Reverses the order of the 8 bytes in a 64-bit integer. */
    static uint64 swap (uint64 value) noexcept;

    //==============================================================================
    /** Swaps the byte order of a 16-bit unsigned int if the CPU is big-endian */
    static uint16 swapIfBigEndian (uint16 value) noexcept;

    /** Swaps the byte order of a 32-bit unsigned int if the CPU is big-endian */
    static uint32 swapIfBigEndian (uint32 value) noexcept;

    /** Swaps the byte order of a 64-bit unsigned int if the CPU is big-endian */
    static uint64 swapIfBigEndian (uint64 value) noexcept;

    /** Swaps the byte order of a 16-bit signed int if the CPU is big-endian */
    static int16 swapIfBigEndian (int16 value) noexcept;

    /** Swaps the byte order of a 32-bit signed int if the CPU is big-endian */
    static int32 swapIfBigEndian (int32 value) noexcept;

    /** Swaps the byte order of a 64-bit signed int if the CPU is big-endian */
    static int64 swapIfBigEndian (int64 value) noexcept;

    /** Swaps the byte order of a 32-bit float if the CPU is big-endian */
    static float swapIfBigEndian (float value) noexcept;

    /** Swaps the byte order of a 64-bit float if the CPU is big-endian */
    static double swapIfBigEndian (double value) noexcept;

    /** Swaps the byte order of a 16-bit unsigned int if the CPU is little-endian */
    static uint16 swapIfLittleEndian (uint16 value) noexcept;

    /** Swaps the byte order of a 32-bit unsigned int if the CPU is little-endian */
    static uint32 swapIfLittleEndian (uint32 value) noexcept;

    /** Swaps the byte order of a 64-bit unsigned int if the CPU is little-endian */
    static uint64 swapIfLittleEndian (uint64 value) noexcept;

    /** Swaps the byte order of a 16-bit signed int if the CPU is little-endian */
    static int16 swapIfLittleEndian (int16 value) noexcept;

    /** Swaps the byte order of a 32-bit signed int if the CPU is little-endian */
    static int32 swapIfLittleEndian (int32 value) noexcept;

    /** Swaps the byte order of a 64-bit signed int if the CPU is little-endian */
    static int64 swapIfLittleEndian (int64 value) noexcept;

    /** Swaps the byte order of a 32-bit float if the CPU is little-endian */
    static float swapIfLittleEndian (float value) noexcept;

    /** Swaps the byte order of a 64-bit float if the CPU is little-endian */
    static double swapIfLittleEndian (double value) noexcept;

    //==============================================================================
    /** Turns 4 bytes into a little-endian integer. */
    static uint32 littleEndianInt (const void* bytes) noexcept;

    /** Turns 8 bytes into a little-endian integer. */
    static uint64 littleEndianInt64 (const void* bytes) noexcept;

    /** Turns 2 bytes into a little-endian integer. */
    static uint16 littleEndianShort (const void* bytes) noexcept;

    /** Turns 4 bytes into a big-endian integer. */
    static uint32 bigEndianInt (const void* bytes) noexcept;

    /** Turns 8 bytes into a big-endian integer. */
    static uint64 bigEndianInt64 (const void* bytes) noexcept;

    /** Turns 2 bytes into a big-endian integer. */
    static uint16 bigEndianShort (const void* bytes) noexcept;

    //==============================================================================
    /** Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */
    static int littleEndian24Bit (const void* bytes) noexcept;

    /** Converts 3 big-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */
    static int bigEndian24Bit (const void* bytes) noexcept;

    /** Copies a 24-bit number to 3 little-endian bytes. */
    static void littleEndian24BitToChars (int value, void* destBytes) noexcept;

    /** Copies a 24-bit number to 3 big-endian bytes. */
    static void bigEndian24BitToChars (int value, void* destBytes) noexcept;

    //==============================================================================
    /** Returns true if the current CPU is big-endian. */
    static bool isBigEndian() noexcept;

private:
    ByteOrder() JUCE_DELETED_FUNCTION;

    JUCE_DECLARE_NON_COPYABLE (ByteOrder)
};

//==============================================================================
#if JUCE_USE_MSVC_INTRINSICS && ! defined (__INTEL_COMPILER)
 #pragma intrinsic (_byteswap_ulong)
#endif

inline uint16 ByteOrder::swap (uint16 n) noexcept
{
   #if JUCE_USE_MSVC_INTRINSICSxxx // agh - the MS compiler has an internal error when you try to use this intrinsic!
    return static_cast<uint16> (_byteswap_ushort (n));
   #else
    return static_cast<uint16> ((n << 8) | (n >> 8));
   #endif
}

inline uint32 ByteOrder::swap (uint32 n) noexcept
{
   #if JUCE_MAC || JUCE_IOS
    return OSSwapInt32 (n);
   #elif JUCE_GCC && JUCE_INTEL && ! JUCE_NO_INLINE_ASM
    asm("bswap %%eax" : "=a"(n) : "a"(n));
    return n;
   #elif JUCE_USE_MSVC_INTRINSICS
    return _byteswap_ulong (n);
   #elif JUCE_MSVC && ! JUCE_NO_INLINE_ASM
    __asm {
        mov eax, n
        bswap eax
        mov n, eax
    }
    return n;
   #elif JUCE_ANDROID
    return bswap_32 (n);
   #else
    return (n << 24) | (n >> 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8);
   #endif
}

inline uint64 ByteOrder::swap (uint64 value) noexcept
{
   #if JUCE_MAC || JUCE_IOS
    return OSSwapInt64 (value);
   #elif JUCE_USE_MSVC_INTRINSICS
    return _byteswap_uint64 (value);
   #else
    return (((uint64) swap ((uint32) value)) << 32) | swap ((uint32) (value >> 32));
   #endif
}

#if JUCE_LITTLE_ENDIAN
 inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) noexcept                                  { return v; }
 inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) noexcept                                  { return v; }
 inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) noexcept                                  { return v; }
 inline int16 ByteOrder::swapIfBigEndian (const int16 v) noexcept                                    { return v; }
 inline int32 ByteOrder::swapIfBigEndian (const int32 v) noexcept                                    { return v; }
 inline int64 ByteOrder::swapIfBigEndian (const int64 v) noexcept                                    { return v; }
 inline float ByteOrder::swapIfBigEndian (const float v) noexcept                                    { return v; }
 inline double ByteOrder::swapIfBigEndian (const double v) noexcept                                  { return v; }

 inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) noexcept                               { return swap (v); }
 inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) noexcept                               { return swap (v); }
 inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) noexcept                               { return swap (v); }
 inline int16 ByteOrder::swapIfLittleEndian (const int16 v) noexcept                                 { return static_cast<int16> (swap (static_cast<uint16> (v))); }
 inline int32 ByteOrder::swapIfLittleEndian (const int32 v) noexcept                                 { return static_cast<int32> (swap (static_cast<uint32> (v))); }
 inline int64 ByteOrder::swapIfLittleEndian (const int64 v) noexcept                                 { return static_cast<int64> (swap (static_cast<uint64> (v))); }
inline float ByteOrder::swapIfLittleEndian (const float v) noexcept                                  { union { uint32 asUInt; float asFloat;  } n; n.asFloat = v; n.asUInt = ByteOrder::swap (n.asUInt); return n.asFloat; }
 inline double ByteOrder::swapIfLittleEndian (const double v) noexcept                               { union { uint64 asUInt; double asFloat; } n; n.asFloat = v; n.asUInt = ByteOrder::swap (n.asUInt); return n.asFloat; }

 inline uint32 ByteOrder::littleEndianInt (const void* const bytes) noexcept                         { return *static_cast<const uint32*> (bytes); }
 inline uint64 ByteOrder::littleEndianInt64 (const void* const bytes) noexcept                       { return *static_cast<const uint64*> (bytes); }
 inline uint16 ByteOrder::littleEndianShort (const void* const bytes) noexcept                       { return *static_cast<const uint16*> (bytes); }
 inline uint32 ByteOrder::bigEndianInt (const void* const bytes) noexcept                            { return swap (*static_cast<const uint32*> (bytes)); }
 inline uint64 ByteOrder::bigEndianInt64 (const void* const bytes) noexcept                          { return swap (*static_cast<const uint64*> (bytes)); }
 inline uint16 ByteOrder::bigEndianShort (const void* const bytes) noexcept                          { return swap (*static_cast<const uint16*> (bytes)); }
 inline bool ByteOrder::isBigEndian() noexcept                                                       { return false; }
#else
 inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) noexcept                                  { return swap (v); }
 inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) noexcept                                  { return swap (v); }
 inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) noexcept                                  { return swap (v); }
 inline int16 ByteOrder::swapIfBigEndian (const int16 v) noexcept                                    { return static_cast<int16> (swap (static_cast<uint16> (v))); }
 inline int32 ByteOrder::swapIfBigEndian (const int32 v) noexcept                                    { return static_cast<int16> (swap (static_cast<uint16> (v))); }
 inline int64 ByteOrder::swapIfBigEndian (const int64 v) noexcept                                    { return static_cast<int16> (swap (static_cast<uint16> (v))); }
 inline float ByteOrder::swapIfBigEndian (const float v) noexcept                                    { union { uint32 asUInt; float asFloat;  } n; n.asFloat = v; n.asUInt = ByteOrder::swap (n.asUInt); return n.asFloat; }
 inline double ByteOrder::swapIfBigEndian (const double v) noexcept                                  { union { uint64 asUInt; double asFloat; } n; n.asFloat = v; n.asUInt = ByteOrder::swap (n.asUInt); return n.asFloat; }

 inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) noexcept                               { return v; }
 inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) noexcept                               { return v; }
 inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) noexcept                               { return v; }
 inline int16 ByteOrder::swapIfLittleEndian (const int16 v) noexcept                                 { return v; }
 inline int32 ByteOrder::swapIfLittleEndian (const int32 v) noexcept                                 { return v; }
 inline int64 ByteOrder::swapIfLittleEndian (const int64 v) noexcept                                 { return v; }
 inline float ByteOrder::swapIfLittleEndian (const float v) noexcept                                 { return v; }
 inline double ByteOrder::swapIfLittleEndian (const double v) noexcept                               { return v; }

 inline uint32 ByteOrder::littleEndianInt (const void* const bytes) noexcept                         { return swap (*static_cast<const uint32*> (bytes)); }
 inline uint64 ByteOrder::littleEndianInt64 (const void* const bytes) noexcept                       { return swap (*static_cast<const uint64*> (bytes)); }
 inline uint16 ByteOrder::littleEndianShort (const void* const bytes) noexcept                       { return swap (*static_cast<const uint16*> (bytes)); }
 inline uint32 ByteOrder::bigEndianInt (const void* const bytes) noexcept                            { return *static_cast<const uint32*> (bytes); }
 inline uint64 ByteOrder::bigEndianInt64 (const void* const bytes) noexcept                          { return *static_cast<const uint64*> (bytes); }
 inline uint16 ByteOrder::bigEndianShort (const void* const bytes) noexcept                          { return *static_cast<const uint16*> (bytes); }
 inline bool ByteOrder::isBigEndian() noexcept                                                       { return true; }
#endif

inline int  ByteOrder::littleEndian24Bit (const void* const bytes) noexcept                          { return (((int) static_cast<const int8*> (bytes)[2]) << 16) | (((int) static_cast<const uint8*> (bytes)[1]) << 8) | ((int) static_cast<const uint8*> (bytes)[0]); }
inline int  ByteOrder::bigEndian24Bit (const void* const bytes) noexcept                             { return (((int) static_cast<const int8*> (bytes)[0]) << 16) | (((int) static_cast<const uint8*> (bytes)[1]) << 8) | ((int) static_cast<const uint8*> (bytes)[2]); }
inline void ByteOrder::littleEndian24BitToChars (const int value, void* const destBytes) noexcept    { static_cast<uint8*> (destBytes)[0] = (uint8) value;         static_cast<uint8*> (destBytes)[1] = (uint8) (value >> 8); static_cast<uint8*> (destBytes)[2] = (uint8) (value >> 16); }
inline void ByteOrder::bigEndian24BitToChars (const int value, void* const destBytes) noexcept       { static_cast<uint8*> (destBytes)[0] = (uint8) (value >> 16); static_cast<uint8*> (destBytes)[1] = (uint8) (value >> 8); static_cast<uint8*> (destBytes)[2] = (uint8) value; }

#endif   // JUCE_BYTEORDER_H_INCLUDED

{'repo_name': 'peersuasive/luce', 'stars': '115', 'repo_language': 'C++', 'file_name': 'juce_linux_BluetoothMidiDevicePairingDialogue.cpp', 'mime_type': 'text/plain', 'hash': -8533665632555464923, 'source_dataset': 'data'}


/*** ESSENTIAL STYLES ***/
.sf-menu, .sf-menu * {
	margin: 0;
	padding: 0;
	list-style: none;
}
.sf-menu li {
	position: relative;
}
.sf-menu ul {
	position: absolute;
	display: none;
	top: 100%;
	left: 0;
	z-index: 99;
}
.sf-menu > li {
	float: left;
}
.sf-menu li:hover > ul,
.sf-menu li.sfHover > ul {
	display: block;
}

.sf-menu a {
	display: block;
	position: relative;
}
.sf-menu ul ul {
	top: 0;
	left: 100%;
}

/*** DEMO SKIN ***/
.sf-menu {
	float: left;
	margin-bottom: 1em;
}
.sf-menu ul {
	box-shadow: 2px 2px 6px rgba(0,0,0,.2);
	min-width: 12em; /* allow long menu items to determine submenu width */
	*width: 12em; /* no auto sub width for IE7, see white-space comment below */
}
.sf-menu a {
	border-left: 1px solid #fff;
	border-top: 1px solid #dFeEFF; /* fallback colour must use full shorthand */
	border-top: 1px solid rgba(255,255,255,.5);
	padding: .75em 1em;
	text-decoration: none;
	zoom: 1; /* IE7 */
}
.sf-menu a {
	color: #13a;
}
.sf-menu li {
	background: #BDD2FF;
	white-space: nowrap; /* no need for Supersubs plugin */
	*white-space: normal; /* ...unless you support IE7 (let it wrap) */
	-webkit-transition: background .2s;
	transition: background .2s;
}
.sf-menu ul li {
	background: #AABDE6;
}
.sf-menu ul ul li {
	background: #9AAEDB;
}
.sf-menu li:hover,
.sf-menu li.sfHover {
	background: #CFDEFF;
	/* only transition out, not in */
	-webkit-transition: none;
	transition: none;
}

/*** arrows (for all except IE7) **/
.sf-arrows .sf-with-ul {
	padding-right: 2.5em;
	*padding-right: 1em; /* no CSS arrows for IE7 (lack pseudo-elements) */
}
/* styling for both css and generated arrows */
.sf-arrows .sf-with-ul:after {
	content: '';
	position: absolute;
	top: 50%;
	right: 1em;
	margin-top: -3px;
	height: 0;
	width: 0;
	/* order of following 3 rules important for fallbacks to work */
	border: 5px solid transparent;
	border-top-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
	border-top-color: rgba(255,255,255,.5);
}
.sf-arrows > li > .sf-with-ul:focus:after,
.sf-arrows > li:hover > .sf-with-ul:after,
.sf-arrows > .sfHover > .sf-with-ul:after {
	border-top-color: white; /* IE8 fallback colour */
}
/* styling for right-facing arrows */
.sf-arrows ul .sf-with-ul:after {
	margin-top: -5px;
	margin-right: -3px;
	border-color: transparent;
	border-left-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
	border-left-color: rgba(255,255,255,.5);
}
.sf-arrows ul li > .sf-with-ul:focus:after,
.sf-arrows ul li:hover > .sf-with-ul:after,
.sf-arrows ul .sfHover > .sf-with-ul:after {
	border-left-color: white;
}

{'repo_name': 'crits/crits', 'stars': '721', 'repo_language': 'JavaScript', 'file_name': 'jquery.colorhelpers.js', 'mime_type': 'text/plain', 'hash': 3296491003711851826, 'source_dataset': 'data'}


#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Spaghetti: Web Server Security Scanner
#
# @url: https://github.com/m4ll0k/Spaghetti
# @author: Momo Outaadi (M4ll0k)
# @license: See the file 'doc/LICENSE'

import AdminInterfaces
import AllowMethod
import ApacheUsers
import ApacheXss
import Backdoor
import Backup
import Captcha
import ClientAccessPolicy
import CommonDirectory
import CommonFile
import Cookie
import HtmlObject
import LDAPInjection
import ModStatus
import Email
import MultiIndex
import PrivateIP
import Robots

def All(url,agent,proxy,redirect):
	Cookie.Cookie(url,agent,proxy,redirect).Run()
	AllowMethod.AllowMethod(url,agent,proxy,redirect).Run()
	Robots.Robots(url,agent,proxy,redirect).Run()
	ClientAccessPolicy.ClientAccessPolicy(url,agent,proxy,redirect).Run()
	PrivateIP.PrivateIP(url,agent,proxy,redirect).Run()
	Email.Email(url,agent,proxy,redirect).Run()
	MultiIndex.MultiIndex(url,agent,proxy,redirect).Run()
	Captcha.Captcha(url,agent,proxy,redirect).Run()
	ApacheUsers.ApacheUsers(url,agent,proxy,redirect).Run()
	ApacheXss.ApacheXss(url,agent,proxy,redirect).Run()
	HtmlObject.HtmlObject(url,agent,proxy,redirect).Run()
	LDAPInjection.LDAPInjection(url,agent,proxy,redirect).Run()
	ModStatus.ModStatus(url,agent,proxy,redirect).Run()
	AdminInterfaces.AdminInterfaces(url,agent,proxy,redirect).Run()
	Backdoor.Backdoors(url,agent,proxy,redirect).Run()
	Backup.Backup(url,agent,proxy,redirect).Run()
	CommonDirectory.CommonDirectory(url,agent,proxy,redirect).Run()
	CommonFile.CommonFile(url,agent,proxy,redirect).Run()

def AdminInterface(url,agent,proxy,redirect):
	AdminInterfaces.AdminInterfaces(url,agent,proxy,redirect).Run()

def Misconfiguration(url,agent,proxy,redirect):
	MultiIndex.MultiIndex(url,agent,proxy,redirect).Run()
	ModStatus.ModStatus(url,agent,proxy,redirect).Run()
	Backdoor.Backdoors(url,agent,proxy,redirect).Run()
	Backup.Backup(url,agent,proxy,redirect).Run()
	CommonDirectory.CommonDirectory(url,agent,proxy,redirect).Run()
	CommonFile.CommonFile(url,agent,proxy,redirect).Run()

def InfoDisclosure(url,agent,proxy,redirect):
	Robots.Robots(url,agent,proxy,redirect).Run()
	ClientAccessPolicy.ClientAccessPolicy(url,agent,proxy,redirect).Run()
	PrivateIP.PrivateIP(url,agent,proxy,redirect).Run()
	Email.Email(url,agent,proxy,redirect).Run()

{'repo_name': 'pikpikcu/Pentest-Tools-Framework', 'stars': '143', 'repo_language': 'Python', 'file_name': '__init__.py', 'mime_type': 'text/x-python', 'hash': 1601527496477570752, 'source_dataset': 'data'}


// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_VALUE_STORE_VALUE_STORE_UNITTEST_H_
#define CHROME_BROWSER_VALUE_STORE_VALUE_STORE_UNITTEST_H_

#include "testing/gtest/include/gtest/gtest.h"

#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/value_store/value_store.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"

// Parameter type for the value-parameterized tests.
typedef ValueStore* (*ValueStoreTestParam)(const base::FilePath& file_path);

// Test fixture for ValueStore tests.  Tests are defined in
// settings_storage_unittest.cc with configurations for both cached
// and non-cached leveldb storage, and cached no-op storage.
class ValueStoreTest : public testing::TestWithParam<ValueStoreTestParam> {
 public:
  ValueStoreTest();
  virtual ~ValueStoreTest();

  virtual void SetUp() OVERRIDE;
  virtual void TearDown() OVERRIDE;

 protected:
  scoped_ptr<ValueStore> storage_;

  std::string key1_;
  std::string key2_;
  std::string key3_;

  scoped_ptr<base::Value> val1_;
  scoped_ptr<base::Value> val2_;
  scoped_ptr<base::Value> val3_;

  std::vector<std::string> empty_list_;
  std::vector<std::string> list1_;
  std::vector<std::string> list2_;
  std::vector<std::string> list3_;
  std::vector<std::string> list12_;
  std::vector<std::string> list13_;
  std::vector<std::string> list123_;

  std::set<std::string> empty_set_;
  std::set<std::string> set1_;
  std::set<std::string> set2_;
  std::set<std::string> set3_;
  std::set<std::string> set12_;
  std::set<std::string> set13_;
  std::set<std::string> set123_;

  scoped_ptr<base::DictionaryValue> empty_dict_;
  scoped_ptr<base::DictionaryValue> dict1_;
  scoped_ptr<base::DictionaryValue> dict3_;
  scoped_ptr<base::DictionaryValue> dict12_;
  scoped_ptr<base::DictionaryValue> dict123_;

 private:
  base::ScopedTempDir temp_dir_;

  // Need these so that the DCHECKs for running on FILE or UI threads pass.
  base::MessageLoop message_loop_;
  content::TestBrowserThread ui_thread_;
  content::TestBrowserThread file_thread_;
};

#endif  // CHROME_BROWSER_VALUE_STORE_VALUE_STORE_UNITTEST_H_

{'repo_name': 'ChromiumWebApps/chromium', 'stars': '184', 'repo_language': 'C++', 'file_name': 'content_setting_media_menu_model.cc', 'mime_type': 'text/x-c', 'hash': -2045047665971110528, 'source_dataset': 'data'}


[InternetShortcut]
URL=http://www.freertos.org/trace
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2

{'repo_name': 'istarc/stm32', 'stars': '141', 'repo_language': 'C', 'file_name': 'Makefile-lib', 'mime_type': 'text/x-makefile', 'hash': 95631887232400529, 'source_dataset': 'data'}


---
udver: '2'
layout: relation
title: 'cop'
shortdef: 'copula'
---

A `cop` (copula) is the relation of a function word used to link a subject to a nonverbal predicate. UD generally only annotates forms of "to be" as cop, which in German would be the forms of the verb "sein". More about copula in UD can be found on the main documentation page for [cop]() or [here](https://universaldependencies.org/v2/copula.html#guidelines-for-udv2).

~~~ sdparse
Er ist ein guter Student . \n He is a good student .
cop(Student, ist)
cop(student, is)
~~~

~~~ sdparse
Alles wird besser sein . \n Everything will be better .
aux(besser, wird)
cop(besser, sein)
aux(better, will)
cop(better, be)
~~~

Note that the verbs sein and werden can be also used as full verbs. Examples for that case can be found under the `nsubj` relation.

{'repo_name': 'UniversalDependencies/docs', 'stars': '176', 'repo_language': 'HTML', 'file_name': 'template-index.md', 'mime_type': 'text/plain', 'hash': -7493579892914101897, 'source_dataset': 'data'}


/*****************************************************************************
 * Author:   Valient Gough <vgough@pobox.com>
 *
 *****************************************************************************
 * Copyright (c) 2004, Valient Gough
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "FileIO.h"

FileIO::FileIO()
{
}

FileIO::~FileIO()
{
}

int FileIO::blockSize() const
{
    return 1;
}

bool FileIO::setIV( uint64_t iv )
{
    (void)iv;
    return true;
}

{'repo_name': 'neurodroid/cryptonite', 'stars': '185', 'repo_language': 'C', 'file_name': 'build.sh', 'mime_type': 'text/x-shellscript', 'hash': 5312754873190711064, 'source_dataset': 'data'}


/*
 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include "eng_int.h"

/* Basic get/set stuff */

int ENGINE_set_load_privkey_function(ENGINE *e,
                                     ENGINE_LOAD_KEY_PTR loadpriv_f)
{
    e->load_privkey = loadpriv_f;
    return 1;
}

int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
{
    e->load_pubkey = loadpub_f;
    return 1;
}

int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
                                             ENGINE_SSL_CLIENT_CERT_PTR
                                             loadssl_f)
{
    e->load_ssl_client_cert = loadssl_f;
    return 1;
}

ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
{
    return e->load_privkey;
}

ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
{
    return e->load_pubkey;
}

ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE
                                                               *e)
{
    return e->load_ssl_client_cert;
}

/* API functions to load public/private keys */

EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
                                  UI_METHOD *ui_method, void *callback_data)
{
    EVP_PKEY *pkey;

    if (e == NULL) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
                  ERR_R_PASSED_NULL_PARAMETER);
        return 0;
    }
    CRYPTO_THREAD_write_lock(global_engine_lock);
    if (e->funct_ref == 0) {
        CRYPTO_THREAD_unlock(global_engine_lock);
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, ENGINE_R_NOT_INITIALISED);
        return 0;
    }
    CRYPTO_THREAD_unlock(global_engine_lock);
    if (!e->load_privkey) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
                  ENGINE_R_NO_LOAD_FUNCTION);
        return 0;
    }
    pkey = e->load_privkey(e, key_id, ui_method, callback_data);
    if (!pkey) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
                  ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
        return 0;
    }
    return pkey;
}

EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
                                 UI_METHOD *ui_method, void *callback_data)
{
    EVP_PKEY *pkey;

    if (e == NULL) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
                  ERR_R_PASSED_NULL_PARAMETER);
        return 0;
    }
    CRYPTO_THREAD_write_lock(global_engine_lock);
    if (e->funct_ref == 0) {
        CRYPTO_THREAD_unlock(global_engine_lock);
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NOT_INITIALISED);
        return 0;
    }
    CRYPTO_THREAD_unlock(global_engine_lock);
    if (!e->load_pubkey) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NO_LOAD_FUNCTION);
        return 0;
    }
    pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
    if (!pkey) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
                  ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
        return 0;
    }
    return pkey;
}

int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
                                STACK_OF(X509_NAME) *ca_dn, X509 **pcert,
                                EVP_PKEY **ppkey, STACK_OF(X509) **pother,
                                UI_METHOD *ui_method, void *callback_data)
{

    if (e == NULL) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
                  ERR_R_PASSED_NULL_PARAMETER);
        return 0;
    }
    CRYPTO_THREAD_write_lock(global_engine_lock);
    if (e->funct_ref == 0) {
        CRYPTO_THREAD_unlock(global_engine_lock);
        ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
                  ENGINE_R_NOT_INITIALISED);
        return 0;
    }
    CRYPTO_THREAD_unlock(global_engine_lock);
    if (!e->load_ssl_client_cert) {
        ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
                  ENGINE_R_NO_LOAD_FUNCTION);
        return 0;
    }
    return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
                                   ui_method, callback_data);
}

{'repo_name': 'versatica/mediasoup', 'stars': '2327', 'repo_language': 'C++', 'file_name': 'VP8.hpp', 'mime_type': 'text/x-c++', 'hash': -5493169462403635130, 'source_dataset': 'data'}


/*MIT License

C++ 3D Game Tutorial Series (https://github.com/PardCode/CPP-3D-Game-Tutorial-Series)

Copyright (c) 2019-2020, PardCode

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/

#include "PixelShader.h"
#include "RenderSystem.h"
#include <exception>

PixelShader::PixelShader(const void* shader_byte_code, size_t byte_code_size,RenderSystem * system) : m_system(system)
{
	if (!SUCCEEDED(m_system->m_d3d_device->CreatePixelShader(shader_byte_code, byte_code_size, nullptr, &m_ps)))
		throw std::exception("PixelShader not created successfully");
}

PixelShader::~PixelShader()
{
	m_ps->Release();
}

{'repo_name': 'PardCode/CPP-3D-Game-Tutorial-Series', 'stars': '258', 'repo_language': 'C++', 'file_name': 'AppWindow.h', 'mime_type': 'text/x-c++', 'hash': 6988026150417960849, 'source_dataset': 'data'}


#%RAML 1.0
title: Enums create String.java source file
types:
  Bus:
    type: object
    properties:
      metadata:
        type: array
        items:
          enum: [ac, multi-axle, reading-light, sleeper]

/bus:
  get:
    description: Get a bus.
    responses:
      200:
        body:
          application/json:
            type: Bus

{'repo_name': 'phoenixnap/springmvc-raml-plugin', 'stars': '136', 'repo_language': 'Java', 'file_name': 'UnionTypeInterpretorTest.java', 'mime_type': 'text/x-java', 'hash': -4671165472048418073, 'source_dataset': 'data'}


/**
 * A specialized version of `_.forEach` for arrays without support for callback
 * shorthands or `this` binding.
 *
 * @private
 * @param {Array} array The array to iterate over.
 * @param {Function} iteratee The function invoked per iteration.
 * @returns {Array} Returns `array`.
 */
function arrayEach(array, iteratee) {
  var index = -1,
      length = array.length;

  while (++index < length) {
    if (iteratee(array[index], index, array) === false) {
      break;
    }
  }
  return array;
}

module.exports = arrayEach;

{'repo_name': 'notepadqq/notepadqq', 'stars': '1417', 'repo_language': 'C++', 'file_name': 'pre-commit', 'mime_type': 'text/x-shellscript', 'hash': 2544394504799879231, 'source_dataset': 'data'}


package org.bouncycastle.pqc.math.linearalgebra;

import java.math.BigInteger;
import java.security.SecureRandom;

/**
 * Class of number-theory related functions for use with integers represented as
 * <tt>int</tt>'s or <tt>BigInteger</tt> objects.
 */
public final class IntegerFunctions
{

    private static final BigInteger ZERO = BigInteger.valueOf(0);

    private static final BigInteger ONE = BigInteger.valueOf(1);

    private static final BigInteger TWO = BigInteger.valueOf(2);

    private static final BigInteger FOUR = BigInteger.valueOf(4);

    private static final int[] SMALL_PRIMES = {3, 5, 7, 11, 13, 17, 19, 23,
        29, 31, 37, 41};

    private static final long SMALL_PRIME_PRODUCT = 3L * 5 * 7 * 11 * 13 * 17
        * 19 * 23 * 29 * 31 * 37 * 41;

    private static SecureRandom sr = null;

    // the jacobi function uses this lookup table
    private static final int[] jacobiTable = {0, 1, 0, -1, 0, -1, 0, 1};

    private IntegerFunctions()
    {
        // empty
    }

    /**
     * Computes the value of the Jacobi symbol (A|B). The following properties
     * hold for the Jacobi symbol which makes it a very efficient way to
     * evaluate the Legendre symbol
     *

     * (A|B) = 0 IF gcd(A,B) > 1

     * (-1|B) = 1 IF n = 1 (mod 1)

     * (-1|B) = -1 IF n = 3 (mod 4)

     * (A|B) (C|B) = (AC|B)

     * (A|B) (A|C) = (A|CB)

     * (A|B) = (C|B) IF A = C (mod B)

     * (2|B) = 1 IF N = 1 OR 7 (mod 8)

     * (2|B) = 1 IF N = 3 OR 5 (mod 8)
     *
     * @param A integer value
     * @param B integer value
     * @return value of the jacobi symbol (A|B)
     */
    public static int jacobi(BigInteger A, BigInteger B)
    {
        BigInteger a, b, v;
        long k = 1;

        k = 1;

        // test trivial cases
        if (B.equals(ZERO))
        {
            a = A.abs();
            return a.equals(ONE) ? 1 : 0;
        }

        if (!A.testBit(0) && !B.testBit(0))
        {
            return 0;
        }

        a = A;
        b = B;

        if (b.signum() == -1)
        { // b < 0
            b = b.negate(); // b = -b
            if (a.signum() == -1)
            {
                k = -1;
            }
        }

        v = ZERO;
        while (!b.testBit(0))
        {
            v = v.add(ONE); // v = v + 1
            b = b.divide(TWO); // b = b/2
        }

        if (v.testBit(0))
        {
            k = k * jacobiTable[a.intValue() & 7];
        }

        if (a.signum() < 0)
        { // a < 0
            if (b.testBit(1))
            {
                k = -k; // k = -k
            }
            a = a.negate(); // a = -a
        }

        // main loop
        while (a.signum() != 0)
        {
            v = ZERO;
            while (!a.testBit(0))
            { // a is even
                v = v.add(ONE);
                a = a.divide(TWO);
            }
            if (v.testBit(0))
            {
                k = k * jacobiTable[b.intValue() & 7];
            }

            if (a.compareTo(b) < 0)
            { // a < b
                // swap and correct intermediate result
                BigInteger x = a;
                a = b;
                b = x;
                if (a.testBit(1) && b.testBit(1))
                {
                    k = -k;
                }
            }
            a = a.subtract(b);
        }

        return b.equals(ONE) ? (int)k : 0;
    }

    /**
     * Computes the square root of a BigInteger modulo a prime employing the
     * Shanks-Tonelli algorithm.
     *
     * @param a value out of which we extract the square root
     * @param p prime modulus that determines the underlying field
     * @return a number <tt>b</tt> such that b2 = a (mod p) if
     *         <tt>a</tt> is a quadratic residue modulo <tt>p</tt>.
     * @throws NoQuadraticResidueException if <tt>a</tt> is a quadratic non-residue modulo <tt>p</tt>
     */
    public static BigInteger ressol(BigInteger a, BigInteger p)
        throws IllegalArgumentException
    {

        BigInteger v = null;

        if (a.compareTo(ZERO) < 0)
        {
            a = a.add(p);
        }

        if (a.equals(ZERO))
        {
            return ZERO;
        }

        if (p.equals(TWO))
        {
            return a;
        }

        // p = 3 mod 4
        if (p.testBit(0) && p.testBit(1))
        {
            if (jacobi(a, p) == 1)
            { // a quadr. residue mod p
                v = p.add(ONE); // v = p+1
                v = v.shiftRight(2); // v = v/4
                return a.modPow(v, p); // return a^v mod p
                // return --> a^((p+1)/4) mod p
            }
            throw new IllegalArgumentException("No quadratic residue: " + a + ", " + p);
        }

        long t = 0;

        // initialization
        // compute k and s, where p = 2^s (2k+1) +1

        BigInteger k = p.subtract(ONE); // k = p-1
        long s = 0;
        while (!k.testBit(0))
        { // while k is even
            s++; // s = s+1
            k = k.shiftRight(1); // k = k/2
        }

        k = k.subtract(ONE); // k = k - 1
        k = k.shiftRight(1); // k = k/2

        // initial values
        BigInteger r = a.modPow(k, p); // r = a^k mod p

        BigInteger n = r.multiply(r).remainder(p); // n = r^2 % p
        n = n.multiply(a).remainder(p); // n = n * a % p
        r = r.multiply(a).remainder(p); // r = r * a %p

        if (n.equals(ONE))
        {
            return r;
        }

        // non-quadratic residue
        BigInteger z = TWO; // z = 2
        while (jacobi(z, p) == 1)
        {
            // while z quadratic residue
            z = z.add(ONE); // z = z + 1
        }

        v = k;
        v = v.multiply(TWO); // v = 2k
        v = v.add(ONE); // v = 2k + 1
        BigInteger c = z.modPow(v, p); // c = z^v mod p

        // iteration
        while (n.compareTo(ONE) == 1)
        { // n > 1
            k = n; // k = n
            t = s; // t = s
            s = 0;

            while (!k.equals(ONE))
            { // k != 1
                k = k.multiply(k).mod(p); // k = k^2 % p
                s++; // s = s + 1
            }

            t -= s; // t = t - s
            if (t == 0)
            {
                throw new IllegalArgumentException("No quadratic residue: " + a + ", " + p);
            }

            v = ONE;
            for (long i = 0; i < t - 1; i++)
            {
                v = v.shiftLeft(1); // v = 1 * 2^(t - 1)
            }
            c = c.modPow(v, p); // c = c^v mod p
            r = r.multiply(c).remainder(p); // r = r * c % p
            c = c.multiply(c).remainder(p); // c = c^2 % p
            n = n.multiply(c).mod(p); // n = n * c % p
        }
        return r;
    }

    /**
     * Computes the greatest common divisor of the two specified integers
     *
     * @param u - first integer
     * @param v - second integer
     * @return gcd(a, b)
     */
    public static int gcd(int u, int v)
    {
        return BigInteger.valueOf(u).gcd(BigInteger.valueOf(v)).intValue();
    }

    /**
     * Extended euclidian algorithm (computes gcd and representation).
     *
     * @param a the first integer
     * @param b the second integer
     * @return <tt>(g,u,v)</tt>, where <tt>g = gcd(abs(a),abs(b)) = ua + vb</tt>
     */
    public static int[] extGCD(int a, int b)
    {
        BigInteger ba = BigInteger.valueOf(a);
        BigInteger bb = BigInteger.valueOf(b);
        BigInteger[] bresult = extgcd(ba, bb);
        int[] result = new int[3];
        result[0] = bresult[0].intValue();
        result[1] = bresult[1].intValue();
        result[2] = bresult[2].intValue();
        return result;
    }

    public static BigInteger divideAndRound(BigInteger a, BigInteger b)
    {
        if (a.signum() < 0)
        {
            return divideAndRound(a.negate(), b).negate();
        }
        if (b.signum() < 0)
        {
            return divideAndRound(a, b.negate()).negate();
        }
        return a.shiftLeft(1).add(b).divide(b.shiftLeft(1));
    }

    public static BigInteger[] divideAndRound(BigInteger[] a, BigInteger b)
    {
        BigInteger[] out = new BigInteger[a.length];
        for (int i = 0; i < a.length; i++)
        {
            out[i] = divideAndRound(a[i], b);
        }
        return out;
    }

    /**
     * Compute the smallest integer that is greater than or equal to the
     * logarithm to the base 2 of the given BigInteger.
     *
     * @param a the integer
     * @return ceil[log(a)]
     */
    public static int ceilLog(BigInteger a)
    {
        int result = 0;
        BigInteger p = ONE;
        while (p.compareTo(a) < 0)
        {
            result++;
            p = p.shiftLeft(1);
        }
        return result;
    }

    /**
     * Compute the smallest integer that is greater than or equal to the
     * logarithm to the base 2 of the given integer.
     *
     * @param a the integer
     * @return ceil[log(a)]
     */
    public static int ceilLog(int a)
    {
        int log = 0;
        int i = 1;
        while (i < a)
        {
            i <<= 1;
            log++;
        }
        return log;
    }

    /**
     * Compute <tt>ceil(log_256 n)</tt>, the number of bytes needed to encode
     * the integer <tt>n</tt>.
     *
     * @param n the integer
     * @return the number of bytes needed to encode <tt>n</tt>
     */
    public static int ceilLog256(int n)
    {
        if (n == 0)
        {
            return 1;
        }
        int m;
        if (n < 0)
        {
            m = -n;
        }
        else
        {
            m = n;
        }

        int d = 0;
        while (m > 0)
        {
            d++;
            m >>>= 8;
        }
        return d;
    }

    /**
     * Compute <tt>ceil(log_256 n)</tt>, the number of bytes needed to encode
     * the long integer <tt>n</tt>.
     *
     * @param n the long integer
     * @return the number of bytes needed to encode <tt>n</tt>
     */
    public static int ceilLog256(long n)
    {
        if (n == 0)
        {
            return 1;
        }
        long m;
        if (n < 0)
        {
            m = -n;
        }
        else
        {
            m = n;
        }

        int d = 0;
        while (m > 0)
        {
            d++;
            m >>>= 8;
        }
        return d;
    }

    /**
     * Compute the integer part of the logarithm to the base 2 of the given
     * integer.
     *
     * @param a the integer
     * @return floor[log(a)]
     */
    public static int floorLog(BigInteger a)
    {
        int result = -1;
        BigInteger p = ONE;
        while (p.compareTo(a) <= 0)
        {
            result++;
            p = p.shiftLeft(1);
        }
        return result;
    }

    /**
     * Compute the integer part of the logarithm to the base 2 of the given
     * integer.
     *
     * @param a the integer
     * @return floor[log(a)]
     */
    public static int floorLog(int a)
    {
        int h = 0;
        if (a <= 0)
        {
            return -1;
        }
        int p = a >>> 1;
        while (p > 0)
        {
            h++;
            p >>>= 1;
        }

        return h;
    }

    /**
     * Compute the largest <tt>h</tt> with <tt>2^h | a</tt> if <tt>a!=0</tt>.
     *
     * @param a an integer
     * @return the largest <tt>h</tt> with <tt>2^h | a</tt> if <tt>a!=0</tt>,
     *         <tt>0</tt> otherwise
     */
    public static int maxPower(int a)
    {
        int h = 0;
        if (a != 0)
        {
            int p = 1;
            while ((a & p) == 0)
            {
                h++;
                p <<= 1;
            }
        }

        return h;
    }

    /**
     * @param a an integer
     * @return the number of ones in the binary representation of an integer
     *         <tt>a</tt>
     */
    public static int bitCount(int a)
    {
        int h = 0;
        while (a != 0)
        {
            h += a & 1;
            a >>>= 1;
        }

        return h;
    }

    /**
     * determines the order of g modulo p, p prime and 1 < g < p. This algorithm
     * is only efficient for small p (see X9.62-1998, p. 68).
     *
     * @param g an integer with 1 < g < p
     * @param p a prime
     * @return the order k of g (that is k is the smallest integer with
     *         gk = 1 mod p
     */
    public static int order(int g, int p)
    {
        int b, j;

        b = g % p; // Reduce g mod p first.
        j = 1;

        // Check whether g == 0 mod p (avoiding endless loop).
        if (b == 0)
        {
            throw new IllegalArgumentException(g + " is not an element of Z/("
                + p + "Z)^*; it is not meaningful to compute its order.");
        }

        // Compute the order of g mod p:
        while (b != 1)
        {
            b *= g;
            b %= p;
            if (b < 0)
            {
                b += p;
            }
            j++;
        }

        return j;
    }

    /**
     * Reduces an integer into a given interval
     *
     * @param n     - the integer
     * @param begin - left bound of the interval
     * @param end   - right bound of the interval
     * @return <tt>n</tt> reduced into <tt>[begin,end]</tt>
     */
    public static BigInteger reduceInto(BigInteger n, BigInteger begin,
                                        BigInteger end)
    {
        return n.subtract(begin).mod(end.subtract(begin)).add(begin);
    }

    /**
     * Compute <tt>ae</tt>.
     *
     * @param a the base
     * @param e the exponent
     * @return <tt>ae</tt>
     */
    public static int pow(int a, int e)
    {
        int result = 1;
        while (e > 0)
        {
            if ((e & 1) == 1)
            {
                result *= a;
            }
            a *= a;
            e >>>= 1;
        }
        return result;
    }

    /**
     * Compute <tt>ae</tt>.
     *
     * @param a the base
     * @param e the exponent
     * @return <tt>ae</tt>
     */
    public static long pow(long a, int e)
    {
        long result = 1;
        while (e > 0)
        {
            if ((e & 1) == 1)
            {
                result *= a;
            }
            a *= a;
            e >>>= 1;
        }
        return result;
    }

    /**
     * Compute <tt>ae mod n</tt>.
     *
     * @param a the base
     * @param e the exponent
     * @param n the modulus
     * @return <tt>ae mod n</tt>
     */
    public static int modPow(int a, int e, int n)
    {
        if (n <= 0 || (n * n) > Integer.MAX_VALUE || e < 0)
        {
            return 0;
        }
        int result = 1;
        a = (a % n + n) % n;
        while (e > 0)
        {
            if ((e & 1) == 1)
            {
                result = (result * a) % n;
            }
            a = (a * a) % n;
            e >>>= 1;
        }
        return result;
    }

    /**
     * Extended euclidian algorithm (computes gcd and representation).
     *
     * @param a - the first integer
     * @param b - the second integer
     * @return <tt>(d,u,v)</tt>, where <tt>d = gcd(a,b) = ua + vb</tt>
     */
    public static BigInteger[] extgcd(BigInteger a, BigInteger b)
    {
        BigInteger u = ONE;
        BigInteger v = ZERO;
        BigInteger d = a;
        if (b.signum() != 0)
        {
            BigInteger v1 = ZERO;
            BigInteger v3 = b;
            while (v3.signum() != 0)
            {
                BigInteger[] tmp = d.divideAndRemainder(v3);
                BigInteger q = tmp[0];
                BigInteger t3 = tmp[1];
                BigInteger t1 = u.subtract(q.multiply(v1));
                u = v1;
                d = v3;
                v1 = t1;
                v3 = t3;
            }
            v = d.subtract(a.multiply(u)).divide(b);
        }
        return new BigInteger[]{d, u, v};
    }

    /**
     * Computation of the least common multiple of a set of BigIntegers.
     *
     * @param numbers - the set of numbers
     * @return the lcm(numbers)
     */
    public static BigInteger leastCommonMultiple(BigInteger[] numbers)
    {
        int n = numbers.length;
        BigInteger result = numbers[0];
        for (int i = 1; i < n; i++)
        {
            BigInteger gcd = result.gcd(numbers[i]);
            result = result.multiply(numbers[i]).divide(gcd);
        }
        return result;
    }

    /**
     * Returns a long integer whose value is <tt>(a mod m</tt>). This method
     * differs from <tt>%</tt> in that it always returns a non-negative
     * integer.
     *
     * @param a value on which the modulo operation has to be performed.
     * @param m the modulus.
     * @return <tt>a mod m</tt>
     */
    public static long mod(long a, long m)
    {
        long result = a % m;
        if (result < 0)
        {
            result += m;
        }
        return result;
    }

    /**
     * Computes the modular inverse of an integer a
     *
     * @param a   - the integer to invert
     * @param mod - the modulus
     * @return <tt>a-1 mod n</tt>
     */
    public static int modInverse(int a, int mod)
    {
        return BigInteger.valueOf(a).modInverse(BigInteger.valueOf(mod))
            .intValue();
    }

    /**
     * Computes the modular inverse of an integer a
     *
     * @param a   - the integer to invert
     * @param mod - the modulus
     * @return <tt>a-1 mod n</tt>
     */
    public static long modInverse(long a, long mod)
    {
        return BigInteger.valueOf(a).modInverse(BigInteger.valueOf(mod))
            .longValue();
    }

    /**
     * Tests whether an integer <tt>a</tt> is power of another integer
     * <tt>p</tt>.
     *
     * @param a - the first integer
     * @param p - the second integer
     * @return n if a = p^n or -1 otherwise
     */
    public static int isPower(int a, int p)
    {
        if (a <= 0)
        {
            return -1;
        }
        int n = 0;
        int d = a;
        while (d > 1)
        {
            if (d % p != 0)
            {
                return -1;
            }
            d /= p;
            n++;
        }
        return n;
    }

    /**
     * Find and return the least non-trivial divisor of an integer <tt>a</tt>.
     *
     * @param a - the integer
     * @return divisor p >1 or 1 if a = -1,0,1
     */
    public static int leastDiv(int a)
    {
        if (a < 0)
        {
            a = -a;
        }
        if (a == 0)
        {
            return 1;
        }
        if ((a & 1) == 0)
        {
            return 2;
        }
        int p = 3;
        while (p <= (a / p))
        {
            if ((a % p) == 0)
            {
                return p;
            }
            p += 2;
        }

        return a;
    }

    /**
     * Miller-Rabin-Test, determines wether the given integer is probably prime
     * or composite. This method returns <tt>true</tt> if the given integer is
     * prime with probability <tt>1 - 2-20</tt>.
     *
     * @param n the integer to test for primality
     * @return <tt>true</tt> if the given integer is prime with probability
     *         2-100, <tt>false</tt> otherwise
     */
    public static boolean isPrime(int n)
    {
        if (n < 2)
        {
            return false;
        }
        if (n == 2)
        {
            return true;
        }
        if ((n & 1) == 0)
        {
            return false;
        }
        if (n < 42)
        {
            for (int i = 0; i < SMALL_PRIMES.length; i++)
            {
                if (n == SMALL_PRIMES[i])
                {
                    return true;
                }
            }
        }

        if ((n % 3 == 0) || (n % 5 == 0) || (n % 7 == 0) || (n % 11 == 0)
            || (n % 13 == 0) || (n % 17 == 0) || (n % 19 == 0)
            || (n % 23 == 0) || (n % 29 == 0) || (n % 31 == 0)
            || (n % 37 == 0) || (n % 41 == 0))
        {
            return false;
        }

        return BigInteger.valueOf(n).isProbablePrime(20);
    }

    /**
     * Short trial-division test to find out whether a number is not prime. This
     * test is usually used before a Miller-Rabin primality test.
     *
     * @param candidate the number to test
     * @return <tt>true</tt> if the number has no factor of the tested primes,
     *         <tt>false</tt> if the number is definitely composite
     */
    public static boolean passesSmallPrimeTest(BigInteger candidate)
    {
        final int[] smallPrime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
            41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
            107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
            173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
            239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
            311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379,
            383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449,
            457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523,
            541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607,
            613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677,
            683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761,
            769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853,
            857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937,
            941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019,
            1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087,
            1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153,
            1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229,
            1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297,
            1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381,
            1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453,
            1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499};

        for (int i = 0; i < smallPrime.length; i++)
        {
            if (candidate.mod(BigInteger.valueOf(smallPrime[i])).equals(
                ZERO))
            {
                return false;
            }
        }
        return true;
    }

    /**
     * Returns the largest prime smaller than the given integer
     *
     * @param n - upper bound
     * @return the largest prime smaller than <tt>n</tt>, or <tt>1</tt> if
     *         <tt>n <= 2</tt>
     */
    public static int nextSmallerPrime(int n)
    {
        if (n <= 2)
        {
            return 1;
        }

        if (n == 3)
        {
            return 2;
        }

        if ((n & 1) == 0)
        {
            n--;
        }
        else
        {
            n -= 2;
        }

        while (n > 3 & !isPrime(n))
        {
            n -= 2;
        }
        return n;
    }

    /**
     * Compute the next probable prime greater than <tt>n</tt> with the
     * specified certainty.
     *
     * @param n         a integer number
     * @param certainty the certainty that the generated number is prime
     * @return the next prime greater than <tt>n</tt>
     */
    public static BigInteger nextProbablePrime(BigInteger n, int certainty)
    {

        if (n.signum() < 0 || n.signum() == 0 || n.equals(ONE))
        {
            return TWO;
        }

        BigInteger result = n.add(ONE);

        // Ensure an odd number
        if (!result.testBit(0))
        {
            result = result.add(ONE);
        }

        while (true)
        {
            // Do cheap "pre-test" if applicable
            if (result.bitLength() > 6)
            {
                long r = result.remainder(
                    BigInteger.valueOf(SMALL_PRIME_PRODUCT)).longValue();
                if ((r % 3 == 0) || (r % 5 == 0) || (r % 7 == 0)
                    || (r % 11 == 0) || (r % 13 == 0) || (r % 17 == 0)
                    || (r % 19 == 0) || (r % 23 == 0) || (r % 29 == 0)
                    || (r % 31 == 0) || (r % 37 == 0) || (r % 41 == 0))
                {
                    result = result.add(TWO);
                    continue; // Candidate is composite; try another
                }
            }

            // All candidates of bitLength 2 and 3 are prime by this point
            if (result.bitLength() < 4)
            {
                return result;
            }

            // The expensive test
            if (result.isProbablePrime(certainty))
            {
                return result;
            }

            result = result.add(TWO);
        }
    }

    /**
     * Compute the next probable prime greater than <tt>n</tt> with the default
     * certainty (20).
     *
     * @param n a integer number
     * @return the next prime greater than <tt>n</tt>
     */
    public static BigInteger nextProbablePrime(BigInteger n)
    {
        return nextProbablePrime(n, 20);
    }

    /**
     * Computes the next prime greater than n.
     *
     * @param n a integer number
     * @return the next prime greater than n
     */
    public static BigInteger nextPrime(long n)
    {
        long i;
        boolean found = false;
        long result = 0;

        if (n <= 1)
        {
            return BigInteger.valueOf(2);
        }
        if (n == 2)
        {
            return BigInteger.valueOf(3);
        }

        for (i = n + 1 + (n & 1); (i <= n << 1) && !found; i += 2)
        {
            for (long j = 3; (j <= i >> 1) && !found; j += 2)
            {
                if (i % j == 0)
                {
                    found = true;
                }
            }
            if (found)
            {
                found = false;
            }
            else
            {
                result = i;
                found = true;
            }
        }
        return BigInteger.valueOf(result);
    }

    /**
     * Computes the binomial coefficient (n|t) ("n over t"). Formula:
     *

     *
if n !=0 and t != 0 then (n|t) = Mult(i=1, t): (n-(i-1))/i

     *
if t = 0 then (n|t) = 1

     *
if n = 0 and t > 0 then (n|t) = 0

     *

     *
     * @param n - the "upper" integer
     * @param t - the "lower" integer
     * @return the binomialcoefficient "n over t" as BigInteger
     */
    public static BigInteger binomial(int n, int t)
    {

        BigInteger result = ONE;

        if (n == 0)
        {
            if (t == 0)
            {
                return result;
            }
            return ZERO;
        }

        // the property (n|t) = (n|n-t) be used to reduce numbers of operations
        if (t > (n >>> 1))
        {
            t = n - t;
        }

        for (int i = 1; i <= t; i++)
        {
            result = (result.multiply(BigInteger.valueOf(n - (i - 1))))
                .divide(BigInteger.valueOf(i));
        }

        return result;
    }

    public static BigInteger randomize(BigInteger upperBound)
    {
        if (sr == null)
        {
            sr = new SecureRandom();
        }
        return randomize(upperBound, sr);
    }

    public static BigInteger randomize(BigInteger upperBound,
                                       SecureRandom prng)
    {
        int blen = upperBound.bitLength();
        BigInteger randomNum = BigInteger.valueOf(0);

        if (prng == null)
        {
            prng = sr != null ? sr : new SecureRandom();
        }

        for (int i = 0; i < 20; i++)
        {
            randomNum = new BigInteger(blen, prng);
            if (randomNum.compareTo(upperBound) < 0)
            {
                return randomNum;
            }
        }
        return randomNum.mod(upperBound);
    }

    /**
     * Extract the truncated square root of a BigInteger.
     *
     * @param a - value out of which we extract the square root
     * @return the truncated square root of <tt>a</tt>
     */
    public static BigInteger squareRoot(BigInteger a)
    {
        int bl;
        BigInteger result, remainder, b;

        if (a.compareTo(ZERO) < 0)
        {
            throw new ArithmeticException(
                "cannot extract root of negative number" + a + ".");
        }

        bl = a.bitLength();
        result = ZERO;
        remainder = ZERO;

        // if the bit length is odd then extra step
        if ((bl & 1) != 0)
        {
            result = result.add(ONE);
            bl--;
        }

        while (bl > 0)
        {
            remainder = remainder.multiply(FOUR);
            remainder = remainder.add(BigInteger.valueOf((a.testBit(--bl) ? 2
                : 0)
                + (a.testBit(--bl) ? 1 : 0)));
            b = result.multiply(FOUR).add(ONE);
            result = result.multiply(TWO);
            if (remainder.compareTo(b) != -1)
            {
                result = result.add(ONE);
                remainder = remainder.subtract(b);
            }
        }

        return result;
    }

    /**
     * Takes an approximation of the root from an integer base, using newton's
     * algorithm
     *
     * @param base the base to take the root from
     * @param root the root, for example 2 for a square root
     */
    public static float intRoot(int base, int root)
    {
        float gNew = base / root;
        float gOld = 0;
        int counter = 0;
        while (Math.abs(gOld - gNew) > 0.0001)
        {
            float gPow = floatPow(gNew, root);
            while (Float.isInfinite(gPow))
            {
                gNew = (gNew + gOld) / 2;
                gPow = floatPow(gNew, root);
            }
            counter += 1;
            gOld = gNew;
            gNew = gOld - (gPow - base) / (root * floatPow(gOld, root - 1));
        }
        return gNew;
    }

    /**
     * Calculation of a logarithmus of a float param
     *
     * @param param
     * @return
     */
    public static float floatLog(float param)
    {
        double arg = (param - 1) / (param + 1);
        double arg2 = arg;
        int counter = 1;
        float result = (float)arg;

        while (arg2 > 0.001)
        {
            counter += 2;
            arg2 *= arg * arg;
            result += (1. / counter) * arg2;
        }
        return 2 * result;
    }

    /**
     * int power of a base float, only use for small ints
     *
     * @param f
     * @param i
     * @return
     */
    public static float floatPow(float f, int i)
    {
        float g = 1;
        for (; i > 0; i--)
        {
            g *= f;
        }
        return g;
    }

    /**
     * calculate the logarithm to the base 2.
     *
     * @param x any double value
     * @return log_2(x)
     * @deprecated use MathFunctions.log(double) instead
     */
    public static double log(double x)
    {
        if (x > 0 && x < 1)
        {
            double d = 1 / x;
            double result = -log(d);
            return result;
        }

        int tmp = 0;
        double tmp2 = 1;
        double d = x;

        while (d > 2)
        {
            d = d / 2;
            tmp += 1;
            tmp2 *= 2;
        }
        double rem = x / tmp2;
        rem = logBKM(rem);
        return tmp + rem;
    }

    /**
     * calculate the logarithm to the base 2.
     *
     * @param x any long value >=1
     * @return log_2(x)
     * @deprecated use MathFunctions.log(long) instead
     */
    public static double log(long x)
    {
        int tmp = floorLog(BigInteger.valueOf(x));
        long tmp2 = 1 << tmp;
        double rem = (double)x / (double)tmp2;
        rem = logBKM(rem);
        return tmp + rem;
    }

    /**
     * BKM Algorithm to calculate logarithms to the base 2.
     *
     * @param arg a double value with 1<= arg<= 4.768462058
     * @return log_2(arg)
     * @deprecated use MathFunctions.logBKM(double) instead
     */
    private static double logBKM(double arg)
    {
        double ae[] = // A_e[k] = log_2 (1 + 0.5^k)
            {
                1.0000000000000000000000000000000000000000000000000000000000000000000000000000,
                0.5849625007211561814537389439478165087598144076924810604557526545410982276485,
                0.3219280948873623478703194294893901758648313930245806120547563958159347765589,
                0.1699250014423123629074778878956330175196288153849621209115053090821964552970,
                0.0874628412503394082540660108104043540112672823448206881266090643866965081686,
                0.0443941193584534376531019906736094674630459333742491317685543002674288465967,
                0.0223678130284545082671320837460849094932677948156179815932199216587899627785,
                0.0112272554232541203378805844158839407281095943600297940811823651462712311786,
                0.0056245491938781069198591026740666017211096815383520359072957784732489771013,
                0.0028150156070540381547362547502839489729507927389771959487826944878598909400,
                0.0014081943928083889066101665016890524233311715793462235597709051792834906001,
                0.0007042690112466432585379340422201964456668872087249334581924550139514213168,
                0.0003521774803010272377989609925281744988670304302127133979341729842842377649,
                0.0001760994864425060348637509459678580940163670081839283659942864068257522373,
                0.0000880524301221769086378699983597183301490534085738474534831071719854721939,
                0.0000440268868273167176441087067175806394819146645511899503059774914593663365,
                0.0000220136113603404964890728830697555571275493801909791504158295359319433723,
                0.0000110068476674814423006223021573490183469930819844945565597452748333526464,
                0.0000055034343306486037230640321058826431606183125807276574241540303833251704,
                0.0000027517197895612831123023958331509538486493412831626219340570294203116559,
                0.0000013758605508411382010566802834037147561973553922354232704569052932922954,
                0.0000006879304394358496786728937442939160483304056131990916985043387874690617,
                0.0000003439652607217645360118314743718005315334062644619363447395987584138324,
                0.0000001719826406118446361936972479533123619972434705828085978955697643547921,
                0.0000000859913228686632156462565208266682841603921494181830811515318381744650,
                0.0000000429956620750168703982940244684787907148132725669106053076409624949917,
                0.0000000214978311976797556164155504126645192380395989504741781512309853438587,
                0.0000000107489156388827085092095702361647949603617203979413516082280717515504,
                0.0000000053744578294520620044408178949217773318785601260677517784797554422804,
                0.0000000026872289172287079490026152352638891824761667284401180026908031182361,
                0.0000000013436144592400232123622589569799954658536700992739887706412976115422,
                0.0000000006718072297764289157920422846078078155859484240808550018085324187007,
                0.0000000003359036149273187853169587152657145221968468364663464125722491530858,
                0.0000000001679518074734354745159899223037458278711244127245990591908996412262,
                0.0000000000839759037391617577226571237484864917411614198675604731728132152582,
                0.0000000000419879518701918839775296677020135040214077417929807824842667285938,
                0.0000000000209939759352486932678195559552767641474249812845414125580747434389,
                0.0000000000104969879676625344536740142096218372850561859495065136990936290929,
                0.0000000000052484939838408141817781356260462777942148580518406975851213868092,
                0.0000000000026242469919227938296243586262369156865545638305682553644113887909,
                0.0000000000013121234959619935994960031017850191710121890821178731821983105443,
                0.0000000000006560617479811459709189576337295395590603644549624717910616347038,
                0.0000000000003280308739906102782522178545328259781415615142931952662153623493,
                0.0000000000001640154369953144623242936888032768768777422997704541618141646683,
                0.0000000000000820077184976595619616930350508356401599552034612281802599177300,
                0.0000000000000410038592488303636807330652208397742314215159774270270147020117,
                0.0000000000000205019296244153275153381695384157073687186580546938331088730952,
                0.0000000000000102509648122077001764119940017243502120046885379813510430378661,
                0.0000000000000051254824061038591928917243090559919209628584150482483994782302,
                0.0000000000000025627412030519318726172939815845367496027046030028595094737777,
                0.0000000000000012813706015259665053515049475574143952543145124550608158430592,
                0.0000000000000006406853007629833949364669629701200556369782295210193569318434,
                0.0000000000000003203426503814917330334121037829290364330169106716787999052925,
                0.0000000000000001601713251907458754080007074659337446341494733882570243497196,
                0.0000000000000000800856625953729399268240176265844257044861248416330071223615,
                0.0000000000000000400428312976864705191179247866966320469710511619971334577509,
                0.0000000000000000200214156488432353984854413866994246781519154793320684126179,
                0.0000000000000000100107078244216177339743404416874899847406043033792202127070,
                0.0000000000000000050053539122108088756700751579281894640362199287591340285355,
                0.0000000000000000025026769561054044400057638132352058574658089256646014899499,
                0.0000000000000000012513384780527022205455634651853807110362316427807660551208,
                0.0000000000000000006256692390263511104084521222346348012116229213309001913762,
                0.0000000000000000003128346195131755552381436585278035120438976487697544916191,
                0.0000000000000000001564173097565877776275512286165232838833090480508502328437,
                0.0000000000000000000782086548782938888158954641464170239072244145219054734086,
                0.0000000000000000000391043274391469444084776945327473574450334092075712154016,
                0.0000000000000000000195521637195734722043713378812583900953755962557525252782,
                0.0000000000000000000097760818597867361022187915943503728909029699365320287407,
                0.0000000000000000000048880409298933680511176764606054809062553340323879609794,
                0.0000000000000000000024440204649466840255609083961603140683286362962192177597,
                0.0000000000000000000012220102324733420127809717395445504379645613448652614939,
                0.0000000000000000000006110051162366710063906152551383735699323415812152114058,
                0.0000000000000000000003055025581183355031953399739107113727036860315024588989,
                0.0000000000000000000001527512790591677515976780735407368332862218276873443537,
                0.0000000000000000000000763756395295838757988410584167137033767056170417508383,
                0.0000000000000000000000381878197647919378994210346199431733717514843471513618,
                0.0000000000000000000000190939098823959689497106436628681671067254111334889005,
                0.0000000000000000000000095469549411979844748553534196582286585751228071408728,
                0.0000000000000000000000047734774705989922374276846068851506055906657137209047,
                0.0000000000000000000000023867387352994961187138442777065843718711089344045782,
                0.0000000000000000000000011933693676497480593569226324192944532044984865894525,
                0.0000000000000000000000005966846838248740296784614396011477934194852481410926,
                0.0000000000000000000000002983423419124370148392307506484490384140516252814304,
                0.0000000000000000000000001491711709562185074196153830361933046331030629430117,
                0.0000000000000000000000000745855854781092537098076934460888486730708440475045,
                0.0000000000000000000000000372927927390546268549038472050424734256652501673274,
                0.0000000000000000000000000186463963695273134274519237230207489851150821191330,
                0.0000000000000000000000000093231981847636567137259618916352525606281553180093,
                0.0000000000000000000000000046615990923818283568629809533488457973317312233323,
                0.0000000000000000000000000023307995461909141784314904785572277779202790023236,
                0.0000000000000000000000000011653997730954570892157452397493151087737428485431,
                0.0000000000000000000000000005826998865477285446078726199923328593402722606924,
                0.0000000000000000000000000002913499432738642723039363100255852559084863397344,
                0.0000000000000000000000000001456749716369321361519681550201473345138307215067,
                0.0000000000000000000000000000728374858184660680759840775119123438968122488047,
                0.0000000000000000000000000000364187429092330340379920387564158411083803465567,
                0.0000000000000000000000000000182093714546165170189960193783228378441837282509,
                0.0000000000000000000000000000091046857273082585094980096891901482445902524441,
                0.0000000000000000000000000000045523428636541292547490048446022564529197237262,
                0.0000000000000000000000000000022761714318270646273745024223029238091160103901};
        int n = 53;
        double x = 1;
        double y = 0;
        double z;
        double s = 1;
        int k;

        for (k = 0; k < n; k++)
        {
            z = x + x * s;
            if (z <= arg)
            {
                x = z;
                y += ae[k];
            }
            s *= 0.5;
        }
        return y;
    }

    public static boolean isIncreasing(int[] a)
    {
        for (int i = 1; i = a[i])
            {
                System.out.println("a[" + (i - 1) + "] = " + a[i - 1] + " >= "
                    + a[i] + " = a[" + i + "]");
                return false;
            }
        }
        return true;
    }

    public static byte[] integerToOctets(BigInteger val)
    {
        byte[] valBytes = val.abs().toByteArray();

        // check whether the array includes a sign bit
        if ((val.bitLength() & 7) != 0)
        {
            return valBytes;
        }
        // get rid of the sign bit (first byte)
        byte[] tmp = new byte[val.bitLength() >> 3];
        System.arraycopy(valBytes, 1, tmp, 0, tmp.length);
        return tmp;
    }

    public static BigInteger octetsToInteger(byte[] data, int offset,
                                             int length)
    {
        byte[] val = new byte[length + 1];

        val[0] = 0;
        System.arraycopy(data, offset, val, 1, length);
        return new BigInteger(val);
    }

    public static BigInteger octetsToInteger(byte[] data)
    {
        return octetsToInteger(data, 0, data.length);
    }

    public static void main(String[] args)
    {
        System.out.println("test");
        // System.out.println(intRoot(37, 5));
        // System.out.println(floatPow((float)2.5, 4));
        System.out.println(floatLog(10));
        System.out.println("test2");
    }
}

{'repo_name': 'redfish64/TinyTravelTracker', 'stars': '104', 'repo_language': 'Java', 'file_name': 'notes.txt~', 'mime_type': 'text/plain', 'hash': 1038594959928350304, 'source_dataset': 'data'}