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

Scala VectorBuilder类代码示例

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

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



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

示例1: maintainSum

//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary

import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.ChangeSet
import hu.bme.mit.ire.util.GenericMath

import scala.collection.immutable.VectorBuilder
import scala.collection.mutable

trait SumLike {
  val sums = new mutable.HashMap[Tuple, Any].withDefault(d => 0)

  def maintainSum(changeSet: ChangeSet, aggregationKeys: Vector[Int], sumKey: Int): ChangeSet = {
    val oldValues = new mutable.HashMap[Tuple, Any]

    for (tuple <- changeSet.positive;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = sums(key)
      }
      sums(key) = GenericMath.plus(sums(key), tuple(sumKey))
    }

    for (tuple <- changeSet.negative;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = sums(key)
      }
      sums(key) = GenericMath.minus(sums(key), tuple(sumKey))
    }

    val positive = new VectorBuilder[Tuple]
    val negative = new VectorBuilder[Tuple]
    for ((key, oldValue) <- oldValues) {
      if (oldValue != 0) {
        negative += key :+ oldValues(key)
      }
      if (sums(key) != 0) {
        positive += key :+ sums(key)
      }
    }

    return ChangeSet(positive = positive.result(), negative = negative.result())
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:46,代码来源:SumLike.scala


示例2: Level

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

import java.io._
import scala.collection.immutable.VectorBuilder

sealed trait Level
object Level {
  case object Info extends Level
  case object Warning extends Level
  case object Error extends Level

  def fromString(level: String): Level = level.toLowerCase match {
    case "info" => Info
    case "warning" => Warning
    case "error" => Error
    case _ => sys.error("Unknown level: " + level)
  }
}

case class DictionaryEntry(pattern: String, level: Level, message: String)

case class Dictionary(entries: Seq[DictionaryEntry]) {
  private[this] val lookup = entries flatMap { entry =>
    val pattern = entry.pattern
    val upperPattern = pattern.toUpperCase
    val lowerPattern = pattern.toLowerCase
    val sentencePattern = pattern.head.toUpper + pattern.tail

    val targets = Seq(pattern, upperPattern, lowerPattern, sentencePattern)
    targets.distinct map { target => target -> entry }
  } toMap

  def get(pattern: String): Option[DictionaryEntry] =
    lookup.get(pattern)
}

object Dictionary {
  private[this] val LineEntry = """([^;]+?);([^;]+?);(.*)""".r

  def parse(path: String): Dictionary = {
    val reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)))
    try {
      val entries = new VectorBuilder[DictionaryEntry]

      var line: String = null
      while ({ line = reader.readLine(); line != null }) {
        val LineEntry(patternStr, levelStr, messageStr) = line
        entries += DictionaryEntry(
          pattern = patternStr.trim,
          level = Level.fromString(levelStr),
          message = messageStr.trim
        )
      }

      new Dictionary(entries.result)
    } finally {
      reader.close()
    }
  }
} 
开发者ID:oradian,项目名称:sbt-dictionary-check,代码行数:61,代码来源:DictionaryEntry.scala


示例3: LineRendering

//设置package包名称以及导入依赖的类
package swave.core.graph.impl

import java.lang.StringBuilder
import swave.core.graph.{Digraph, GlyphSet}
import scala.collection.immutable.VectorBuilder
import Infrastructure._

private[graph] object LineRendering {

  def renderLines[V](nodes: Vector[Node], glyphSet: GlyphSet): Digraph.Rendering[V] = {
    var charBuf: Array[Char] = Array.emptyCharArray
    val lines                = new VectorBuilder[String]
    val sb                   = new StringBuilder
    var maxLineLength        = 0

    val vertexRenderings =
      for (node ? nodes) yield {
        val maxChars = node.glyphs.size * glyphSet.columns * 2
        if (charBuf.length < maxChars) charBuf = new Array[Char](maxChars)
        lines.clear()

        for (glyphRow ? 0 until glyphSet.rows) {
          val endIx = node.glyphs.foldLeft(0)((ix, glyph) ? glyphSet.place(glyph, glyphRow, charBuf, ix))
          sb.append(charBuf, 0, endIx)
          // trim whitespace at line end
          while (sb.length > 0 && Character.isWhitespace(sb.charAt(sb.length - 1))) sb.setLength(sb.length - 1)
          // if (glyphRow == glyphSet.rows / 2) sb.append(' ').append(node.xRank.level)
          val line = sb.toString
          maxLineLength = math.max(maxLineLength, line.length)
          lines += line
          sb.setLength(0)
        }

        Digraph.VertexRendering(node.vertex.asInstanceOf[V], lines.result())
      }

    Digraph.Rendering(glyphSet, maxLineLength, vertexRenderings)
  }

} 
开发者ID:sirthias,项目名称:swave,代码行数:41,代码来源:LineRendering.scala


示例4: fixtureState

//设置package包名称以及导入依赖的类
package swave.core.internal.testkit

import scala.collection.immutable.VectorBuilder
import scala.concurrent.{Future, Promise}
import swave.core.impl.stages.StageImpl

