• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TreeMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1:

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


  import scala.collection.immutable.TreeSet
  val ts = TreeSet(9, 3, 1, 8, 0, 2, 7, 4, 6, 5)
  println(ts)
  val ts2 = TreeSet(ts.toSeq: _*)(ts.ordering.reverse)
  println(ts2)
  val cs = TreeSet('f', 'u', 'n')
  println(cs)

  import scala.collection.immutable.TreeMap
  var tm = TreeMap(3 -> 'x', 1 -> 'x', 4 -> 'x')
  tm += (2 -> 'x')
  println(tm)

  val tm2 = TreeMap(tm.toSeq: _*)(tm.ordering.reverse)
  println(tm2)

} 
开发者ID:seraekim,项目名称:srkim-lang-scala,代码行数:21,代码来源:c17_i02.scala


示例2: Stats

//设置package包名称以及导入依赖的类
package akka.performance.workbench

import scala.collection.immutable.TreeMap

@SerialVersionUID(1L)
case class Stats(
  name: String,
  load: Int,
  timestamp: Long = System.currentTimeMillis,
  durationNanos: Long = 0L,
  n: Long = 0L,
  min: Long = 0L,
  max: Long = 0L,
  mean: Double = 0.0,
  tps: Double = 0.0,
  percentiles: TreeMap[Int, Long] = Stats.emptyPercentiles) {

  def median: Long = percentiles(50)
}

object Stats {
  val emptyPercentiles = TreeMap[Int, Long](
    5 -> 0L,
    25 -> 0L,
    50 -> 0L,
    75 -> 0L,
    95 -> 0L)
} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:29,代码来源:Stats.scala


示例3: DistributedPubSubMessageSerializerSpec

//设置package包名称以及导入依赖的类
package akka.contrib.pattern.protobuf

import akka.actor.{ ExtendedActorSystem, Address }
import akka.testkit.AkkaSpec
import akka.contrib.pattern.DistributedPubSubMediator._
import akka.contrib.pattern.DistributedPubSubMediator.Internal._
import akka.actor.Props
import scala.collection.immutable.TreeMap

@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class DistributedPubSubMessageSerializerSpec extends AkkaSpec {

  val serializer = new DistributedPubSubMessageSerializer(system.asInstanceOf[ExtendedActorSystem])

  def checkSerialization(obj: AnyRef): Unit = {
    val blob = serializer.toBinary(obj)
    val ref = serializer.fromBinary(blob, obj.getClass)
    ref should be(obj)
  }

  " DistributedPubSubMessages" must {

    "be serializable" in {
      val address1 = Address("akka.tcp", "system", "some.host.org", 4711)
      val address2 = Address("akka.tcp", "system", "other.host.org", 4711)
      val address3 = Address("akka.tcp", "system", "some.host.org", 4712)
      val u1 = system.actorOf(Props.empty, "u1")
      val u2 = system.actorOf(Props.empty, "u2")
      val u3 = system.actorOf(Props.empty, "u3")
      val u4 = system.actorOf(Props.empty, "u4")
      checkSerialization(Status(Map(address1 -> 3, address2 -> 17, address3 -> 5)))
      checkSerialization(Delta(List(
        Bucket(address1, 3, TreeMap("/user/u1" -> ValueHolder(2, Some(u1)), "/user/u2" -> ValueHolder(3, Some(u2)))),
        Bucket(address2, 17, TreeMap("/user/u3" -> ValueHolder(17, Some(u3)))),
        Bucket(address3, 5, TreeMap("/user/u4" -> ValueHolder(4, Some(u4)), "/user/u5" -> ValueHolder(5, None))))))
      checkSerialization(Send("/user/u3", "hello", localAffinity = true))
      checkSerialization(SendToAll("/user/u3", "hello", allButSelf = true))
      checkSerialization(Publish("mytopic", "hello"))
    }
  }
} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:42,代码来源:DistributedPubSubMessageSerializerSpec.scala


示例4: RouteBuilder

//设置package包名称以及导入依赖的类
package com.viajobien.busy.models.routing

import scala.collection.immutable.TreeMap


class RouteBuilder(routeTables: List[Route]) extends PathUtil {

  def createRouteTree: RouteTree = routeTables.foldLeft[RouteTree](
    new RouteEmpty()
  ) { (rn, rt) =>
      rn ++ this.buildTree(rt, this.splitPath(rt.path))
    }

