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

Scala HashSet类代码示例

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

本文整理汇总了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);
} 
开发者ID:ipogudin,项目名称:data-processing-examples,代码行数:29,代码来源:App.scala


示例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)
  }


} 
开发者ID:ralreiroe,项目名称:embarcadero,代码行数:21,代码来源:SetOrderTest.scala


示例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)
  }

} 
开发者ID:ralreiroe,项目名称:embarcadero,代码行数:53,代码来源:DuplicatesRemovalTest.scala


示例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])
      }
    }
  }

} 
开发者ID:JohnnyCosta,项目名称:graphcheck,代码行数:62,代码来源:CalculateImportance.scala


示例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 _ =>
    }
  }
} 
开发者ID:arguslab,项目名称:argus-cit-intellij,代码行数:33,代码来源:JawaTypeHierarchyProvider.scala


示例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) 
开发者ID:raviguntur,项目名称:TextAnalytics,代码行数:19,代码来源:Commons.scala


示例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")
  }

} 
开发者ID:tophua,项目名称:spark1.52,代码行数:18,代码来源:MutableSet.scala


示例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:_*)
  }

} 
开发者ID:velkoborsky,项目名称:scaffvis,代码行数:33,代码来源:Molecules.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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