diff options
author | vsalvis <salvisbergvera@gmail.com> | 2015-06-29 18:56:06 +0200 |
---|---|---|
committer | Janek Bogucki <janekdb@gmail.com> | 2015-10-21 22:30:48 +0100 |
commit | 6ed701004550fa04b8ac2d3419f2ea4141c834ad (patch) | |
tree | e28689413c03483296511086654d17913dba969f /src/library/scala/collection/mutable | |
parent | cea7de026ddcf5aa846edc2b9e2e00b608acda2c (diff) | |
download | scala-6ed701004550fa04b8ac2d3419f2ea4141c834ad.tar.gz scala-6ed701004550fa04b8ac2d3419f2ea4141c834ad.tar.bz2 scala-6ed701004550fa04b8ac2d3419f2ea4141c834ad.zip |
Conform foreach tparam to majority naming convention
'U' is the common choice for the foreach function result tparam.
This command summarises the naming diversity before and after this change.
$ fgrep -r 'def foreach[' *|cut -f2 -d:|cut -f1 -d'('|tr -s ' '|sed 's/override //g'|sort|uniq -c|sort -nr
Before,
80 def foreach[U]
6 def foreach[C]
6 def foreach[B]
4 final def foreach[U]
3 def foreach[S]
2 inline final def foreach[U]
2 def foreach[A]
1 inline final def foreach[specialized
1 final def foreach[B]
1 * def foreach[U]
1 def foreach[Q]
1 def foreach[D]
1 def foreach[A,B,U]
After,
98 def foreach[U]
5 final def foreach[U]
2 inline final def foreach[U]
1 inline final def foreach[specialized
1 * def foreach[U]
1 def foreach[A,B,U]
(@ symbols removed.)
Diffstat (limited to 'src/library/scala/collection/mutable')
9 files changed, 128 insertions, 128 deletions
diff --git a/src/library/scala/collection/mutable/AnyRefMap.scala b/src/library/scala/collection/mutable/AnyRefMap.scala index fccc9d83e6..369d596ec3 100644 --- a/src/library/scala/collection/mutable/AnyRefMap.scala +++ b/src/library/scala/collection/mutable/AnyRefMap.scala @@ -5,23 +5,23 @@ package mutable import generic.CanBuildFrom /** This class implements mutable maps with `AnyRef` keys based on a hash table with open addressing. - * - * Basic map operations on single entries, including `contains` and `get`, + * + * Basic map operations on single entries, including `contains` and `get`, * are typically significantly faster with `AnyRefMap` than [[HashMap]]. * Note that numbers and characters are not handled specially in AnyRefMap; * only plain `equals` and `hashCode` are used in comparisons. - * + * * Methods that traverse or regenerate the map, including `foreach` and `map`, * are not in general faster than with `HashMap`. The methods `foreachKey`, * `foreachValue`, `mapValuesNow`, and `transformValues` are, however, faster * than alternative ways to achieve the same functionality. - * + * * Maps with open addressing may become less efficient at lookup after * repeated addition/removal of elements. Although `AnyRefMap` makes a * decent attempt to remain efficient regardless, calling `repack` * on a map that will no longer have elements removed but will be * used heavily may save both time and storage space. - * + * * This map is not intended to contain more than 2^29^ entries (approximately * 500 million). The maximum capacity is 2^30^, but performance will degrade * rapidly as 2^30^ is approached. @@ -34,50 +34,50 @@ extends AbstractMap[K, V] { import AnyRefMap._ def this() = this(AnyRefMap.exceptionDefault, 16, true) - + /** Creates a new `AnyRefMap` that returns default values according to a supplied key-value mapping. */ def this(defaultEntry: K => V) = this(defaultEntry, 16, true) /** Creates a new `AnyRefMap` with an initial buffer of specified size. - * + * * An `AnyRefMap` can typically contain half as many elements as its buffer size * before it requires resizing. */ def this(initialBufferSize: Int) = this(AnyRefMap.exceptionDefault, initialBufferSize, true) - + /** Creates a new `AnyRefMap` with specified default values and initial buffer size. */ def this(defaultEntry: K => V, initialBufferSize: Int) = this(defaultEntry, initialBufferSize, true) - + private[this] var mask = 0 private[this] var _size = 0 private[this] var _vacant = 0 private[this] var _hashes: Array[Int] = null private[this] var _keys: Array[AnyRef] = null private[this] var _values: Array[AnyRef] = null - + if (initBlank) defaultInitialize(initialBufferSize) - + private[this] def defaultInitialize(n: Int) { - mask = + mask = if (n<0) 0x7 else (((1 << (32 - java.lang.Integer.numberOfLeadingZeros(n-1))) - 1) & 0x3FFFFFFF) | 0x7 _hashes = new Array[Int](mask+1) _keys = new Array[AnyRef](mask+1) _values = new Array[AnyRef](mask+1) } - + private[collection] def initializeTo( m: Int, sz: Int, vc: Int, hz: Array[Int], kz: Array[AnyRef], vz: Array[AnyRef] ) { mask = m; _size = sz; _vacant = vc; _hashes = hz; _keys = kz; _values = vz } - + override def size: Int = _size override def empty: AnyRefMap[K,V] = new AnyRefMap(defaultEntry) - - private def imbalanced: Boolean = + + private def imbalanced: Boolean = (_size + _vacant) > 0.5*mask || _vacant > _size - + private def hashOf(key: K): Int = { if (key eq null) 0x41081989 else { @@ -88,7 +88,7 @@ extends AbstractMap[K, V] if (j==0) 0x41081989 else j & 0x7FFFFFFF } } - + private def seekEntry(h: Int, k: AnyRef): Int = { var e = h & mask var x = 0 @@ -100,7 +100,7 @@ extends AbstractMap[K, V] } e | MissingBit } - + private def seekEntryOrOpen(h: Int, k: AnyRef): Int = { var e = h & mask var x = 0 @@ -114,19 +114,19 @@ extends AbstractMap[K, V] } if (o >= 0) o | MissVacant else e | MissingBit } - + override def contains(key: K): Boolean = seekEntry(hashOf(key), key) >= 0 - + override def get(key: K): Option[V] = { val i = seekEntry(hashOf(key), key) if (i < 0) None else Some(_values(i).asInstanceOf[V]) } - + override def getOrElse[V1 >: V](key: K, default: => V1): V1 = { val i = seekEntry(hashOf(key), key) if (i < 0) default else _values(i).asInstanceOf[V] } - + override def getOrElseUpdate(key: K, defaultValue: => V): V = { val h = hashOf(key) var i = seekEntryOrOpen(h, key) @@ -154,10 +154,10 @@ extends AbstractMap[K, V] } else _values(i).asInstanceOf[V] } - + /** Retrieves the value associated with a key, or the default for that type if none exists * (null for AnyRef, 0 for floats and integers). - * + * * Note: this is the fastest way to retrieve a value that may or * may not exist, if the default null/zero is acceptable. For key/value * pairs that do exist, `apply` (i.e. `map(key)`) is equally fast. @@ -166,22 +166,22 @@ extends AbstractMap[K, V] val i = seekEntry(hashOf(key), key) (if (i < 0) null else _values(i)).asInstanceOf[V] } - - /** Retrieves the value associated with a key. + + /** Retrieves the value associated with a key. * If the key does not exist in the map, the `defaultEntry` for that key - * will be returned instead; an exception will be thrown if no + * will be returned instead; an exception will be thrown if no * `defaultEntry` was supplied. */ override def apply(key: K): V = { val i = seekEntry(hashOf(key), key) if (i < 0) defaultEntry(key) else _values(i).asInstanceOf[V] } - + /** Defers to defaultEntry to find a default value for the key. Throws an * exception if no other default behavior was specified. */ override def default(key: K) = defaultEntry(key) - + private def repack(newMask: Int) { val oh = _hashes val ok = _keys @@ -205,9 +205,9 @@ extends AbstractMap[K, V] i += 1 } } - + /** Repacks the contents of this `AnyRefMap` for maximum efficiency of lookup. - * + * * For maps that undergo a complex creation process with both addition and * removal of keys, and then are used heavily with no further removal of * elements, calling `repack` after the end of the creation can result in @@ -220,7 +220,7 @@ extends AbstractMap[K, V] while (m > 8 && 8*_size < m) m = m >>> 1 repack(m) } - + override def put(key: K, value: V): Option[V] = { val h = hashOf(key) val k = key @@ -243,9 +243,9 @@ extends AbstractMap[K, V] ans } } - + /** Updates the map to include a new key-value pair. - * + * * This is the fastest way to add an entry to an `AnyRefMap`. */ override def update(key: K, value: V): Unit = { @@ -267,12 +267,12 @@ extends AbstractMap[K, V] _values(i) = value.asInstanceOf[AnyRef] } } - + /** Adds a new key/value pair to this map and returns the map. */ def +=(key: K, value: V): this.type = { update(key, value); this } def +=(kv: (K, V)): this.type = { update(kv._1, kv._2); this } - + def -=(key: K): this.type = { val i = seekEntry(hashOf(key), key) if (i >= 0) { @@ -284,14 +284,14 @@ extends AbstractMap[K, V] } this } - + def iterator: Iterator[(K, V)] = new Iterator[(K, V)] { private[this] val hz = _hashes private[this] val kz = _keys private[this] val vz = _values - + private[this] var index = 0 - + def hasNext: Boolean = index<hz.length && { var h = hz(index) while (h+h == 0) { @@ -301,7 +301,7 @@ extends AbstractMap[K, V] } true } - + def next: (K, V) = { if (hasNext) { val ans = (kz(index).asInstanceOf[K], vz(index).asInstanceOf[V]) @@ -311,8 +311,8 @@ extends AbstractMap[K, V] else throw new NoSuchElementException("next") } } - - override def foreach[A](f: ((K,V)) => A) { + + override def foreach[U](f: ((K,V)) => U) { var i = 0 var e = _size while (e > 0) { @@ -325,7 +325,7 @@ extends AbstractMap[K, V] else return } } - + override def clone(): AnyRefMap[K, V] = { val hz = java.util.Arrays.copyOf(_hashes, _hashes.length) val kz = java.util.Arrays.copyOf(_keys, _keys.length) @@ -334,7 +334,7 @@ extends AbstractMap[K, V] arm.initializeTo(mask, _size, _vacant, hz, kz, vz) arm } - + private[this] def foreachElement[A,B](elems: Array[AnyRef], f: A => B) { var i,j = 0 while (i < _hashes.length & j < _size) { @@ -346,13 +346,13 @@ extends AbstractMap[K, V] i += 1 } } - + /** Applies a function to all keys of this map. */ def foreachKey[A](f: K => A) { foreachElement[K,A](_keys, f) } /** Applies a function to all values of this map. */ def foreachValue[A](f: V => A) { foreachElement[V,A](_values, f) } - + /** Creates a new `AnyRefMap` with different values. * Unlike `mapValues`, this method generates a new * collection immediately. @@ -374,8 +374,8 @@ extends AbstractMap[K, V] arm.initializeTo(mask, _size, _vacant, hz, kz, vz) arm } - - /** Applies a transformation function to all values stored in this map. + + /** Applies a transformation function to all values stored in this map. * Note: the default, if any, is not transformed. */ def transformValues(f: V => V): this.type = { @@ -398,15 +398,15 @@ object AnyRefMap { private final val MissingBit = 0x80000000 private final val VacantBit = 0x40000000 private final val MissVacant = 0xC0000000 - + private val exceptionDefault = (k: Any) => throw new NoSuchElementException(if (k == null) "(null)" else k.toString) - + implicit def canBuildFrom[K <: AnyRef, V, J <: AnyRef, U]: CanBuildFrom[AnyRefMap[K,V], (J, U), AnyRefMap[J,U]] = new CanBuildFrom[AnyRefMap[K,V], (J, U), AnyRefMap[J,U]] { def apply(from: AnyRefMap[K,V]): AnyRefMapBuilder[J, U] = apply() def apply(): AnyRefMapBuilder[J, U] = new AnyRefMapBuilder[J, U] } - + final class AnyRefMapBuilder[K <: AnyRef, V] extends Builder[(K, V), AnyRefMap[K, V]] { private[collection] var elems: AnyRefMap[K, V] = new AnyRefMap[K, V] def +=(entry: (K, V)): this.type = { @@ -425,14 +425,14 @@ object AnyRefMap { if (arm.size < (sz>>3)) arm.repack() arm } - + /** Creates a new empty `AnyRefMap`. */ def empty[K <: AnyRef, V]: AnyRefMap[K, V] = new AnyRefMap[K, V] - + /** Creates a new empty `AnyRefMap` with the supplied default */ def withDefault[K <: AnyRef, V](default: K => V): AnyRefMap[K, V] = new AnyRefMap[K, V](default) - - /** Creates a new `AnyRefMap` from arrays of keys and values. + + /** Creates a new `AnyRefMap` from arrays of keys and values. * Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`. */ def fromZip[K <: AnyRef, V](keys: Array[K], values: Array[V]): AnyRefMap[K, V] = { @@ -443,8 +443,8 @@ object AnyRefMap { if (arm.size < (sz>>3)) arm.repack() arm } - - /** Creates a new `AnyRefMap` from keys and values. + + /** Creates a new `AnyRefMap` from keys and values. * Equivalent to but more efficient than `AnyRefMap((keys zip values): _*)`. */ def fromZip[K <: AnyRef, V](keys: Iterable[K], values: Iterable[V]): AnyRefMap[K, V] = { diff --git a/src/library/scala/collection/mutable/ArraySeq.scala b/src/library/scala/collection/mutable/ArraySeq.scala index 577a838315..ddb48627af 100644 --- a/src/library/scala/collection/mutable/ArraySeq.scala +++ b/src/library/scala/collection/mutable/ArraySeq.scala @@ -68,7 +68,7 @@ extends AbstractSeq[A] array(idx) = elem.asInstanceOf[AnyRef] } - override def foreach[U](f: A => U) { + override def foreach[U](f: A => U) { var i = 0 while (i < length) { f(array(i).asInstanceOf[A]) diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala index fec2da8839..8ff128c026 100644 --- a/src/library/scala/collection/mutable/ArrayStack.scala +++ b/src/library/scala/collection/mutable/ArrayStack.scala @@ -233,7 +233,7 @@ extends AbstractSeq[T] } } - override def foreach[U](f: T => U) { + override def foreach[U](f: T => U) { var currentIndex = index while (currentIndex > 0) { currentIndex -= 1 diff --git a/src/library/scala/collection/mutable/HashMap.scala b/src/library/scala/collection/mutable/HashMap.scala index 6fca75ffea..eab4202353 100644 --- a/src/library/scala/collection/mutable/HashMap.scala +++ b/src/library/scala/collection/mutable/HashMap.scala @@ -96,16 +96,16 @@ extends AbstractMap[A, B] def iterator = entriesIterator map (e => ((e.key, e.value))) - override def foreach[C](f: ((A, B)) => C): Unit = foreachEntry(e => f((e.key, e.value))) + override def foreach[U](f: ((A, B)) => U): Unit = foreachEntry(e => f((e.key, e.value))) /* Override to avoid tuple allocation in foreach */ override def keySet: scala.collection.Set[A] = new DefaultKeySet { - override def foreach[C](f: A => C) = foreachEntry(e => f(e.key)) + override def foreach[U](f: A => U) = foreachEntry(e => f(e.key)) } /* Override to avoid tuple allocation in foreach */ override def values: scala.collection.Iterable[B] = new DefaultValuesIterable { - override def foreach[C](f: B => C) = foreachEntry(e => f(e.value)) + override def foreach[U](f: B => U) = foreachEntry(e => f(e.value)) } /* Override to avoid tuple allocation */ diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala index 886fee5a59..3a16e4efa5 100644 --- a/src/library/scala/collection/mutable/HashSet.scala +++ b/src/library/scala/collection/mutable/HashSet.scala @@ -70,7 +70,7 @@ extends AbstractSet[A] override def iterator: Iterator[A] = super[FlatHashTable].iterator - override def foreach[U](f: A => U) { + override def foreach[U](f: A => U) { var i = 0 val len = table.length while (i < len) { diff --git a/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala b/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala index 730b22227d..d7eec70b15 100644 --- a/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala +++ b/src/library/scala/collection/mutable/ImmutableSetAdaptor.scala @@ -32,7 +32,7 @@ extends AbstractSet[A] def contains(elem: A): Boolean = set.contains(elem) - override def foreach[U](f: A => U): Unit = set.foreach(f) + override def foreach[U](f: A => U): Unit = set.foreach(f) override def exists(p: A => Boolean): Boolean = set.exists(p) diff --git a/src/library/scala/collection/mutable/LinkedListLike.scala b/src/library/scala/collection/mutable/LinkedListLike.scala index a9d385bc5b..d0748b8a9f 100644 --- a/src/library/scala/collection/mutable/LinkedListLike.scala +++ b/src/library/scala/collection/mutable/LinkedListLike.scala @@ -172,7 +172,7 @@ trait LinkedListLike[A, This <: Seq[A] with LinkedListLike[A, This]] extends Seq } } - override def foreach[B](f: A => B) { + override def foreach[U](f: A => U) { var these = this while (these.nonEmpty) { f(these.elem) diff --git a/src/library/scala/collection/mutable/LongMap.scala b/src/library/scala/collection/mutable/LongMap.scala index c124f35cd7..198e34bd29 100644 --- a/src/library/scala/collection/mutable/LongMap.scala +++ b/src/library/scala/collection/mutable/LongMap.scala @@ -5,20 +5,20 @@ package mutable import generic.CanBuildFrom /** This class implements mutable maps with `Long` keys based on a hash table with open addressing. - * - * Basic map operations on single entries, including `contains` and `get`, + * + * Basic map operations on single entries, including `contains` and `get`, * are typically substantially faster with `LongMap` than [[HashMap]]. Methods * that act on the whole map, including `foreach` and `map` are not in * general expected to be faster than with a generic map, save for those * that take particular advantage of the internal structure of the map: * `foreachKey`, `foreachValue`, `mapValuesNow`, and `transformValues`. - * + * * Maps with open addressing may become less efficient at lookup after * repeated addition/removal of elements. Although `LongMap` makes a * decent attempt to remain efficient regardless, calling `repack` * on a map that will no longer have elements removed but will be * used heavily may save both time and storage space. - * + * * This map is not intended to contain more than 2^29 entries (approximately * 500 million). The maximum capacity is 2^30, but performance will degrade * rapidly as 2^30 is approached. @@ -33,20 +33,20 @@ extends AbstractMap[Long, V] import LongMap._ def this() = this(LongMap.exceptionDefault, 16, true) - + /** Creates a new `LongMap` that returns default values according to a supplied key-value mapping. */ def this(defaultEntry: Long => V) = this(defaultEntry, 16, true) - + /** Creates a new `LongMap` with an initial buffer of specified size. - * + * * A LongMap can typically contain half as many elements as its buffer size * before it requires resizing. */ def this(initialBufferSize: Int) = this(LongMap.exceptionDefault, initialBufferSize, true) - + /** Creates a new `LongMap` with specified default values and initial buffer size. */ def this(defaultEntry: Long => V, initialBufferSize: Int) = this(defaultEntry, initialBufferSize, true) - + private[this] var mask = 0 private[this] var extraKeys: Int = 0 private[this] var zeroValue: AnyRef = null @@ -55,43 +55,43 @@ extends AbstractMap[Long, V] private[this] var _vacant = 0 private[this] var _keys: Array[Long] = null private[this] var _values: Array[AnyRef] = null - + if (initBlank) defaultInitialize(initialBufferSize) - + private[this] def defaultInitialize(n: Int) = { - mask = + mask = if (n<0) 0x7 else (((1 << (32 - java.lang.Integer.numberOfLeadingZeros(n-1))) - 1) & 0x3FFFFFFF) | 0x7 _keys = new Array[Long](mask+1) _values = new Array[AnyRef](mask+1) } - + private[collection] def initializeTo( m: Int, ek: Int, zv: AnyRef, mv: AnyRef, sz: Int, vc: Int, kz: Array[Long], vz: Array[AnyRef] ) { mask = m; extraKeys = ek; zeroValue = zv; minValue = mv; _size = sz; _vacant = vc; _keys = kz; _values = vz } - + override def size: Int = _size + (extraKeys+1)/2 override def empty: LongMap[V] = new LongMap() - - private def imbalanced: Boolean = + + private def imbalanced: Boolean = (_size + _vacant) > 0.5*mask || _vacant > _size - + private def toIndex(k: Long): Int = { // Part of the MurmurHash3 32 bit finalizer val h = ((k ^ (k >>> 32)) & 0xFFFFFFFFL).toInt val x = (h ^ (h >>> 16)) * 0x85EBCA6B (x ^ (x >>> 13)) & mask } - + private def seekEmpty(k: Long): Int = { var e = toIndex(k) var x = 0 while (_keys(e) != 0) { x += 1; e = (e + 2*(x+1)*x - 3) & mask } e } - + private def seekEntry(k: Long): Int = { var e = toIndex(k) var x = 0 @@ -99,7 +99,7 @@ extends AbstractMap[Long, V] while ({ q = _keys(e); if (q==k) return e; q != 0}) { x += 1; e = (e + 2*(x+1)*x - 3) & mask } e | MissingBit } - + private def seekEntryOrOpen(k: Long): Int = { var e = toIndex(k) var x = 0 @@ -116,12 +116,12 @@ extends AbstractMap[Long, V] } o } - + override def contains(key: Long): Boolean = { if (key == -key) (((key>>>63).toInt+1) & extraKeys) != 0 else seekEntry(key) >= 0 } - + override def get(key: Long): Option[V] = { if (key == -key) { if ((((key>>>63).toInt+1) & extraKeys) == 0) None @@ -133,7 +133,7 @@ extends AbstractMap[Long, V] if (i < 0) None else Some(_values(i).asInstanceOf[V]) } } - + override def getOrElse[V1 >: V](key: Long, default: => V1): V1 = { if (key == -key) { if ((((key>>>63).toInt+1) & extraKeys) == 0) default @@ -145,7 +145,7 @@ extends AbstractMap[Long, V] if (i < 0) default else _values(i).asInstanceOf[V1] } } - + override def getOrElseUpdate(key: Long, defaultValue: => V): V = { if (key == -key) { val kbits = (key>>>63).toInt + 1 @@ -185,10 +185,10 @@ extends AbstractMap[Long, V] else _values(i).asInstanceOf[V] } } - + /** Retrieves the value associated with a key, or the default for that type if none exists * (null for AnyRef, 0 for floats and integers). - * + * * Note: this is the fastest way to retrieve a value that may or * may not exist, if the default null/zero is acceptable. For key/value * pairs that do exist, `apply` (i.e. `map(key)`) is equally fast. @@ -204,8 +204,8 @@ extends AbstractMap[Long, V] if (i < 0) null.asInstanceOf[V] else _values(i).asInstanceOf[V] } } - - /** Retrieves the value associated with a key. + + /** Retrieves the value associated with a key. * If the key does not exist in the map, the `defaultEntry` for that key * will be returned instead. */ @@ -220,12 +220,12 @@ extends AbstractMap[Long, V] if (i < 0) defaultEntry(key) else _values(i).asInstanceOf[V] } } - + /** The user-supplied default value for the key. Throws an exception * if no other default behavior was specified. */ override def default(key: Long) = defaultEntry(key) - + private def repack(newMask: Int) { val ok = _keys val ov = _values @@ -244,9 +244,9 @@ extends AbstractMap[Long, V] i += 1 } } - + /** Repacks the contents of this `LongMap` for maximum efficiency of lookup. - * + * * For maps that undergo a complex creation process with both addition and * removal of keys, and then are used heavily with no further removal of * elements, calling `repack` after the end of the creation can result in @@ -259,7 +259,7 @@ extends AbstractMap[Long, V] while (m > 8 && 8*_size < m) m = m >>> 1 repack(m) } - + override def put(key: Long, value: V): Option[V] = { if (key == -key) { if (key == 0) { @@ -294,9 +294,9 @@ extends AbstractMap[Long, V] } } } - + /** Updates the map to include a new key-value pair. - * + * * This is the fastest way to add an entry to a `LongMap`. */ override def update(key: Long, value: V): Unit = { @@ -326,12 +326,12 @@ extends AbstractMap[Long, V] } } } - + /** Adds a new key/value pair to this map and returns the map. */ def +=(key: Long, value: V): this.type = { update(key, value); this } - + def +=(kv: (Long, V)): this.type = { update(kv._1, kv._2); this } - + def -=(key: Long): this.type = { if (key == -key) { if (key == 0L) { @@ -354,22 +354,22 @@ extends AbstractMap[Long, V] } this } - + def iterator: Iterator[(Long, V)] = new Iterator[(Long, V)] { private[this] val kz = _keys private[this] val vz = _values - - private[this] var nextPair: (Long, V) = + + private[this] var nextPair: (Long, V) = if (extraKeys==0) null else if ((extraKeys&1)==1) (0L, zeroValue.asInstanceOf[V]) else (Long.MinValue, minValue.asInstanceOf[V]) - private[this] var anotherPair: (Long, V) = + private[this] var anotherPair: (Long, V) = if (extraKeys==3) (Long.MinValue, minValue.asInstanceOf[V]) else null - + private[this] var index = 0 - + def hasNext: Boolean = nextPair != null || (index < kz.length && { var q = kz(index) while (q == -q) { @@ -392,8 +392,8 @@ extends AbstractMap[Long, V] ans } } - - override def foreach[A](f: ((Long,V)) => A) { + + override def foreach[U](f: ((Long,V)) => U) { if ((extraKeys & 1) == 1) f((0L, zeroValue.asInstanceOf[V])) if ((extraKeys & 2) == 2) f((Long.MinValue, minValue.asInstanceOf[V])) var i,j = 0 @@ -406,7 +406,7 @@ extends AbstractMap[Long, V] i += 1 } } - + override def clone(): LongMap[V] = { val kz = java.util.Arrays.copyOf(_keys, _keys.length) val vz = java.util.Arrays.copyOf(_values, _values.length) @@ -414,7 +414,7 @@ extends AbstractMap[Long, V] lm.initializeTo(mask, extraKeys, zeroValue, minValue, _size, _vacant, kz, vz) lm } - + /** Applies a function to all keys of this map. */ def foreachKey[A](f: Long => A) { if ((extraKeys & 1) == 1) f(0L) @@ -444,7 +444,7 @@ extends AbstractMap[Long, V] i += 1 } } - + /** Creates a new `LongMap` with different values. * Unlike `mapValues`, this method generates a new * collection immediately. @@ -467,8 +467,8 @@ extends AbstractMap[Long, V] lm.initializeTo(mask, extraKeys, zv, mv, _size, _vacant, kz, vz) lm } - - /** Applies a transformation function to all values stored in this map. + + /** Applies a transformation function to all values stored in this map. * Note: the default, if any, is not transformed. */ def transformValues(f: V => V): this.type = { @@ -492,15 +492,15 @@ object LongMap { private final val MissingBit = 0x80000000 private final val VacantBit = 0x40000000 private final val MissVacant = 0xC0000000 - + private val exceptionDefault: Long => Nothing = (k: Long) => throw new NoSuchElementException(k.toString) - - implicit def canBuildFrom[V, U]: CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] = + + implicit def canBuildFrom[V, U]: CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] = new CanBuildFrom[LongMap[V], (Long, U), LongMap[U]] { def apply(from: LongMap[V]): LongMapBuilder[U] = apply() def apply(): LongMapBuilder[U] = new LongMapBuilder[U] } - + final class LongMapBuilder[V] extends Builder[(Long, V), LongMap[V]] { private[collection] var elems: LongMap[V] = new LongMap[V] def +=(entry: (Long, V)): this.type = { @@ -519,14 +519,14 @@ object LongMap { if (lm.size < (sz>>3)) lm.repack() lm } - + /** Creates a new empty `LongMap`. */ def empty[V]: LongMap[V] = new LongMap[V] - + /** Creates a new empty `LongMap` with the supplied default */ def withDefault[V](default: Long => V): LongMap[V] = new LongMap[V](default) - - /** Creates a new `LongMap` from arrays of keys and values. + + /** Creates a new `LongMap` from arrays of keys and values. * Equivalent to but more efficient than `LongMap((keys zip values): _*)`. */ def fromZip[V](keys: Array[Long], values: Array[V]): LongMap[V] = { @@ -537,8 +537,8 @@ object LongMap { if (lm.size < (sz>>3)) lm.repack() lm } - - /** Creates a new `LongMap` from keys and values. + + /** Creates a new `LongMap` from keys and values. * Equivalent to but more efficient than `LongMap((keys zip values): _*)`. */ def fromZip[V](keys: Iterable[Long], values: Iterable[V]): LongMap[V] = { diff --git a/src/library/scala/collection/mutable/SynchronizedSet.scala b/src/library/scala/collection/mutable/SynchronizedSet.scala index 60e2e79d3f..dd842f26ce 100644 --- a/src/library/scala/collection/mutable/SynchronizedSet.scala +++ b/src/library/scala/collection/mutable/SynchronizedSet.scala @@ -78,7 +78,7 @@ trait SynchronizedSet[A] extends Set[A] { super.subsetOf(that) } - override def foreach[U](f: A => U) = synchronized { + override def foreach[U](f: A => U) = synchronized { super.foreach(f) } |