  private def buildTree(routeTable: Route, parts: List[String] = Nil): RouteTree =
    parts match {
      case Nil                 => new RouteEndpointNode(List(routeTable))
      case PATH_WILDCARD :: ps => new RouteNode(TreeMap(PATH_WILDCARD -> new RouteWildcardNode(List(routeTable))))
      case p :: ps             => new RouteNode(TreeMap(p -> this.buildTree(routeTable, ps)))
    }

} 
开发者ID:viajobien,项目名称:busy,代码行数:22,代码来源:RouteBuilder.scala


示例5: LandRegistryPricePaidData

//设置package包名称以及导入依赖的类
import scala.collection.immutable.TreeMap

package object PaidDatas {
  type PaidDatas = TreeMap[String, LandRegistryPricePaidDataItem]
}


class LandRegistryPricePaidData(val paidDatas: PaidDatas.PaidDatas ) {

  def this(ppds: List[LandRegistryPricePaidDataItem] = List() ) {
    this(ppds.map(t => t.transactionUniqueIdentifier -> t)(collection.breakOut) : PaidDatas.PaidDatas)
  } 

  
  def merge(ppds: List[LandRegistryPricePaidDataItem]): LandRegistryPricePaidData = { 
    val newListOfPpds = ppds.foldLeft(paidDatas)((z, t) => 
      t.recordStatus match {
        case "D" => z - t.transactionUniqueIdentifier
        case _   => z + (t.transactionUniqueIdentifier -> t)
      }
    ) 
     
    new LandRegistryPricePaidData(newListOfPpds)
  }
} 
开发者ID:Geovation,项目名称:housemining,代码行数:26,代码来源:LandRegistryPricePaidData.scala


示例6: TreeSetStdDevBench

//设置package包名称以及导入依赖的类
package com.rklaehn.persistentsummary

import ichi.bench.Thyme
import scala.collection.immutable.TreeMap

object TreeSetStdDevBench extends App {

  val cachedSummary = PersistentSummary.treeMapValue(StdDevSummary)

  def avgAndStdDev(values: TreeMap[Int, Double]): (Long, Double, Double) = {
    val (n, sum, sum2) = cachedSummary(values)
    val avg = sum / n
    val variance = sum2 / (n - 1) - (sum * sum) / (n * (n - 1.0))
    val stdDev = math.sqrt(variance)
    (n, avg, stdDev)
  }

  def avgAndStdDevUncached(values: TreeMap[Int, Double]): (Long, Double, Double) = {
    val (n, sum, sum2) = values.values.foldLeft(StdDevSummary.empty) { case (a, e) => StdDevSummary.combine(a, StdDevSummary.apply(e)) }
    val avg = sum / n
    val variance = sum2 / (n - 1) - (sum * sum) / (n * (n - 1.0))
    val stdDev = math.sqrt(variance)
    (n, avg, stdDev)
  }

  val max = 16 * 1024

  val elements: TreeMap[Int, Double] = TreeMap((0 until max).map { i => i -> (i % 16).toDouble }: _*)

  println(avgAndStdDev(elements))

  val elements1 = elements + (max / 2 -> 1000.0)

  println(avgAndStdDev(elements1))

  val th = Thyme.warmed(warmth = Thyme.HowWarm.BenchOff, verbose = println)

  def stdDevUncached(): Double = {
    val elements1 = elements + (max / 2 -> 1000.0)
    avgAndStdDevUncached(elements1)._3
  }

  def stdDevCached(): Double = {
    val elements1 = elements + (max / 2 -> 1000.0)
    avgAndStdDev(elements1)._3
  }

  th.pbenchOffWarm(s"average and stddev when modifying one element in a collection of size $max")(th.Warm(stdDevCached()))(th.Warm(stdDevUncached()))
} 
开发者ID:rklaehn,项目名称:persistentsummary,代码行数:50,代码来源:TreeSetStdDevBench.scala


示例7: DistributedRandomGenerator

//设置package包名称以及导入依赖的类
package com.wavesplatform.generator

import scala.collection.immutable.TreeMap

