本文整理汇总了Scala中collection.mutable.HashMap类的典型用法代码示例。如果您正苦于以下问题:Scala HashMap类的具体用法?Scala HashMap怎么用?Scala HashMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HashMap类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Graph
//设置package包名称以及导入依赖的类
package ppl.dsl.optiml.datastruct.scala
import ppl.dsl.optila.datastruct.scala._
import collection.mutable.{HashMap}
class Graph[VD:Manifest,ED:Manifest] {
// TODO: we are storing a lot of data here. investigate reducing the footprint vs. performance.
var _edgeToVertices = HashMap[Edge[VD,ED], (Vertex[VD,ED], Vertex[VD,ED])]()
// var verticesToEdges = HashMap[(V, V), E]()
// this is used only during construction (before frozen), for fast sorting
var _adjacencies = HashMap[Vertex[VD,ED], List[(Edge[VD,ED], Vertex[VD,ED])]]()
// this is used only after construction (after frozen), for fast access
// Map from vertex to id
val _vertexIds = HashMap[Vertex[VD,ED], Int]()
var _vertices : Array[Vertex[VD,ED]] = null
var _edges : Array[Edge[VD,ED]] = null
var _vertexEdges : Array[DenseVector[Edge[VD,ED]]] = null
var _neighbors : Array[DenseVector[Vertex[VD,ED]]] = null
var _neighborsSelf : Array[DenseVector[Vertex[VD,ED]]] = null
var _frozen = false
}
示例2: LabelData
//设置package包名称以及导入依赖的类
package ppl.dsl.deliszt.datastruct.scala
import collection.mutable.{Map, HashMap}
class LabelData[MO<:MeshObj] {
val data: Map[String,Array[Object]] = new HashMap[String,Array[Object]]()
val fns: Map[String,Object => Object] = new HashMap[String,Object => Object]()
}
trait MeshObj {
def id : Int
}
trait Vertex extends MeshObj
trait Edge extends MeshObj
trait Face extends MeshObj
trait Cell extends MeshObj
class Mesh {
implicit val vertexData = new LabelData[Vertex]
var nvertices : Int = 0
var nedges : Int = 0
var nfaces : Int = 0
var ncells : Int = 0
var vtov : CRS = null
var vtoe : CRS = null
var vtof : CRS = null
var vtoc : CRS = null
var etov : CRS = null
var etof : CRS = null
var etoc : CRS = null
var ftov : CRS = null
var ftoe : CRS = null
var ftoc : CRS = null
var ctov : CRS = null
var ctoe : CRS = null
var ctof : CRS = null
var ctoc : CRS = null
}
示例3: PerformanceTimer
//设置package包名称以及导入依赖的类
package ppl.delite.benchmarking.sorting.tpch.util
import collection.mutable.{ArrayBuffer, HashMap}
object PerformanceTimer
{
val currentTimer = new HashMap[String, Long]
val times = new HashMap[String, ArrayBuffer[Double]]
def start(component: String, printMessage: Boolean = true) {
if (!times.contains(component)) {
times += component -> new ArrayBuffer[Double]()
}
if (printMessage) println("[METRICS]: Timing " + component + " #" + times(component).size + " started")
currentTimer += component -> System.currentTimeMillis
}
def stop(component: String, printMessage: Boolean = true) {
val x = (System.currentTimeMillis - currentTimer(component)) / 1000D
times(component) += x
if (printMessage) println("[METRICS]: Timing " + component + " #" + (times(component).size - 1) + " stopped")
}
def totalTime(component: String) {
val total = times(component).toList.reduceLeft[Double](_+_)
println("[METRICS]: total time for component " + component + ": " + total)
}
def clearAll() {
for((k,v) <- times) {
v.clear
}
}
def print(component: String) {
val timeStr = times.get(component) map { "[METRICS]: Latest time for component " + component + ": " + _.last.formatted("%.6f") + "s" }
println(timeStr getOrElse "[METRICS]: No data for component " + component)
}
}
示例4: User
//设置package包名称以及导入依赖的类
import collection.mutable.HashMap
import scala.util.Try
case class User(name : String, roles: List[String])
case class UserRepository(userDictionary: HashMap[Int,User]){
def findUser(id: Int): User = {
if (userDictionary.keySet.exists(_ == id)){
userDictionary(id)
} else {
null
}
}
}
object GetRolesById {
def tryToInt( s: String ) = Try(s.toInt).getOrElse(-1)
def main(args:Array[String]):Unit = {
val userDictInit = HashMap(1 -> User("mickey",List("admin","content manager")),2 -> User("donald",List("user")))
val userRepository = UserRepository(userDictInit)
if (!args.isEmpty){
val user = userRepository.findUser(tryToInt(args(0)))
if (user!= null) {
user.roles.map(x => println("Role: "+x))
}
}
}
}
示例5: JavaLoggerStatsReceiver
//设置package包名称以及导入依赖的类
package com.twitter.finagle.stats
import collection.mutable.HashMap
import com.twitter.conversions.time._
import com.twitter.finagle.netty3.Conversions._
import com.twitter.finagle.util.DefaultTimer
import com.twitter.util.{Timer, TimerTask}
import java.util.logging.Logger
class JavaLoggerStatsReceiver(logger: Logger, timer: Timer)
extends StatsReceiverWithCumulativeGauges
{
val repr = logger
var timerTasks = new HashMap[Seq[String], TimerTask]
// Timer here will never be released. This is ok since this class
// is used for debugging only.
def this(logger: Logger) = this(logger, DefaultTimer.twitter)
def stat(name: String*) = new Stat {
def add(value: Float) {
logger.info("%s add %f".format(formatName(name), value))
}
}
def counter(name: String*) = new Counter {
def incr(delta: Int) {
logger.info("%s incr %d".format(formatName(name), delta))
}
}
protected[this] def registerGauge(name: Seq[String], f: => Float) = synchronized {
deregisterGauge(name)
timerTasks(name) = timer.schedule(10.seconds) {
logger.info("%s %2f".format(formatName(name), f))
}
}
protected[this] def deregisterGauge(name: Seq[String]) {
timerTasks.remove(name) foreach { _.cancel() }
}
private[this] def formatName(description: Seq[String]) = {
description mkString "/"
}
}
object JavaLoggerStatsReceiver {
def apply(): JavaLoggerStatsReceiver =
new JavaLoggerStatsReceiver(Logger.getLogger("Finagle"))
}