private[testkit] trait TestStage extends StageImpl {

  private[this] val resultBuilder = new VectorBuilder[AnyRef]
  private[this] var _resultSize   = 0

  private[this] var _fixtureState: TestFixture.State = TestFixture.State.Starting
  private[this] val _finishedState                   = Promise[TestFixture.State.Finished]()

  private[this] var onElem: AnyRef ? Unit = x ? ()

  def fixtureState: TestFixture.State = _fixtureState
  def fixtureState_=(value: TestFixture.State): Unit = {
    value match {
      case TestFixture.State.Cancelled ? _finishedState.success(TestFixture.State.Cancelled)
      case TestFixture.State.Completed ? _finishedState.success(TestFixture.State.Completed)
      case TestFixture.State.Error(e)  ? _finishedState.failure(e)
      case _                           ?
    }
    _fixtureState = value
  }
  def finishedState: Future[TestFixture.State.Finished] = _finishedState.future

  private[testkit] final def result[T]: Vector[T] = resultBuilder.result().asInstanceOf[Vector[T]]
  private[testkit] final def resultSize: Int      = _resultSize

  protected final def recordElem(elem: AnyRef): Unit = {
    resultBuilder += elem
    _resultSize += 1
    onElem(elem)
  }

  def appendElemHandler(f: AnyRef ? Unit): Unit = {
    val prev = onElem
    onElem = { elem ?
      prev(elem)
      f(elem)
    }
  }

  def id: Int

  def formatLong: String

  def scriptedSize: Int
} 
开发者ID:sirthias,项目名称:swave,代码行数:52,代码来源:TestStage.scala


示例5: maintainCount

//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary

import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.ChangeSet

import scala.collection.immutable.VectorBuilder
import scala.collection.mutable

trait CountLike {
  val counts = new mutable.HashMap[Tuple, Int].withDefault(d => 0)
  def maintainCount(changeSet: ChangeSet, aggregationKeys: Vector[Int]): ChangeSet = {
    val oldValues = new mutable.HashMap[Tuple, Int]

    for (tuple <- changeSet.positive;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = counts(key)
      }
      counts(key) += 1
    }

    for (tuple <- changeSet.negative;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = counts(key)
      }
      counts(key) -= 1
    }

    val positive = new VectorBuilder[Tuple]
    val negative = new VectorBuilder[Tuple]
    for ((key, oldValue) <- oldValues) {
      if (oldValue != 0) {
        negative += key :+ oldValues(key)
      }
      if (counts(key) != 0) {
        positive += key :+ counts(key)
      }
    }

    return ChangeSet(positive = positive.result(), negative = negative.result())
  }
} 
开发者ID:FTSRG,项目名称:ire,代码行数:44,代码来源:CountLike.scala


示例6: ExtremeNode

//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary

import hu.bme.mit.ire.SingleForwarder
import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.{ChangeSet, ReteMessage}
import hu.bme.mit.ire.util.SizeCounter

import scala.collection.immutable.VectorBuilder
import scala.collection.mutable

abstract class ExtremeNode(override val next: (ReteMessage) => Unit,
                           val aggregationKeys: Vector[Int],
                           val extremeKey: Int,
                           override val expectedTerminatorCount: Int = 1
                          ) extends UnaryNode with SingleForwarder {
  val data = new mutable.HashMap[Vector[Any], mutable.SortedSet[Tuple]]()
  implicit val order : Ordering[Tuple]

  override def onSizeRequest(): Long = SizeCounter.count(data.values)

  override def onChangeSet(changeSet: ChangeSet): Unit = {

    val oldValues = new mutable.HashMap[Vector[Any], Option[Any]]

    for (tuple <- changeSet.positive;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = data.get(key).map(_.last(extremeKey))
      }
      data.getOrElseUpdate(key, mutable.SortedSet[Tuple]()) += tuple
    }

    for (tuple <- changeSet.negative;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = data.get(key).map(_.last(extremeKey))
      }
      data(key) -= tuple
    }
    val positive = new VectorBuilder[Tuple]
    val negative = new VectorBuilder[Tuple]
    for ((key, oldValue) <- oldValues) {
      if (oldValue.isEmpty || data(key) != oldValue.get)
        if (oldValue.isDefined) {
          negative += key :+ oldValues(key).get
        }

      positive += key :+ data(key).last(extremeKey)
    }

    forward(ChangeSet(positive = positive.result(), negative = negative.result()))
  }

} 
开发者ID:FTSRG,项目名称:ire,代码行数:55,代码来源:ExtremeNode.scala


示例7: CollectNode

//设置package包名称以及导入依赖的类
package hu.bme.mit.ire.nodes.unary

import hu.bme.mit.ire.SingleForwarder
import hu.bme.mit.ire.datatypes._
import hu.bme.mit.ire.messages.{ChangeSet, ReteMessage}
import hu.bme.mit.ire.util.SizeCounter

import scala.collection.immutable.VectorBuilder
import scala.collection.mutable
import scala.collection.mutable.ListBuffer

class CollectNode(override val next: (ReteMessage) => Unit,
                  val aggregationKeys: Vector[Int],
                  val collectKey: Int) extends UnaryNode with SingleForwarder {
  val collections = new mutable.HashMap[Tuple, ListBuffer[Any]].withDefault(d => new ListBuffer())

  override def onSizeRequest(): Long = SizeCounter.count(collections.values)

  def maintainCollections(changeSet: ChangeSet, aggregationKeys: Vector[Int], collectKey: Int): ChangeSet = {
    val oldValues = new mutable.HashMap[Tuple, ListBuffer[Any]]

    for (tuple <- changeSet.positive;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = collections(key)
      }
      collections(key) = collections(key) :+ tuple(collectKey)
    }

    for (tuple <- changeSet.negative;
         key = aggregationKeys.map(tuple(_))) {
      if (!oldValues.contains(key)) {
        oldValues(key) = collections(key)
      }
      collections(key) = collections(key) - tuple(collectKey)
    }

    val positive = new VectorBuilder[Tuple]
    val negative = new VectorBuilder[Tuple]
    for ((key, oldValue) <- oldValues) {
      if (!oldValue.isEmpty) {
        negative += key :+ oldValues(key).toVector
      }
      if (!collections(key).isEmpty) {
        positive += key :+ collections(key).toVector
      }
    }

    return ChangeSet(positive = positive.result(), negative = negative.result())
  }

  override def onChangeSet(changeSet: ChangeSet): Unit = {
    val newChangeSet = maintainCollections(changeSet, aggregationKeys, collectKey)
    forward(newChangeSet)
  }

} 
开发者ID:FTSRG,项目名称:ire,代码行数:58,代码来源:CollectNode.scala


示例8: getPostSummaries

//设置package包名称以及导入依赖的类
package docs.home.scaladsl.persistence

//#imports
import scala.collection.immutable
import scala.collection.immutable.VectorBuilder
import akka.NotUsed
import com.lightbend.lagom.scaladsl.api.Service
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.jdbc.JdbcSession

//#imports

trait JdbcReadSideQuery {

  trait BlogService extends Service {
    def getPostSummaries(): ServiceCall[NotUsed, immutable.IndexedSeq[PostSummary]]

    override def descriptor = ???
  }

  //#service-impl
  class BlogServiceImpl(jdbcSession: JdbcSession) extends BlogService {
    import JdbcSession.tryWith

    override def getPostSummaries() = ServiceCall { request =>
      jdbcSession.withConnection { connection =>
        tryWith(connection.prepareStatement("SELECT id, title FROM blogsummary")) { ps =>
          tryWith(ps.executeQuery()) { rs =>
            val summaries = new VectorBuilder[PostSummary]
            while (rs.next()) {
              summaries += PostSummary(rs.getString("id"), rs.getString("title"))
            }
            summaries.result()
          }
        }
      }
    }
    //#service-impl

  }
} 
开发者ID:lagom,项目名称:lagom,代码行数:42,代码来源:JdbcReadSideQuery.scala


示例9: FileUtil

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

import java.io.File

import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
import io.github.lukehutch.fastclasspathscanner.matchprocessor.FileMatchContentsProcessorWithContext
import sangria.parser.QueryParser
import sangria.parser.DeliveryScheme.Throw
import spray.json._

import scala.collection.immutable.VectorBuilder
import scala.io.Source

import net.jcazevedo.moultingyaml._


object FileUtil {
  def loadQuery(name: String) =
    loadResource("queries/" + name)

  def loadYaml(name: String, root: String = "scenarios") =
    loadResource(root + "/" + name).parseYaml

  def loadScenarios(path: String, root: String = "scenarios") = this.synchronized {
    val builder = new VectorBuilder[ScenarioFile]

    new FastClasspathScanner(root + "." + path).matchFilenameExtension("yaml", new FileMatchContentsProcessorWithContext {
      override def processMatch(file: File, relativePath: String, fileContents: Array[Byte]) = {
        builder += ScenarioFile(file.getName, relativePath, new String(fileContents, "UTF-8").parseYaml)
      }
    }).scan()

    builder.result()
  }

  def loadSchema(path: String) =
    QueryParser.parse(loadResource(path))

  def loadTestData(path: String): Either[YamlValue, JsValue] = {
    val text = loadResource(path)

    if (path endsWith ".yaml") Left(text.parseYaml)
    else if (path endsWith ".json") Right(text.parseJson)
    else throw new IllegalArgumentException(s"Unsupported file format for test data '$path'. Only `*.json` and `*.yaml` files are supported.")
  }

  def loadResource(path: String) =
    Option(this.getClass.getResourceAsStream("/" + path)) match {
      case Some(res) ? Source.fromInputStream(res, "UTF-8").mkString
      case None ? throw new IllegalArgumentException("Resource not found: /" + path)
    }

  case class ScenarioFile(fileName: String, path: String, scenario: YamlValue) {
    def folder = path.substring(0, path.lastIndexOf("/"))
  }
} 
开发者ID:gitprowl,项目名称:prowlgria,代码行数:57,代码来源:FileUtil.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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