class DistributedRandomGenerator[T](probabilities: Map[T, Float]) {
  assert(probabilities.values.sum == 1)
  def getRandom: T = {
    val rand = Math.random
    val g = probabilities.foldLeft((TreeMap[Float, Option[T]](0f -> None), 0f)) { case ((m, max), (t, prob)) =>
      val limit = max + prob
      (m.updated(limit, Some(t)), limit)
    }._1
    g.toSeq.sliding(2).find {
      case Seq((from, _), (to, _)) =>
        rand >= from && rand <= to
    }.flatMap(_.last._2).get
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:19,代码来源:DistributedRandomGenerator.scala


示例8: MultiMap

//设置package包名称以及导入依赖的类
package pl.touk.nussknacker.engine.api.util

import scala.collection.immutable.TreeMap

object MultiMap {
  def apply[K:Ordering, V] : MultiMap[K, V] = MultiMap(TreeMap())
}

case class MultiMap[K, V](map: TreeMap[K, List[V]]) {

  def add(key: K, value: V) : MultiMap[K, V] = {
    val newElement = map.get(key) match {
      case Some(list) => value::list
      case None => List(value)
    }
    MultiMap(map + (key -> newElement))
  }

  def remove(key: K, value: V) : MultiMap[K, V] = {
    map.get(key) match {
      case Some(list) =>
        //TODO: this is only ineffective operation, but in our case lists should be rather short
        val withRemovedEl = list.filterNot(_ == value)
        MultiMap(map + (key -> withRemovedEl))
      case None =>
        this
    }

  }

  def from(minimalKey: K) = MultiMap(map.from(minimalKey))

  def until(minimalKey: K) = MultiMap(map.until(minimalKey))


} 
开发者ID:TouK,项目名称:nussknacker,代码行数:37,代码来源:MultiMap.scala


示例9: RouletteWheelSelector

//设置package包名称以及导入依赖的类
package com.swara.learn.genetic
package selectors

import scala.collection.immutable.TreeMap
import scala.util.Random


class RouletteWheelSelector[T] extends Selector[T] {

  override def select(individuals: Seq[Individual[T]], n: Int): Seq[Individual[T]] = {
    // Build a prefix-sum of individual fitness and store in a tree map. This allows us to perform
    // fitness-proportionate random selection in O(|I| log |I| + n log |I|).
    var wheel = TreeMap.empty[Double, Individual[T]]
    var total = 0.0

    individuals.foreach { i =>
      if (total == 0.0 || i.fitness > 0.0) {
        total += i.fitness
        wheel += total -> i
      }
    }

    // Randomly sample from the roulette wheel to choose the selected individuals.
    Seq.fill(n)(wheel.valuesIteratorFrom(Random.nextDouble() * total).next())
  }

} 
开发者ID:ashwin153,项目名称:swara,代码行数:28,代码来源:RouletteWheelSelector.scala


示例10: CanonicalHeaders

//设置package包名称以及导入依赖的类
package jkugiya.awstools.signer.v4

import scala.collection.immutable.TreeMap
import scala.collection.mutable

private[v4] final case class CanonicalHeaders private (private val headers: TreeMap[String, Vector[String]]) {

  val names: String = {
    val sb =
      headers.keySet
        .foldLeft(mutable.StringBuilder.newBuilder)((acc, v) => acc.append(v.toLowerCase()).append(';'))
    sb.deleteCharAt(sb.lastIndexOf(";"))
    sb.mkString
  }
  val mkString: String = {
    val sb = mutable.StringBuilder.newBuilder
    for {
      (key, values) <- headers
      value <- values
    } yield {
      sb.append(key.toLowerCase())
        .append(':')
        .append(value)
        .append('\n')
    }
    sb.toString()
  }

  def apply(key: String): Vector[String] = headers(key)

  def get(key: String): Option[Vector[String]] = headers.get(key)

}

object CanonicalHeaders {

  def apply(headers: Header*): CanonicalHeaders = {
    // HTTP header keys are case insensitive
    implicit val orderingForKey = new Ordering[String] {
      override def compare(x: String, y: String): Int =
        x.toLowerCase().compareTo(y.toLowerCase())
    }
    val internalMap =
      headers.foldLeft(TreeMap.empty[String, Vector[String]]) {
        case (acc, Header(k, v)) =>
          acc.get(k).fold {
            acc + (k -> Vector(v))
          } { values =>
            acc + (k -> (values :+ v))
          }
      }
    CanonicalHeaders(internalMap)
  }

} 
开发者ID:jkugiya,项目名称:aws-v4-signer-scala,代码行数:56,代码来源:CanonicalHeaders.scala


示例11: ShipMap

//设置package包名称以及导入依赖的类
package com.harry0000.kancolle

import scala.collection.{Map, Seq, mutable}
import scala.collection.immutable.TreeMap

package object ac {
  type ShipName = String
  type ShipMap = TreeMap[ShipCategory, Seq[ShipName]]
  object ShipMap {
    def empty: ShipMap = TreeMap.empty[ShipCategory, Seq[ShipName]]
    def apply(value: (ShipCategory, Seq[ShipName]) *): ShipMap = TreeMap(value: _*)
  }

  sealed abstract class ShipCategory(val name: String)
  object ShipCategory {
    case object Destroyer       extends ShipCategory("???")
    case object LightCruiser    extends ShipCategory("??")
    case object HeavyCruiser    extends ShipCategory("??")
    case object SeaplaneTender  extends ShipCategory("?????")
    case object AircraftCarrier extends ShipCategory("??")
    case object Submarine       extends ShipCategory("???")
    case object Battleship      extends ShipCategory("??")

    private val order: Map[ShipCategory, Int] = mutable.LinkedHashMap.empty ++ Seq(
      Destroyer,
      LightCruiser,
      HeavyCruiser,
      SeaplaneTender,
      AircraftCarrier,
      Submarine,
      Battleship
    ).zipWithIndex

    implicit val ordering: Ordering[ShipCategory] = Ordering.by(order.getOrElse(_, Int.MaxValue))

    def apply(shipType: String): ShipCategory = shipType match {
      case "??" => Destroyer
      case "??" => LightCruiser
      case "??" => HeavyCruiser
      case "??" => SeaplaneTender
      case "??" => AircraftCarrier
      case "??" => AircraftCarrier
      case "??" => Submarine
      case "??" => Battleship
    }

    def get(index: Int): Option[ShipCategory] = order.find(_._2 == index).map(_._1)

    def values: Seq[ShipCategory] = order.keys.toSeq
  }
} 
开发者ID:harry0000,项目名称:DropTableParser,代码行数:52,代码来源:package.scala


示例12: Set_Map

//设置package包名称以及导入依赖的类
import scala.collection.immutable.TreeMap
import scala.collection.mutable


object Set_Map {
  def main(args: Array[String]) {
    val data = mutable.Set.empty[String]
    data ++= List("1", "2", "2")
    data += "4"
    data --= List("2", "3")

    println(data)
    data += "1"
    println(data)
    data.clear
    println(data)

    val map = mutable.Map.empty[String, String]
    map("java") = "Hadoop"
    map("scala") = "Spark"
    println(map)
    println(map("java"))

    val treeSet = mutable.TreeSet(3, 45, 6, 3, 67, 35, 86, 32, 23)
    println(treeSet)
    val treeSetForChar = mutable.TreeSet("Spark", "Scala", "Hadoop")
    println(treeSetForChar)


    val treeMap = TreeMap("scala" -> "Spark", "Java" -> "Hadoop")
    val treeMap2=treeMap.addString(new StringBuilder("hello") ,"life is good","dsada","dasda")
    println(treeMap)
    println(treeMap2)




  }
} 
开发者ID:WeiLi1201,项目名称:ProgrammingNote,代码行数:40,代码来源:Set_Map.scala


示例13: LabelSpec

//设置package包名称以及导入依赖的类
package com.scalafi.dynamics.attribute

import com.scalafi.openbook.orderbook.OrderBook
import org.scalatest.FlatSpec

import scala.collection.immutable.TreeMap

class LabelSpec extends FlatSpec {

  // Mean price = (100 + 110) / 2 = 105
  val lowerMeanPriceOrderBook = new OrderBook("AAPL", TreeMap(100 -> 1), TreeMap(110 ->1))

  // Mean price = (110 + 120) / 2 = 115
  val higherMeanPriceOrderBook = new OrderBook("AAPL", TreeMap(110 -> 1), TreeMap(120 -> 1))

  "MeanPriceMovementLabel" should "correctly assign label" in {
    assert(MeanPriceMovementLabel(lowerMeanPriceOrderBook, higherMeanPriceOrderBook) == Some(MeanPriceMove.Up))
    assert(MeanPriceMovementLabel(higherMeanPriceOrderBook, lowerMeanPriceOrderBook) == Some(MeanPriceMove.Down))
    assert(MeanPriceMovementLabel(lowerMeanPriceOrderBook, lowerMeanPriceOrderBook) == Some(MeanPriceMove.Stationary))
  }
} 
开发者ID:wensdong,项目名称:ML-test,代码行数:22,代码来源:LabelSpec.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Free类代码示例发布时间:2022-05-23
下一篇:
Scala Database类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap