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

Scala TreeSet类代码示例

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

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



在下文中一共展示了TreeSet类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: ProcessorHierarchySpec

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

import akka.stream.testkit.AkkaSpec
import akka.stream.scaladsl.Flow
import akka.actor.ActorContext
import scala.concurrent.Await
import scala.concurrent.duration._
import akka.actor.ActorRef
import scala.collection.immutable.TreeSet
import scala.util.control.NonFatal
import akka.stream.impl.ActorBasedFlowMaterializer

class ProcessorHierarchySpec extends AkkaSpec("akka.actor.debug.lifecycle=off\nakka.loglevel=INFO") {

  val materializer = FlowMaterializer(MaterializerSettings())

  def self = ActorBasedFlowMaterializer.currentActorContext().self

  "An ActorBasedFlowMaterializer" must {

    "generate the right level of descendants" in {
      val f = Flow(() ? {
        testActor ! self
        Flow(List(1)).map(x ? { testActor ! self; x }).toProducer(materializer)
      }).take(3).foreach(x ? {
        testActor ! self
        Flow(x).foreach(_ ? testActor ! self).consume(materializer)
      }).toFuture(materializer)
      Await.result(f, 3.seconds)
      val refs = receiveWhile(idle = 250.millis) {
        case r: ActorRef ? r
      }
      try {
        refs.toSet.size should be(8)
        refs.distinct.map(_.path.elements.size).groupBy(x ? x).mapValues(x ? x.size) should be(Map(2 -> 2, 3 -> 6))
      } catch {
        case NonFatal(e) ?
          println(refs.map(_.toString).to[TreeSet].mkString("\n"))
          throw e
      }
    }

  }

} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:46,代码来源:ProcessorHierarchySpec.scala


示例3: TreePrinter

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

import scala.collection.immutable.{ CollectionTreeUtil, TreeSet }
import scala.util.Random

object TreePrinter extends App {
  var t = TreeSet.empty[Int]
  val r = new Random()
  for (i ? 0 until 10)
    t += r.nextInt(100)
  val text = CollectionTreeUtil.toGraphVizDot(t)
  println(text)

  t += r.nextInt(100)
  val text2 = CollectionTreeUtil.toGraphVizDot(t)
  println(text2)
} 
开发者ID:rklaehn,项目名称:persistentsummary,代码行数:18,代码来源:TreePrinter.scala


示例4: SimpleTreeSetSummaryBench

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

import ichi.bench.Thyme

import scala.collection.immutable.TreeSet

object SimpleTreeSetSummaryBench extends App {

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

  val summarizer = PersistentSummary.treeSet(IntLongSummary)

  def buildCached(n: Int): Long = {
    var current = TreeSet.empty[Int]
    var totalSum = 0L
    for (i ? 0 until n) {
      current += i
      totalSum += summarizer(current)
    }
    totalSum
  }

  def buildUncached(n: Int): Long = {
    var current = TreeSet.empty[Int]
    var totalSum = 0L
    for (i ? 0 until n) {
      current += i
      totalSum += current.iterator.map(_.toLong).sum
    }
    totalSum
  }

  val n = 5000
  val s = TreeSet(0 until n: _*)
  def accessSummary(): Long = {
    summarizer(s)
  }

  def summarySmallChange(): Long = {
    val s1 = s + 10000
    summarizer(s)
  }

  def sumSmallChange(): Long = {
    val s1 = s + 10000
    s1.iterator.map(_.toLong).sum
  }

  println("measures the time to access an already existing summary from a guava cache with weak keys")
  th.pbenchWarm(th.Warm(accessSummary()), title = "access")

  println("compares persistent summary with recalculating from scratch every time")
  th.pbenchOffWarm(s"build 1 to $n uncached vs. cached")(th.Warm(buildUncached(n)))(th.Warm(buildCached(n)))

  println("compare persistent summary with recalculating from scratch (single update to large collection)")
  th.pbenchOffWarm(s"update 5000 / 1 uncached vs. cached")(th.Warm(sumSmallChange()))(th.Warm(summarySmallChange()))

} 
开发者ID:rklaehn,项目名称:persistentsummary,代码行数:59,代码来源:SimpleTreeSetSummaryBench.scala


示例5: BootstrapListener

//设置package包名称以及导入依赖的类
package cwe.scala.library.audit.listener
import cwe.scala.library.audit._
import cwe.scala.library.audit.data._
import cwe.scala.library.runtime.io.Logger
import scala.collection.immutable.TreeSet


class BootstrapListener extends AuditEventListener {
	private var forwardListener: AuditEventListener = null
	private var eventBuffer = new TreeSet[AuditEvent]

	// Dependency injection

	def setForwardListener(l: AuditEventListener) = {
		if (l == null) throw new IllegalArgumentException("AuditEventListener cannot be null")
		else synchronized { forwardListener = l }
	}
	def getForwardListener(): AuditEventListener = {
		if (forwardListener == null) synchronized { if (forwardListener == null) setForwardListener(getTraceService) }
		forwardListener
	}
	private def getTraceService = {
		val ts = AuditServiceProvider.createTraceService
		ts.setLogger(Logger.createInstance("bootstrap"))
		ts
	}

	// Implementation

	def handleAuditEvent(e: AuditEvent) = {
		// if first event, then forces the creation of the forwardListener to force all remaining events
		if (eventBuffer.isEmpty) getForwardListener()
		eventBuffer += e
	}

	def unregistred() = {
		val l = this.getForwardListener()
		this.eventBuffer.foreach((e) => { l.handleAuditEvent(e) })
		l.unregistred()
	}
	private def myThreadId = Thread.currentThread().getId()
	private def currentTime = System.currentTimeMillis()
} 
开发者ID:wwwigii-system,项目名称:research,代码行数:44,代码来源:BootstrapListener.scala


示例6: EnumerationMacros

//设置package包名称以及导入依赖的类
package net.woaf.jono.phonehome

import scala.language.experimental.macros

import scala.reflect.macros.blackbox.Context
import scala.collection.immutable.TreeSet


object EnumerationMacros {
  def sealedInstancesOf[A]: TreeSet[A] = macro sealedInstancesOfImpl[A]

  def sealedInstancesOfImpl[A: c.WeakTypeTag](c: Context): c.Expr[TreeSet[A]] = {
    import c.universe._ // scalastyle:ignore

    val symbol = weakTypeOf[A].typeSymbol.asClass

    if  (!symbol.isClass || !symbol.isSealed) {
      c.abort(c.enclosingPosition, "Can only enumerate values of a sealed trait or class.")
    } else {

      val children = symbol.knownDirectSubclasses.toList

      if (!children.forall(_.isModuleClass)) {
        c.abort(c.enclosingPosition, "All children must be objects.")
      } else {
        c.Expr[TreeSet[A]] {

          def sourceModuleRef(sym: Symbol) = Ident(sym.asInstanceOf[scala.reflect.internal.Symbols#Symbol
            ].sourceModule.asInstanceOf[Symbol]
          )

          Apply(
            Select(
              reify(TreeSet).tree,
              TermName("apply")
            ),
            children.map(sourceModuleRef(_))
          )
        }
      }
    }
  }
} 
开发者ID:JonathanO,项目名称:phonehome,代码行数:44,代码来源:EnumerationMacros.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Publish类代码示例发布时间:2022-05-23
下一篇:
Scala BasicStroke类代码示例发布时间: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