summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/WrappedArray.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/scala/collection/mutable/WrappedArray.scala')
-rw-r--r--src/library/scala/collection/mutable/WrappedArray.scala63
1 files changed, 58 insertions, 5 deletions
diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala
index 8740bda835..0b5ebe7e9a 100644
--- a/src/library/scala/collection/mutable/WrappedArray.scala
+++ b/src/library/scala/collection/mutable/WrappedArray.scala
@@ -13,9 +13,12 @@ package collection
package mutable
import scala.reflect.ClassTag
-import scala.runtime.ScalaRunTime._
+import scala.runtime.BoxedUnit
import scala.collection.generic._
import scala.collection.parallel.mutable.ParArray
+import scala.util.hashing.MurmurHash3
+
+import java.util.Arrays
/**
* A class representing `Array[T]`.
@@ -46,7 +49,7 @@ extends AbstractSeq[T]
def elemTag: ClassTag[T]
@deprecated("use elemTag instead", "2.10.0")
- def elemManifest: ClassManifest[T] = ClassManifest.fromClass[T](arrayElementClass(elemTag).asInstanceOf[Class[T]])
+ def elemManifest: ClassManifest[T] = ClassManifest.fromClass[T](elemTag.runtimeClass.asInstanceOf[Class[T]])
/** The length of the array */
def length: Int
@@ -63,10 +66,10 @@ extends AbstractSeq[T]
override def par = ParArray.handoff(array)
private def elementClass: Class[_] =
- arrayElementClass(array.getClass)
+ array.getClass.getComponentType
override def toArray[U >: T : ClassTag]: Array[U] = {
- val thatElementClass = arrayElementClass(implicitly[ClassTag[U]])
+ val thatElementClass = implicitly[ClassTag[U]].runtimeClass
if (elementClass eq thatElementClass)
array.asInstanceOf[Array[U]]
else
@@ -122,10 +125,15 @@ object WrappedArray {
def newBuilder[A]: Builder[A, IndexedSeq[A]] = new ArrayBuffer
final class ofRef[T <: AnyRef](val array: Array[T]) extends WrappedArray[T] with Serializable {
- lazy val elemTag = ClassTag[T](arrayElementClass(array.getClass))
+ lazy val elemTag = ClassTag[T](array.getClass.getComponentType)
def length: Int = array.length
def apply(index: Int): T = array(index).asInstanceOf[T]
def update(index: Int, elem: T) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofRef[_] => Arrays.equals(array.asInstanceOf[Array[AnyRef]], that.array.asInstanceOf[Array[AnyRef]])
+ case _ => super.equals(that)
+ }
}
final class ofByte(val array: Array[Byte]) extends WrappedArray[Byte] with Serializable {
@@ -133,6 +141,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Byte = array(index)
def update(index: Int, elem: Byte) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedBytesHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofByte => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofShort(val array: Array[Short]) extends WrappedArray[Short] with Serializable {
@@ -140,6 +153,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Short = array(index)
def update(index: Int, elem: Short) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofShort => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofChar(val array: Array[Char]) extends WrappedArray[Char] with Serializable {
@@ -147,6 +165,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Char = array(index)
def update(index: Int, elem: Char) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofChar => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofInt(val array: Array[Int]) extends WrappedArray[Int] with Serializable {
@@ -154,6 +177,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Int = array(index)
def update(index: Int, elem: Int) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofInt => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofLong(val array: Array[Long]) extends WrappedArray[Long] with Serializable {
@@ -161,6 +189,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Long = array(index)
def update(index: Int, elem: Long) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofLong => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofFloat(val array: Array[Float]) extends WrappedArray[Float] with Serializable {
@@ -168,6 +201,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Float = array(index)
def update(index: Int, elem: Float) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofFloat => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofDouble(val array: Array[Double]) extends WrappedArray[Double] with Serializable {
@@ -175,6 +213,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Double = array(index)
def update(index: Int, elem: Double) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofDouble => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofBoolean(val array: Array[Boolean]) extends WrappedArray[Boolean] with Serializable {
@@ -182,6 +225,11 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Boolean = array(index)
def update(index: Int, elem: Boolean) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofBoolean => Arrays.equals(array, that.array)
+ case _ => super.equals(that)
+ }
}
final class ofUnit(val array: Array[Unit]) extends WrappedArray[Unit] with Serializable {
@@ -189,5 +237,10 @@ object WrappedArray {
def length: Int = array.length
def apply(index: Int): Unit = array(index)
def update(index: Int, elem: Unit) { array(index) = elem }
+ override def hashCode = MurmurHash3.wrappedArrayHash(array)
+ override def equals(that: Any) = that match {
+ case that: ofUnit => array.length == that.array.length
+ case _ => super.equals(that)
+ }
}
}