changed actor message type from AnyRef to Any
This commit is contained in:
parent
b01df1e11b
commit
708a9e39fa
6 changed files with 77 additions and 42 deletions
|
|
@ -27,19 +27,28 @@ import java.lang.{Float => JFloat, Double => JDouble}
|
|||
object HashCode {
|
||||
val SEED = 23
|
||||
|
||||
def hash(seed: Int, any: Any): Int = any match {
|
||||
case value: Boolean => hash(seed, value)
|
||||
case value: Char => hash(seed, value)
|
||||
case value: Short => hash(seed, value)
|
||||
case value: Int => hash(seed, value)
|
||||
case value: Long => hash(seed, value)
|
||||
case value: Float => hash(seed, value)
|
||||
case value: Double => hash(seed, value)
|
||||
case value: Byte => hash(seed, value)
|
||||
case value: AnyRef =>
|
||||
var result = seed
|
||||
if (value == null) result = hash(result, 0)
|
||||
else if (!isArray(value)) result = hash(result, value.hashCode())
|
||||
else for (id <- 0 until JArray.getLength(value)) result = hash(result, JArray.get(value, id)) // is an array
|
||||
result
|
||||
}
|
||||
def hash(seed: Int, value: Boolean): Int = firstTerm(seed) + (if (value) 1 else 0)
|
||||
def hash(seed: Int, value: Char): Int = firstTerm(seed) + value.asInstanceOf[Int]
|
||||
def hash(seed: Int, value: Int): Int = firstTerm(seed) + value
|
||||
def hash(seed: Int, value: Long): Int = firstTerm(seed) + (value ^ (value >>> 32) ).asInstanceOf[Int]
|
||||
def hash(seed: Int, value: Float): Int = hash(seed, JFloat.floatToIntBits(value))
|
||||
def hash(seed: Int, value: Double): Int = hash(seed, JDouble.doubleToLongBits(value))
|
||||
def hash(seed: Int, anyRef: AnyRef): Int = {
|
||||
var result = seed
|
||||
if (anyRef == null) result = hash(result, 0)
|
||||
else if (!isArray(anyRef)) result = hash(result, anyRef.hashCode())
|
||||
else for (id <- 0 until JArray.getLength(anyRef)) result = hash(result, JArray.get(anyRef, id)) // is an array
|
||||
result
|
||||
}
|
||||
|
||||
private def firstTerm(seed: Int): Int = PRIME * seed
|
||||
private def isArray(anyRef: AnyRef): Boolean = anyRef.getClass.isArray
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue