multimap.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 44 行

SCALA
44
字号
/*                     __                                               *\**     ________ ___   / /  ___     Scala API                            ****    / __/ __// _ | / /  / _ |    (c) 2003-2006, LAMP/EPFL             ****  __\ \/ /__/ __ |/ /__/ __ |                                         **** /____/\___/_/ |_/____/_/ | |                                         ****                          |/                                          **\*                                                                      */// $Id: MultiMap.scala 8837 2006-10-04 12:18:48Z michelou $package scala.collection.mutable/** This class is typically used as a mixin. It turns maps which map <code>A</code> *  to <code>Set[B]</code> objects into multi maps which map <code>A</code> to *  <code>B</code> objects. * *  @author  Matthias Zenger *  @version 1.0, 08/07/2003 */trait MultiMap[A, B] extends Map[A, Set[B]] {  protected def makeSet: Set[B] = new HashSet[B]  def add(key: A, value: B): Unit = get(key) match {    case None =>      val set = makeSet      set += value      this(key) = set    case Some(set) =>      set += value  }  def remove(key: A, value: B) = get(key) match {    case None =>    case Some(set) => set -= value  }  def entryExists(key: A, p: B => Boolean): Boolean = get(key) match {    case None => false    case Some(set) => set exists p  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?