当前位置: 首页>>代码示例>>Scala>>正文


Scala min类代码示例

本文整理汇总了Scala中scala.math.min的典型用法代码示例。如果您正苦于以下问题:Scala min类的具体用法?Scala min怎么用?Scala min使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了min类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: Publisher

//设置package包名称以及导入依赖的类
package akka_in_action.FSM

import akka.actor.Actor
import scala.math.min

class Publisher(totalNrBooks: Int, nrBooksPerRequest: Int)
  extends Actor {

  var nrLeft = totalNrBooks

  def receive = {
    case PublisherRequest => {
      if(nrLeft == 0)
        sender ! BookSupplySoldOut
      else {
        val supply = min(nrBooksPerRequest, nrLeft)
        nrLeft -= supply
        sender ! new BookSupply(supply)
      }
    }
  }
} 
开发者ID:rockdragon,项目名称:fourthgala,代码行数:23,代码来源:Publisher.scala

示例2: Application

//设置package包名称以及导入依赖的类
package controllers

import akka.actor.ActorSystem
import com.github.luqmansahaf.playlivy.LivyManager
import javax.inject.Inject
import org.apache.spark.sql.SparkSession
import play.api.mvc._
import play.api.Configuration
import play.Logger
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
import scala.util.{Failure, Success}


class Application @Inject() (val system: ActorSystem, config: Configuration, livyManager: LivyManager)
  extends Controller {

  
  def runPiExample(num: String) = Action {
    val number = num.toInt
    try {
      val handle = livyManager.submit(context => {
        import scala.math.{random,max,min}
        val spark: SparkSession = context.sparkSession
        // Pi calculation code
        // Adapted from: https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala
        val slices = max(number,2)
        val n = min(100000L * slices, Int.MaxValue).toInt // avoid overflow
        val count = spark.sparkContext.parallelize(1 until n, slices).map { i =>
            val x = random * 2 - 1
            val y = random * 2 - 1
            if (x*x + y*y <= 1) 1 else 0
          }.reduce(_ + _)
        println("Pi is roughly " + 4.0 * count / (n - 1))
        4.0 * count / (n - 1)
      })
      Await.ready(handle, 60 second)
      handle.value match {
        case Some(Success(pi)) =>
          Logger.info(s"pi = $pi")
          Ok(pi.toString)
        case Some(Failure(e)) =>
          Logger.error(s"error occurred while computing pi: ${e.getMessage}")
          e.printStackTrace()
          Status(500)
        case None => Status(500)
      }
    } catch {
      case e: Exception =>
        Logger.error("error occurred")
        e.printStackTrace()
        Status(500)
    }
  }
} 
开发者ID:LuqmanSahaf,项目名称:Play-Livy-Module,代码行数:57,代码来源:Application.scala

示例3: SortedBlocks

//设置package包名称以及导入依赖的类
package de.fuberlin.wiwiss.silk.execution.methods

import de.fuberlin.wiwiss.silk.entity.{Path, Index, Entity}
import de.fuberlin.wiwiss.silk.linkagerule.LinkageRule
import de.fuberlin.wiwiss.silk.execution.ExecutionMethod
import scala.math.{min,max,pow}

case class SortedBlocks(sourceKey: Path, targetKey: Path, overlap: Double = 0.5) extends ExecutionMethod {

  private val minChar = 'a'
  private val maxChar = 'z'
  private val numChars = 3 //Maximum number of chars that will be indexed

  private val blockCount = pow((maxChar - minChar + 1), 2).toInt

  override def indexEntity(entity: Entity, rule: LinkageRule): Index = {
    val key = if(sourceKey.variable == entity.desc.variable) sourceKey else targetKey
    val values = entity.evaluate(key)

    values.map(indexValue).reduce(_ merge _)
  }

  private def indexValue(value: String): Index = {
    //Given a string, generate a value in the interval [0,1[
    var index = 0.0
    for(i <- 0 until min(numChars, value.length)) {
      //Make sure the character is inside the interval [minChar,maxChar]
      val croppedChar = min(max(value(i).toLower, minChar), maxChar)
      //Update index
      index += (croppedChar - minChar) / pow(maxChar - minChar + 1, i + 1)
    }

    //Generate index
    Index.continuous(
      value = index,
      minValue = 0.0,
      maxValue = 1.0,
      blockCount = blockCount,
      overlap = overlap
    )
  }
} 
开发者ID:petrovskip,项目名称:silk.2.6-GenLinkSA,代码行数:43,代码来源:SortedBlocks.scala


注:本文中的scala.math.min类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。