@@ -4,45 +4,24 @@ package core
4
4
import Types ._
5
5
import scala .util .hashing .{ MurmurHash3 => hashing }
6
6
7
- object Hashable {
7
+ abstract class Hashing {
8
+ import Hashing ._
8
9
9
- /** A hash value indicating that the underlying type is not
10
- * cached in uniques.
11
- */
12
- final val NotCached = 0
13
-
14
- /** An alternative value returned from `hash` if the
15
- * computed hashCode would be `NotCached`.
16
- */
17
- private [core] final val NotCachedAlt = Int .MinValue
18
-
19
- /** A value that indicates that the hash code is unknown
20
- */
21
- private [core] final val HashUnknown = 1234
22
-
23
- /** An alternative value if computeHash would otherwise yield HashUnknown
24
- */
25
- private [core] final val HashUnknownAlt = 4321
26
- }
27
-
28
- trait Hashable {
29
- import Hashable ._
30
-
31
- protected def hashSeed : Int = getClass.hashCode
32
-
33
- protected final def finishHash (hashCode : Int , arity : Int ): Int =
10
+ final def finishHash (hashCode : Int , arity : Int ): Int =
34
11
avoidSpecialHashes(hashing.finalizeHash(hashCode, arity))
35
12
36
- final def identityHash = avoidSpecialHashes(System .identityHashCode(this ))
13
+ protected def typeHash (tp : Type ) = tp.hash
14
+
15
+ final def identityHash (tp : Type ) = avoidSpecialHashes(System .identityHashCode(tp))
37
16
38
17
protected def finishHash (seed : Int , arity : Int , tp : Type ): Int = {
39
- val elemHash = tp.hash
18
+ val elemHash = typeHash(tp)
40
19
if (elemHash == NotCached ) return NotCached
41
20
finishHash(hashing.mix(seed, elemHash), arity + 1 )
42
21
}
43
22
44
23
protected def finishHash (seed : Int , arity : Int , tp1 : Type , tp2 : Type ): Int = {
45
- val elemHash = tp1.hash
24
+ val elemHash = typeHash( tp1)
46
25
if (elemHash == NotCached ) return NotCached
47
26
finishHash(hashing.mix(seed, elemHash), arity + 1 , tp2)
48
27
}
@@ -52,7 +31,7 @@ trait Hashable {
52
31
var xs = tps
53
32
var len = arity
54
33
while (xs.nonEmpty) {
55
- val elemHash = xs.head.hash
34
+ val elemHash = typeHash( xs.head)
56
35
if (elemHash == NotCached ) return NotCached
57
36
h = hashing.mix(h, elemHash)
58
37
xs = xs.tail
@@ -62,37 +41,36 @@ trait Hashable {
62
41
}
63
42
64
43
protected def finishHash (seed : Int , arity : Int , tp : Type , tps : List [Type ]): Int = {
65
- val elemHash = tp.hash
44
+ val elemHash = typeHash(tp)
66
45
if (elemHash == NotCached ) return NotCached
67
46
finishHash(hashing.mix(seed, elemHash), arity + 1 , tps)
68
47
}
69
48
70
- protected final def doHash (x : Any ): Int =
71
- finishHash(hashing.mix(hashSeed , x.hashCode), 1 )
49
+ final def doHash (clazz : Class [_], x : Any ): Int =
50
+ finishHash(hashing.mix(clazz.hashCode , x.hashCode), 1 )
72
51
73
- protected final def doHash (tp : Type ): Int =
74
- finishHash(hashSeed , 0 , tp)
52
+ final def doHash (clazz : Class [_], tp : Type ): Int =
53
+ finishHash(clazz.hashCode , 0 , tp)
75
54
76
- protected final def doHash (x1 : Any , tp2 : Type ): Int =
77
- finishHash(hashing.mix(hashSeed , x1.hashCode), 1 , tp2)
55
+ final def doHash (clazz : Class [_], x1 : Any , tp2 : Type ): Int =
56
+ finishHash(hashing.mix(clazz.hashCode , x1.hashCode), 1 , tp2)
78
57
79
- protected final def doHash (tp1 : Type , tp2 : Type ): Int =
80
- finishHash(hashSeed , 0 , tp1, tp2)
58
+ final def doHash (clazz : Class [_], tp1 : Type , tp2 : Type ): Int =
59
+ finishHash(clazz.hashCode , 0 , tp1, tp2)
81
60
82
- protected final def doHash (x1 : Any , tp2 : Type , tp3 : Type ): Int =
83
- finishHash(hashing.mix(hashSeed , x1.hashCode), 1 , tp2, tp3)
61
+ final def doHash (clazz : Class [_], x1 : Any , tp2 : Type , tp3 : Type ): Int =
62
+ finishHash(hashing.mix(clazz.hashCode , x1.hashCode), 1 , tp2, tp3)
84
63
85
- protected final def doHash (tp1 : Type , tps2 : List [Type ]): Int =
86
- finishHash(hashSeed , 0 , tp1, tps2)
64
+ final def doHash (clazz : Class [_], tp1 : Type , tps2 : List [Type ]): Int =
65
+ finishHash(clazz.hashCode , 0 , tp1, tps2)
87
66
88
- protected final def doHash (x1 : Any , tp2 : Type , tps3 : List [Type ]): Int =
89
- finishHash(hashing.mix(hashSeed , x1.hashCode), 1 , tp2, tps3)
67
+ final def doHash (clazz : Class [_], x1 : Any , tp2 : Type , tps3 : List [Type ]): Int =
68
+ finishHash(hashing.mix(clazz.hashCode , x1.hashCode), 1 , tp2, tps3)
90
69
70
+ final def doHash (clazz : Class [_], x1 : Int , x2 : Int ): Int =
71
+ finishHash(hashing.mix(hashing.mix(clazz.hashCode, x1), x2), 1 )
91
72
92
- protected final def doHash (x1 : Int , x2 : Int ): Int =
93
- finishHash(hashing.mix(hashing.mix(hashSeed, x1), x2), 1 )
94
-
95
- protected final def addDelta (elemHash : Int , delta : Int ) =
73
+ final def addDelta (elemHash : Int , delta : Int ) =
96
74
if (elemHash == NotCached ) NotCached
97
75
else avoidSpecialHashes(elemHash + delta)
98
76
@@ -101,3 +79,25 @@ trait Hashable {
101
79
else if (h == HashUnknown ) HashUnknownAlt
102
80
else h
103
81
}
82
+
83
+ object Hashing extends Hashing {
84
+
85
+ /** A hash value indicating that the underlying type is not
86
+ * cached in uniques.
87
+ */
88
+ final val NotCached = 0
89
+
90
+ /** An alternative value returned from `hash` if the
91
+ * computed hashCode would be `NotCached`.
92
+ */
93
+ private [core] final val NotCachedAlt = Int .MinValue
94
+
95
+ /** A value that indicates that the hash code is unknown
96
+ */
97
+ private [core] final val HashUnknown = 1234
98
+
99
+ /** An alternative value if computeHash would otherwise yield HashUnknown
100
+ */
101
+ private [core] final val HashUnknownAlt = 4321
102
+ }
103
+
0 commit comments