本文整理汇总了Scala中scala.collection.immutable.HashSet类的典型用法代码示例。如果您正苦于以下问题:Scala HashSet类的具体用法?Scala HashSet怎么用?Scala HashSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HashSet类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: App
//设置package包名称以及导入依赖的类
package spark.test
import scala.collection.immutable.HashSet
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object App {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val f = sc.textFile("/Users/ipogudin/Downloads/wikispeedia/paths_unfinished.tsv")
val r = f
.filter((s: String) => !s.startsWith("#") && s.nonEmpty)
.map((s: String) => s.split(Array('\t', ' ', ';')))
.flatMap((a) => a.drop(3).filter(s => !Filters.isStopWord(s)).map(s => (s, 1)))
.reduceByKey((a, b) => a + b).take(5)
r.map(s => s._1 + "=" + s._2).foreach(println)
sc.stop()
}
}
object Filters {
val stopWords = HashSet("timeout", "restart")
def isStopWord(s: String): Boolean = stopWords.contains(s);
}
示例2: SetOrderTest
//设置package包名称以及导入依赖的类
import org.scalatest._
import scala.collection._
import scala.collection.immutable.HashSet
class SetOrderTest extends FlatSpec with Matchers {
val srclist = List(1000,3,3,2)
"removing duplicates" can "remove original order" in {
def removeDuplicates = {
val immut = HashSet.empty[Int]
srclist.foldLeft(immut){
(acc, curr) => acc.+(curr)
}
}
println(removeDuplicates.head) //Set(2, 1000, 3)
}
}
示例3: DuplicatesRemovalTest
//设置package包名称以及导入依赖的类
import org.scalatest._
import scala.collection.immutable.HashSet
import scala.collection._
class DuplicatesRemovalTest extends FlatSpec with Matchers {
val srclist = List(1000,3,3,2)
"removing duplicates" can "remove original order" in {
def removeDuplicates = {
val immut = HashSet.empty[Int]
srclist.foldLeft(immut){
(acc, curr) => acc.+(curr)
}
}
println(removeDuplicates) //Set(2, 1000, 3)
}
"removing duplicates" can "preserve original order" in {
def removeDuplicates = {
val mut = mutable.LinkedHashSet.empty[Int]
srclist.foldLeft(mut){
(acc,curr) => acc.+=(curr)
}
}
println(removeDuplicates) //Set(1000, 3, 2)
}
"removing duplicates" can "sort at the same time" in {
def removeDuplicates = {
val mut = mutable.SortedSet.empty[Int]
srclist.foldLeft(mut){
(acc,curr) => acc.+=(curr)
}
}
println(removeDuplicates) //TreeSet(2, 3, 1000)
}
"removing duplicates" can "sort at the same time using immutable SortedSet" in {
def removeDuplicates = {
val immut = immutable.SortedSet.empty[Int]
srclist.foldLeft(immut){
(acc,curr) => acc.+(curr)
}
}
println(removeDuplicates) //TreeSet(2, 3, 1000)
}
}
示例4: CalculateImportance
//设置package包名称以及导入依赖的类
package org.gc.calculation
import com.typesafe.scalalogging.Logger
import org.gc.component.{Component, Network}
import scala.collection.immutable.HashSet
class CalculateImportance(val network: Network) {
val log = Logger(classOf[CalculateImportance])
val failureThreshold = 20
val failureScore = 10
val pointOfFailureScore = 10
var subNetwork = new HashSet[Component]
def updateNetwork(startComponent: Component): Set[Component] = {
// Update only the subnet
subNetwork = new HashSet[Component]
DFS(startComponent)
val aps = new CalculateAP(network).findArticulationPoints(startComponent)
for (n <- aps) {
n.asInstanceOf[Component].isPointOfFailure = true
}
for (n <- subNetwork) {
scoreCalculator(n.asInstanceOf[Component])
}
return subNetwork
}
private def scoreCalculator(comp: Component) = {
var finalScore = 0
if (comp.isPointOfFailure) {
finalScore += pointOfFailureScore
}
if (comp.failureRate >= failureThreshold) {
finalScore += failureScore
}
finalScore += comp.userImportanceRate
comp.score = finalScore
}
private def DFS(v: Component) {
subNetwork += v
for (x <- v.adjacentNodes()) {
if (subNetwork.find(x.equals).isEmpty) {
DFS(x.asInstanceOf[Component])
}
}
}
}
示例5: JawaTypeHierarchyProvider
//设置package包名称以及导入依赖的类
package org.argus.cit.intellij.jawa.hierarchy
import com.intellij.ide.hierarchy.HierarchyBrowser
import com.intellij.ide.hierarchy.`type`.JavaTypeHierarchyProvider
import com.intellij.psi.PsiElement
import org.argus.cit.intellij.jawa.lang.psi.api.toplevel.JawaTypeDefinition
import scala.collection.immutable.HashSet
class JawaTypeHierarchyProvider extends JavaTypeHierarchyProvider {
override def createHierarchyBrowser(target: PsiElement): HierarchyBrowser = {
target match {
case clazz: JawaTypeDefinition =>
collectSupers(clazz, new HashSet[JawaTypeDefinition])
case _ =>
}
super.createHierarchyBrowser(target)
}
def collectSupers(clazz: JawaTypeDefinition, visited: HashSet[JawaTypeDefinition]) {
clazz.getSupers.foreach {
case clazz: JawaTypeDefinition =>
if (visited.contains(clazz)) {
println("clazz.getText = " + clazz.getText)
} else {
collectSupers(clazz, visited + clazz)
}
case _ =>
}
}
}
示例6: Commons
//设置package包名称以及导入依赖的类
package com.darkknight.analytics.textsummary.textmodel
import scala.collection.immutable.HashSet
object Commons {
val StopList = HashSet("a","an","and","all",
"be", "become","became",
"can","cannot","could","cant",
"do","done","dont","did",
"find","follow","following","go","gone","him","has","had","how","it","just","know","let",
"lot","was","would","who","their","them","the","that","those"
)
}
case class Story(index : Int, story : String)
case class Phrase(kind: String, phrase: String)
示例7: MutableSet
//设置package包名称以及导入依赖的类
package scalaDemo
object MutableSet {
def main(args: Array[String]):Unit= {
//??
import scala.collection.mutable.Set
val movieSet = Set("Hitch", "Poltergeist")
movieSet += "Shrek"
println(movieSet)
//???
import scala.collection.immutable.HashSet
val hashSet = HashSet("Tomatoes", "Chilies")
println(hashSet + "Coriander")
}
}
示例8: Molecules
//设置package包名称以及导入依赖的类
package scaffvis.client.store.model
import scaffvis.shared.model._
import diode.data.Pot
import scala.collection.immutable.{HashMap, HashSet}
case class Molecules(im: IndexedMolecules,
svg: Map[MoleculeId, Pot[String]] = Map.empty,
selected: Set[MoleculeId] = Set.empty, active: Option[MoleculeId] = None) {
def molecules: Iterable[Molecule] = im.molecules
def scaffoldMolecules(scaffoldId: ScaffoldId) = im.scaffoldIndex.getOrElse(scaffoldId, Set.empty)
def get(moleculeId: MoleculeId): Option[Molecule] = im.moleculeMap.get(moleculeId)
def get_!(moleculeId: MoleculeId): Molecule = im.moleculeMap.apply(moleculeId)
}
case class IndexedMolecules(molecules: Vector[Molecule]) {
val moleculeMap: Map[MoleculeId, Molecule] = HashMap(molecules.map(m => m.id -> m).toSeq:_*)
val scaffoldIndex: Map[ScaffoldId,Set[MoleculeId]] = {
val pairs: Iterable[(ScaffoldId, MoleculeId)] = for {
m <- molecules
s <- m.scaffolds
} yield s -> m.id
val groups: Map[ScaffoldId, Iterable[(ScaffoldId, MoleculeId)]] = pairs.groupBy(_._1)
val index: Map[ScaffoldId, Set[MoleculeId]] = groups.mapValues(i => i.map(_._2).to[HashSet])
HashMap(index.toSeq:_*)
}
}