synchronizedpriorityqueue.scala

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

SCALA
100
字号
/*                     __                                               *\**     ________ ___   / /  ___     Scala API                            ****    / __/ __// _ | / /  / _ |    (c) 2003-2006, LAMP/EPFL             ****  __\ \/ /__/ __ |/ /__/ __ |                                         **** /____/\___/_/ |_/____/_/ | |                                         ****                          |/                                          **\*                                                                      */// $Id: SynchronizedPriorityQueue.scala 10203 2007-03-05 14:21:28Z odersky $package scala.collection.mutable/** This class implements synchronized priority queues using a heap. *  The elements of the queue have to be ordered in terms of the *  <code>Ordered[T]</code> class. * *  @author  Matthias Zenger *  @version 1.0, 03/05/2004 */class SynchronizedPriorityQueue[A <% Ordered[A]] extends PriorityQueue[A] {  /** Checks if the queue is empty.   *   *  @return true, iff there is no element in the queue.   */  override def isEmpty: Boolean = synchronized { super.isEmpty }  /** Inserts a single element into the priority queue.   *   *  @param  elem        the element to insert   */  override def +=(elem: A): Unit = synchronized { super.+=(elem) }  /** Adds all elements provided by an <code>Iterable</code> object   *  into the priority queue.   *   *  @param  iter        an iterable object   */  override def ++=(iter: Iterable[A]): Unit = synchronized { super.++=(iter) }  /** Adds all elements provided by an iterator into the priority queue.   *   *  @param  it        an iterator   */  override def ++=(it: Iterator[A]): Unit = synchronized { super.++=(it) }  /** Adds all elements to the queue.   *   *  @param  elems       the elements to add.   */  override def enqueue(elems: A*): Unit = synchronized { super.++=(elems) }  /** Returns the element with the highest priority in the queue,   *  and removes this element from the queue.   *   *  @return   the element with the highest priority.   */  override def dequeue(): A = synchronized { super.dequeue }  /** Returns the element with the highest priority in the queue,   *  or throws an error if there is no element contained in the queue.   *   *  @return   the element with the highest priority.   */  override def max: A = synchronized { super.max }  /** Removes all elements from the queue. After this operation is completed,   *  the queue will be empty.   */  override def clear(): Unit = synchronized { super.clear }  /** Returns an iterator which yiels all the elements of the priority   *  queue in descending priority order.   *   *  @return  an iterator over all elements sorted in descending order.   */  override def elements: Iterator[A] = synchronized { super.elements }  /** Checks if two queues are structurally identical.   *   *  @return true, iff both queues contain the same sequence of elements.   */  override def equals(that: Any): Boolean = synchronized { super.equals(that) }  /** The hashCode method always yields an error, since it is not   *  safe to use mutable queues as keys in hash tables.   *   *  @return never.   */  override def hashCode(): Int = synchronized { super.hashCode() }  /** Returns a textual representation of a queue as a string.   *   *  @return the string representation of this queue.   */  override def toString(): String = synchronized { super.toString() }}

⌨️ 快捷键说明

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