From 4788fee88e2cee8b072193bd11e4fe29c0ec8988 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 16 Jun 2009 15:26:45 +0000 Subject: made Hashable use a Seq instead of List. --- src/library/scala/util/Hashable.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/library/scala/util/Hashable.scala b/src/library/scala/util/Hashable.scala index 88d3b72fbd..348c3c0b96 100644 --- a/src/library/scala/util/Hashable.scala +++ b/src/library/scala/util/Hashable.scala @@ -8,7 +8,7 @@ package scala.util /** A convenience trait for simplifying hashCode creation. - * Mix this into a class and define val hashValues = List(x1, x2, ...) + * Mix this into a class and define val hashValues = Seq(x1, x2, ...) * and your hashCode will be derived from those values. If you define * equals in terms of equalHashValues then your hashCode and equals * methods will never be out of sync. Something like: @@ -23,29 +23,29 @@ package scala.util abstract trait Hashable extends AnyRef { import Hashable._ - protected def hashValues: List[Any] // in an ideal universe this would be more like List[Hashable] + protected def hashValues: Seq[Any] // in an ideal universe this would be more like Seq[Hashable] protected def hashSeed: Int = 0 override def hashCode: Int = (hashValues map calculateHashCode).foldLeft(hashSeed)((x, y) => x * 41 + y) protected def equalHashValues(other: Any) = other match { - case x: Hashable => hashValues == x.hashValues + case x: Hashable => hashValues sameElements x.hashValues case _ => false } } abstract trait StrictHashable extends Hashable { - protected def hashValues: List[Hashable] + protected def hashValues: Seq[Hashable] } object Hashable { - /** This implicit is for StrictHashable's benefit, so your hashValues list + /** This implicit is for StrictHashable's benefit, so your hashValues Seq * can contain both explicitly Hashable classes and value types. */ implicit def anyVal2Hashable(x: AnyVal): Hashable = - new Hashable { protected def hashValues = List(x) } + new Hashable { protected def hashValues = Seq(x) } private def calculateHashCode(x: Any) = x match { case null => 0 -- cgit v1.2.3