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

Scala Queue类代码示例

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

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



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

示例1: QueueTest

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

import org.scalatest.FunSuite
import scala.collection.mutable.Queue

class QueueTest extends FunSuite {
  test("t") {
    val q = Queue[Int]()
    q += 1
    q += 2
    q += 3
    q += 4
    q += 5
    Range(0, q.length).foreach { _ =>
      q.dequeue()
    }
    println("size:" + q.size)
  }
} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:20,代码来源:QueueTest.scala


示例2: LinkQueueActor

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

import scala.collection.mutable.Queue
import scala.collection.mutable.Set
import akka.actor.{Actor, ActorRef, ActorLogging}


class LinkQueueActor(parseQueue: ActorRef) extends Actor with ActorLogging {
  // We have provided some definitions below which will help you with
  // you implementation. You are welcome to modify these, however, this
  // is what we used for our implementation.
  log.info("LinkQueueActor created")
  val queue        = Queue[String]()
  val fetchers     = Set[ActorRef]()
  var limit        = 500

  def receive = {

    case NeedLink =>     if(limit == 0)
                             context.system.shutdown()
                         else {
                               if(queue.isEmpty)
                                  sender ! NoLinks
                                  else
                                  {
                                   println(limit + " more links to do")
                                    limit = limit -1
                                    sender ! FetchLink(queue.dequeue)
                                  }
                                }


    case Page(url,html)    =>  parseQueue ! Page(url,html)

    case QueueLink(url)    => queue.enqueue(url)
  }

} 
开发者ID:juconghe,项目名称:web-crawler,代码行数:39,代码来源:LinkQueueActor.scala


示例3: Function

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

import scala.collection.mutable.{Set, Queue}

sealed class Function(funName: String) extends Iterable[BasicBlock] {
  private val _name: String = funName
  private var _first: BasicBlock = null

  def name: String = _name

  def first: BasicBlock = _first

  def first_=(bb: BasicBlock): Unit = _first = bb

  override def iterator: Iterator[BasicBlock] = new Iterator[BasicBlock] {
    private val visited = Set[BasicBlock]()
    private val queue = new Queue[BasicBlock]() += first

    def hasNext = ! queue.isEmpty

    def next = {
      val res = queue.dequeue
      visited += res
      res foreach {
        case B(cond, ifBB, elseBB) => {
          if (! (visited contains ifBB) && ! (queue contains ifBB)) {
            queue += ifBB
          }
          if (! (visited contains elseBB) && ! (queue contains elseBB)) {
            queue += elseBB
          }
        }
        case _ =>
      }
      res
    }
  }

  
  def traverseInstructions(action: Instruction => Unit): Unit =
    traverseBB(bb => bb foreach action)

  override def toString(): String = {
    var res = "fun " + name + " {\n"
    this foreach (bb => res += "" + bb + "\n")
    res += "}\n"
    res
  }
} 
开发者ID:fabian-r,项目名称:scanalyzer,代码行数:51,代码来源:Function.scala


示例4:

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

import cfg._
import util._

import scala.collection.mutable.{Set, Queue, Map}


    val depMap = Map[Named, Set[Named]]()

    setUpDependencyMap(depMap)

    Util.dbgmsg("Dependencies:")
    if (Util.dbg) {
      depMap foreach {
        case (Named(n), s) => Util.dbgmsg("  " + n + " ->" + Util.strIt(s))
        case _ =>
      }
    }

    val queue = new Queue[Named]

    queue ++= depMap.keys

    while (! queue.isEmpty) {
      Util.dbgmsg("Queue: " + Util.strIt(queue))

      val current = queue.dequeue
      val before = symtab(current.Name)
      eval(current)
      val after = symtab(current.Name)

      Util.dbgmsg("Transform `" + current.Name + "` from `" + before +
        "` to `" + after)

      if (after != before) {
        val add = (depMap(current) filterNot (queue contains _))
        Util.dbgmsg("  ~> Adding `" + Util.strIt(add) + "` to queue")
        queue ++= add
      }
    }
  }
} 
开发者ID:fabian-r,项目名称:scanalyzer,代码行数:45,代码来源:SimpleValueIterationAnalysis.scala


示例5: ParseQueueActor

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

