diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-01 21:06:36 +0200 |
---|---|---|
committer | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-01 21:06:36 +0200 |
commit | ddaf6c5235acbf808ffd5ded710f513f4df3882e (patch) | |
tree | 426d70ff22f0926e072740bb58154afa6f0e333a /src/library | |
parent | bb30e08d71c888f923e814e7ccbeb03427fd8808 (diff) | |
download | scala-ddaf6c5235acbf808ffd5ded710f513f4df3882e.tar.gz scala-ddaf6c5235acbf808ffd5ded710f513f4df3882e.tar.bz2 scala-ddaf6c5235acbf808ffd5ded710f513f4df3882e.zip |
Fix `Hashing`.
Move `Hashing` to `scala.util.hashing`.
Adde `Hashing.Default` to `Hashing` companion object.
Change `TrieMap` to autoswitch from `Hashing.Default` to `TrieMap.MangledHashing`.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/concurrent/TrieMap.scala | 22 | ||||
-rw-r--r-- | src/library/scala/util/MurmurHash3.scala | 8 | ||||
-rw-r--r-- | src/library/scala/util/hashing/Hashing.scala (renamed from src/library/scala/math/Hashing.scala) | 6 |
3 files changed, 24 insertions, 12 deletions
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala index 7c786619fb..f944d20bdb 100644 --- a/src/library/scala/collection/concurrent/TrieMap.scala +++ b/src/library/scala/collection/concurrent/TrieMap.scala @@ -14,7 +14,7 @@ package concurrent import java.util.concurrent.atomic._ import collection.immutable.{ ListMap => ImmutableListMap } import collection.parallel.mutable.ParTrieMap -import math.Hashing +import util.hashing.Hashing import generic._ import annotation.tailrec import annotation.switch @@ -637,7 +637,7 @@ extends scala.collection.concurrent.Map[K, V] with CustomParallelizable[(K, V), ParTrieMap[K, V]] with Serializable { - private var hashingobj = hashf + private var hashingobj = if (hashf.isInstanceOf[Hashing.Default[_]]) new TrieMap.MangledHashing[K] else hashf private var equalityobj = ef private var rootupdater = rtupd def hashing = hashingobj @@ -824,14 +824,8 @@ extends scala.collection.concurrent.Map[K, V] if (!RDCSS_ROOT(r, r.gcasRead(this), INode.newRootNode[K, V])) clear() } - @inline private def mangle(hc: Int): Int = { - var hcode = hc * 0x9e3775cd - hcode = java.lang.Integer.reverseBytes(hcode) - hcode * 0x9e3775cd - } - @inline - def computeHash(k: K) = mangle(hashingobj.hashCode(k)) + def computeHash(k: K) = hashingobj.hashCode(k) final def lookup(k: K): V = { val hc = computeHash(k) @@ -919,7 +913,15 @@ object TrieMap extends MutableMapFactory[TrieMap] { implicit def canBuildFrom[K, V]: CanBuildFrom[Coll, (K, V), TrieMap[K, V]] = new MapCanBuildFrom[K, V] def empty[K, V]: TrieMap[K, V] = new TrieMap[K, V] - + + class MangledHashing[K] extends Hashing[K] { + def hashCode(k: K) = { + var hcode = k.## * 0x9e3775cd + hcode = java.lang.Integer.reverseBytes(hcode) + hcode * 0x9e3775cd + } + } + } diff --git a/src/library/scala/util/MurmurHash3.scala b/src/library/scala/util/MurmurHash3.scala index fbb67116dd..9a7f64b4ee 100644 --- a/src/library/scala/util/MurmurHash3.scala +++ b/src/library/scala/util/MurmurHash3.scala @@ -1,3 +1,11 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + package scala.util import java.lang.Integer.{ rotateLeft => rotl } diff --git a/src/library/scala/math/Hashing.scala b/src/library/scala/util/hashing/Hashing.scala index 0d0fecf442..f27a825125 100644 --- a/src/library/scala/math/Hashing.scala +++ b/src/library/scala/util/hashing/Hashing.scala @@ -6,7 +6,7 @@ ** |/ ** \* */ -package scala.math +package scala.util.hashing /** `Hashing` is a trait whose instances each represent a strategy for hashing * instances of a type. @@ -29,10 +29,12 @@ trait Hashing[T] extends Serializable { object Hashing { - implicit def default[T] = new Hashing[T] { + final class Default[T] extends Hashing[T] { def hashCode(x: T) = x.## } + implicit def default[T] = new Default[T] + def fromFunction[T](f: T => Int) = new Hashing[T] { def hashCode(x: T) = f(x) } |