summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Prokopec <axel22@gmail.com>2012-06-01 18:08:48 +0200
committerAleksandar Prokopec <axel22@gmail.com>2012-06-01 18:09:14 +0200
commitbb30e08d71c888f923e814e7ccbeb03427fd8808 (patch)
tree76f2675a59b76f5f431a2f3824a979c05bdd740e
parentd38ad5e9877011e635b6c2cb6c4f3fcb31dfb7d2 (diff)
downloadscala-bb30e08d71c888f923e814e7ccbeb03427fd8808.tar.gz
scala-bb30e08d71c888f923e814e7ccbeb03427fd8808.tar.bz2
scala-bb30e08d71c888f923e814e7ccbeb03427fd8808.zip
Remove Equality in favour of Equiv.
Make Equiv serializable.
-rw-r--r--src/library/scala/Equality.scala37
-rw-r--r--src/library/scala/collection/concurrent/TrieMap.scala10
-rw-r--r--src/library/scala/math/Equiv.scala2
-rw-r--r--src/library/scala/math/Hashing.scala6
-rw-r--r--test/files/run/triemap-hash.scala4
5 files changed, 11 insertions, 48 deletions
diff --git a/src/library/scala/Equality.scala b/src/library/scala/Equality.scala
deleted file mode 100644
index 92835fb157..0000000000
--- a/src/library/scala/Equality.scala
+++ /dev/null
@@ -1,37 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-package scala
-
-/** `Equality` is a trait whose instances each represent a strategy for determining
- * equality of instances of a type.
- *
- * `Equality`'s companion object defines a default equality for all
- * objects - it calls their `==` method.
- *
- * @since 2.10
- */
-@annotation.implicitNotFound(msg = "No implicit Equality defined for ${T}.")
-trait Equality[T] extends Serializable {
-
- def areEqual(x: T, y: T): Boolean
-
-}
-
-
-object Equality {
-
- implicit def defaultEquality[T] = new Equality[T] {
- def areEqual(x: T, y: T) = x == y
- }
-
- def apply[T](f: (T, T) => Boolean) = new Equality[T] {
- def areEqual(x: T, y: T) = f(x, y)
- }
-
-}
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala
index b38cb4e376..7c786619fb 100644
--- a/src/library/scala/collection/concurrent/TrieMap.scala
+++ b/src/library/scala/collection/concurrent/TrieMap.scala
@@ -82,7 +82,7 @@ private[collection] final class INode[K, V](bn: MainNode[K, V], g: Gen) extends
}
@inline
- private def equal(k1: K, k2: K, ct: TrieMap[K, V]) = ct.equality.areEqual(k1, k2)
+ private def equal(k1: K, k2: K, ct: TrieMap[K, V]) = ct.equality.equiv(k1, k2)
@inline private def inode(cn: MainNode[K, V]) = {
val nin = new INode[K, V](gen)
@@ -631,7 +631,7 @@ private[concurrent] case class RDCSS_Descriptor[K, V](old: INode[K, V], expected
* @since 2.10
*/
@SerialVersionUID(0L - 6402774413839597105L)
-final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater[TrieMap[K, V], AnyRef], hashf: Hashing[K], ef: Equality[K])
+final class TrieMap[K, V] private (r: AnyRef, rtupd: AtomicReferenceFieldUpdater[TrieMap[K, V], AnyRef], hashf: Hashing[K], ef: Equiv[K])
extends scala.collection.concurrent.Map[K, V]
with scala.collection.mutable.MapLike[K, V, TrieMap[K, V]]
with CustomParallelizable[(K, V), ParTrieMap[K, V]]
@@ -644,14 +644,14 @@ extends scala.collection.concurrent.Map[K, V]
def equality = equalityobj
@volatile var root = r
- def this(hashf: Hashing[K], ef: Equality[K]) = this(
+ def this(hashf: Hashing[K], ef: Equiv[K]) = this(
INode.newRootNode,
AtomicReferenceFieldUpdater.newUpdater(classOf[TrieMap[K, V]], classOf[AnyRef], "root"),
hashf,
ef
)
- def this() = this(Hashing.defaultHashing, Equality.defaultEquality)
+ def this() = this(Hashing.default, Equiv.universal)
/* internal methods */
@@ -673,7 +673,7 @@ extends scala.collection.concurrent.Map[K, V]
rootupdater = AtomicReferenceFieldUpdater.newUpdater(classOf[TrieMap[K, V]], classOf[AnyRef], "root")
hashingobj = in.readObject().asInstanceOf[Hashing[K]]
- equalityobj = in.readObject().asInstanceOf[Equality[K]]
+ equalityobj = in.readObject().asInstanceOf[Equiv[K]]
var obj: AnyRef = null
do {
diff --git a/src/library/scala/math/Equiv.scala b/src/library/scala/math/Equiv.scala
index bd8414a18d..a8ba0aa40c 100644
--- a/src/library/scala/math/Equiv.scala
+++ b/src/library/scala/math/Equiv.scala
@@ -29,7 +29,7 @@ import java.util.Comparator
* @since 2.7
*/
-trait Equiv[T] extends Any {
+trait Equiv[T] extends Any with Serializable {
/** Returns `true` iff `x` is equivalent to `y`.
*/
def equiv(x: T, y: T): Boolean
diff --git a/src/library/scala/math/Hashing.scala b/src/library/scala/math/Hashing.scala
index 6902b3ab06..0d0fecf442 100644
--- a/src/library/scala/math/Hashing.scala
+++ b/src/library/scala/math/Hashing.scala
@@ -14,7 +14,7 @@ package scala.math
* `Hashing`'s companion object defines a default hashing strategy for all
* objects - it calls their `##` method.
*
- * Note: when using a custom `Hashing`, make sure to use it with the `Equality`
+ * Note: when using a custom `Hashing`, make sure to use it with the `Equiv`
* such that if any two objects are equal, then their hash codes must be equal.
*
* @since 2.10
@@ -29,11 +29,11 @@ trait Hashing[T] extends Serializable {
object Hashing {
- implicit def defaultHashing[T] = new Hashing[T] {
+ implicit def default[T] = new Hashing[T] {
def hashCode(x: T) = x.##
}
- def apply[T](f: T => Int) = new Hashing[T] {
+ def fromFunction[T](f: T => Int) = new Hashing[T] {
def hashCode(x: T) = f(x)
}
diff --git a/test/files/run/triemap-hash.scala b/test/files/run/triemap-hash.scala
index 23cdd26bed..8f2347a96f 100644
--- a/test/files/run/triemap-hash.scala
+++ b/test/files/run/triemap-hash.scala
@@ -15,7 +15,7 @@ object Test {
def hashing() {
import collection._
- val tm = new concurrent.TrieMap[String, String](Hashing(x => x.length + x(0).toInt), Equality.defaultEquality)
+ val tm = new concurrent.TrieMap[String, String](Hashing.fromFunction(x => x.length + x(0).toInt), Equiv.universal)
tm.put("a", "b")
tm.put("c", "d")
@@ -29,7 +29,7 @@ object Test {
def equality() {
import collection._
- val tm = new concurrent.TrieMap[String, String](Hashing(x => x(0).toInt), Equality(_(0) == _(0)))
+ val tm = new concurrent.TrieMap[String, String](Hashing.fromFunction(x => x(0).toInt), Equiv.fromFunction(_(0) == _(0)))
tm.put("a", "b")
tm.put("a1", "d")
tm.put("b", "c")