import scala.collection.mutable.Queue
import akka.actor.Actor
import akka.actor.{ActorRef, ActorLogging}


class ParseQueueActor(indexer: ActorRef) extends Actor with ActorLogging {
  log.info("ParseQueueActor created")
  var linkQueue: Option[ActorRef] = None
  val queue = Queue[ParsePage]()

  def receive = {
    case Page(url, html) => {
      println("ParseQueueActor receive Page Messaged\n" + sender)

      if (linkQueue == None)
        linkQueue = Some(sender)
        println("sending checkpage to indexer\n" + linkQueue.get)
        indexer ! CheckPage(url,html)
      }

    case ParsePage(url,html) => {
                                println("ParseQueueActor receive ParsePage Message\n" + sender)
                                  queue.enqueue(ParsePage(url,html))
                                }
    case NeedPage            => {
                                    println("ParseQueueActor receive NeedPage Message\n" + sender)
                                    if(!queue.isEmpty)
                                    sender ! queue.dequeue
                                    else
                                    sender ! NoPages
                                  }

    case Link(url)           => {
      println("ParseQueueActor receive Link Message\n" + sender)
      indexer ! CheckLink(url)
    }
    case Word(url,word)      => {
      println("ParseQueueActor receive word Message\n" + sender)
      indexer ! (Word(url,word))
    }
    case QueueLink(url)      =>
    {
      println("ParseQueueActor receive QueueLink Message\n" + sender)
      linkQueue.get ! (QueueLink(url))
    }
    // MORE TO BE DONE HERE...
  }
} 
开发者ID:amherst-takeout,项目名称:asn-inverted-index-student-master,代码行数:51,代码来源:ParseQueueActor.scala


示例6: LinkQueueActor

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

import scala.collection.mutable.Queue
import scala.collection.mutable.Set
import akka.actor.{Actor, ActorRef, ActorLogging}


class LinkQueueActor(parseQueue: ActorRef) extends Actor with ActorLogging {
  // We have provided some definitions below which will help you with
  // you implementation. You are welcome to modify these, however, this
  // is what we used for our implementation.
  log.info("LinkQueueActor created")
  val queue        = Queue[String]()
  val fetchers     = Set[ActorRef]()
  var limit        = 500

  def receive = {
    case NeedLink =>   {   println("LinkQueueActor receive NeedLink Message\n" + sender)
                            if(limit == 0){
                             context.system.shutdown() }
                             else {
                               limit = limit -1;
                               if(queue.isEmpty)
                                  sender ! NoLinks
                                  else{
                                  sender ! FetchLink(queue.dequeue)
                                }
                             }
                           }

    case Page(url,html)    =>    { println("LinkQueueActor receive Page Message\n" + sender)
                                  parseQueue ! Page(url,html)
                                }

    case QueueLink(url) =>      {
      println("LinkQueueActor receive QueueLink Message\n" + sender)
      queue.enqueue(url)
      println(queue.size)
    }
  }

} 
开发者ID:amherst-takeout,项目名称:asn-inverted-index-student-master,代码行数:43,代码来源:LinkQueueActor.scala


示例7: Palindrome

//设置package包名称以及导入依赖的类
package de.tu_berlin.dima.bdapro.flink.palindrome.omarflores16

import org.apache.flink.api.scala._
import org.apache.flink.util.Collector

import scala.collection.mutable.Queue

object Palindrome {
  def main(args: Array[String]){

    if (args.length != 1) {
      Console.err.println("Usage: <jar> inputPath outputPath")
      System.exit(-1)
    }

    var maxStringPalindrome = 0
    val inputPath = args(0)
    val env = ExecutionEnvironment.getExecutionEnvironment

    val lineText = env.readTextFile(inputPath)
      .flatMap( _.toLowerCase.trim.split("\\n") filter { _.nonEmpty } )
      .map{ strPalindrome =>  (strPalindrome.size,strPalindrome,palindromeFunc(strPalindrome))}

    for (t <- lineText.max(0).collect())
      maxStringPalindrome = t._1

    val finalTuple = lineText
      .reduceGroup{
        (in, out: Collector[(String)]) =>
          for (t <- in) {
            if (t._3 && t._1 >= maxStringPalindrome)
              out.collect("The biggest palindrome sentence: " + t._2)
          }
      }
    finalTuple.writeAsText("Output")
    env.execute("bdapro-ws1617-flink")
  }

