Skip to content
Permalink
Browse files

Remove Equality in favour of Equiv.

Make Equiv serializable.
  • Loading branch information
axel22 committed Jun 1, 2012
1 parent d38ad5e commit bb30e08d71c888f923e814e7ccbeb03427fd8808

This file was deleted.

@@ -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 {
@@ -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
@@ -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)
}

@@ -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")

0 comments on commit bb30e08

Please sign in to comment.
You can’t perform that action at this time.