  def palindromeFunc(phrase: String): Boolean ={
    var qPalindrome = new Queue[(Char)]
    var isEqually: Boolean = true

    (phrase).foreach( (w: Char) => if (!w.isSpaceChar)
      qPalindrome.enqueue(w.toLower) )

    while(qPalindrome.size > 1 && isEqually){
      val wFirst = qPalindrome.dequeue().toString
      qPalindrome = qPalindrome.reverse
      val wLast =  qPalindrome.dequeue().toString
      qPalindrome = qPalindrome.reverse

      if (wFirst != wLast)
        isEqually = false
    }

    return isEqually
  }

} 
开发者ID:cristiprg,项目名称:BDAPRO.GlobalStateML,代码行数:60,代码来源:Palindrome.scala


示例8: SimpleTaskRunner

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

//package scala.concurrent
package com.biosimilarity.lift.lib.concurrent

import scala.collection.mutable.Queue

trait SimpleTaskRunners extends TaskRunnersBase {
  
  type TaskRunner = SimpleTaskRunner
  
  class SimpleTaskRunner extends AbstractSequentialTaskRunner {
    val runq = new Queue[Task]()

    val maxNest = 10//150
    var curNest = 0

    def submitTask(f:Task) {
      if (curNest < maxNest) {
        curNest += 1
        f();
      } else {
        curNest = 0
        runq += f
      }
    }

    def waitUntilFinished() {
      while(!runq.isEmpty) {
        val k = runq.dequeue();
        k()
      }
    }

  }
  
  def createDefaultTaskRunner() = new SimpleTaskRunner

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


示例9: TestableQueueInputDStream

//设置package包名称以及导入依赖的类
package org.apache.spark.streaming

import java.io.{ObjectInputStream, ObjectOutputStream}

import org.apache.spark.rdd.{RDD, UnionRDD}
import org.apache.spark.streaming.dstream.InputDStream

import scala.collection.mutable.{ArrayBuffer, Queue}
import scala.reflect.ClassTag

class TestableQueueInputDStream[T: ClassTag](
                                              ssc: StreamingContext,
                                              val queue: Queue[RDD[T]],
                                              oneAtATime: Boolean,
                                              defaultRDD: RDD[T]
                                              ) extends InputDStream[T](ssc) {

  override def start() { }

  override def stop() { }

  private def readObject(in: ObjectInputStream): Unit = {
    logWarning("queueStream doesn't support checkpointing")
  }

  private def writeObject(oos: ObjectOutputStream): Unit = {
    logWarning("queueStream doesn't support checkpointing")
  }

  override def compute(validTime: Time): Option[RDD[T]] = {
    val buffer = new ArrayBuffer[RDD[T]]()
    queue.synchronized {
      if (oneAtATime && queue.nonEmpty) {
        buffer += queue.dequeue()
      } else {
        buffer ++= queue
        queue.clear()
      }
    }
    if (buffer.nonEmpty) {
      if (oneAtATime) {
        Some(buffer.head)
      } else {
        Some(new UnionRDD(context.sc, buffer.toSeq))
      }
    } else if (defaultRDD != null) {
      Some(defaultRDD)
    } else {
      Some(ssc.sparkContext.emptyRDD)
    }
  }

} 
开发者ID:tmalaska,项目名称:SparkUnitTestingExamples,代码行数:54,代码来源:TestableQueueInputDStream.scala


示例10: RuntimeStats

//设置package包名称以及导入依赖的类
//case class Stats(runtime_pc: Int,runtime_bbds: Int, runtime_gts: Int)
package com.models

import scala.collection.mutable.ListBuffer
import scala.collection.mutable.Queue

trait RuntimeStats

object RuntimeStats{
    
    case class RuntimeStats(time_stamp: String, num_records_returned: Int, runtime_pc: Int, runtime_bbds: Int, runtime_gts: Int, runtime_ss: Int)
    
    val sample_stats = ListBuffer[RuntimeStats](
        RuntimeStats("2016-03-22", 3, 3970, 69, 6853, 466),
        RuntimeStats("2016-03-21", 4, 4970, 59, 9853, 766),
        RuntimeStats("2016-03-20", 7, 7970, 49, 3853, 66),
        RuntimeStats("2016-03-19", 8, 8970, 39, 1853, 366),
        RuntimeStats("2016-03-18", 5, 5970, 29, 853, 466)
      )
      
    val stats = Queue[RuntimeStats](
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0)
      )

} 
开发者ID:dbdev138,项目名称:DEV-FYP-Process-Controller-Service,代码行数:30,代码来源:RuntimeStats.scala


示例11: RuntimeStats

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

import scala.collection.mutable.ListBuffer
import scala.collection.mutable.Queue

trait RuntimeStats

object RuntimeStats{
    
    //Model: To store runtime statistics
    case class RuntimeStats(time_stamp: String, num_records_returned: Int, runtime_pc: Int, runtime_bbds: Int, runtime_gts: Int, runtime_ss: Int)
    
    //Collection: Sample statistics
    val sample_stats = ListBuffer[RuntimeStats](
        RuntimeStats("2016-03-22", 3, 3970, 69, 6853, 466),
        RuntimeStats("2016-03-21", 4, 4970, 59, 9853, 766),
        RuntimeStats("2016-03-20", 7, 7970, 49, 3853, 66),
        RuntimeStats("2016-03-19", 8, 8970, 39, 1853, 366),
        RuntimeStats("2016-03-18", 5, 5970, 29, 853, 466)
      )
      
    //Collection: Queue comprised of null value entries
    val stats = Queue[RuntimeStats](
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0),
        RuntimeStats("", 0, 0, 0, 0, 0)
      )

} 
开发者ID:microdg,项目名称:BETA-Process-Controller-Service,代码行数:32,代码来源:RuntimeStats.scala


示例12: Button

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

import java.awt.event._
import javax.swing._
import scala.collection.mutable.Queue
import core.main._, core.pieces._, core.shapes.dim0._, core.shapes.dim1._, core.shapes.dim2._, core.shapes.forces._

object Button {
  sealed trait State {
    def is(x: State) = eq(x)|(if(eq(DOWN_NEW)) x.eq(DOWN) else if(eq(UP_NEW)) x.eq(UP) else false)
    def then(x: State): State = if(strip == x) x else if(isDown) UP_NEW else DOWN_NEW
    def then(x: Boolean): State = then((if(x == true) DOWN else UP))
    lazy val isDown = is(DOWN)
    lazy val isDownNew = is(DOWN_NEW)
    lazy val isUp = is(UP)
    lazy val isUpNew = is(UP_NEW)
    lazy val isNew = is(DOWN_NEW)|is(UP_NEW)
    lazy val strip = if(isDown) DOWN else UP
  }
  case object DOWN extends State
  case object UP extends State
  case object DOWN_NEW extends State
  case object UP_NEW extends State
}

class UserInput(
      val key: Map[Char,Button.State] = Map(' ' -> Button.UP).withDefaultValue(Button.UP),
      val mb: Map[Char,Button.State] = Map('r' -> Button.UP, 'l' -> Button.UP, 'm' -> Button.UP),
      val mouse: Point = new PointImpl(0,0)
  ){
  lazy val mouseX = mouse.x
  lazy val mouseY = mouse.y
  lazy val mbRight = mb('r')
  lazy val mbLeft = mb('l')
  lazy val mbMiddle = mb('m')
  def getNext(keys: Queue[(Char,Boolean)], mbs: (Char,Boolean,Point), mPos: Point) = {
    var newKey: Map[Char,Button.State] = key.map{case (a,b)=>(a,b.strip)}
    keys.foreach(x => newKey = newKey + (x._1 -> key(x._1).then(x._2))) 
    new UserInput(
      newKey.withDefaultValue(Button.UP),
      mb.map{case (a,b)=>(a,b.strip)} + (if(mbs==null) 'n'->Button.UP else mbs._1->mb(mbs._1).then(mbs._2)),
      if(mbs == null){mPos}else{mbs._3})
  }
} 
开发者ID:radiotech,项目名称:FlatLand,代码行数:45,代码来源:UserInput.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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