mirror of
https://github.com/irmen/prog8.git
synced 2024-08-20 05:29:02 +00:00
hash
This commit is contained in:
parent
b44e76db57
commit
58e5d5c071
@ -18,6 +18,7 @@ import prog8.compiler.target.c64.Petscii
|
||||
import prog8.functions.BuiltinFunctions
|
||||
import prog8.functions.NotConstArgumentException
|
||||
import prog8.functions.builtinFunctionReturnType
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
@ -316,7 +317,7 @@ class NumericLiteralValue(val type: DataType, // only numerical types allowed
|
||||
|
||||
override fun inferType(program: Program) = type
|
||||
|
||||
override fun hashCode(): Int = type.hashCode() * 31 xor number.hashCode()
|
||||
override fun hashCode(): Int = Objects.hash(type, number)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if(other==null || other !is NumericLiteralValue)
|
||||
@ -457,11 +458,7 @@ class ReferenceLiteralValue(val type: DataType, // only reference types allo
|
||||
|
||||
override fun inferType(program: Program) = type
|
||||
|
||||
override fun hashCode(): Int {
|
||||
val sh = str?.hashCode() ?: 0x00014567
|
||||
val ah = array?.hashCode() ?: 0x11119876
|
||||
return sh * 31 xor ah xor type.hashCode()
|
||||
}
|
||||
override fun hashCode(): Int = Objects.hash(str, array, type)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if(other==null || other !is ReferenceLiteralValue)
|
||||
|
@ -83,13 +83,7 @@ class HeapValues {
|
||||
return type==other.type && str==other.str && Arrays.equals(array, other.array) && Arrays.equals(doubleArray, other.doubleArray)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = type.hashCode()
|
||||
result = 31 * result + (str?.hashCode() ?: 0)
|
||||
result = 31 * result + (array?.let { Arrays.hashCode(it) } ?: 0)
|
||||
result = 31 * result + (doubleArray?.let { Arrays.hashCode(it) } ?: 0)
|
||||
return result
|
||||
}
|
||||
override fun hashCode(): Int = Objects.hash(str, array, doubleArray)
|
||||
|
||||
val arraysize: Int = array?.size ?: doubleArray?.size ?: 0
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import prog8.ast.expressions.NumericLiteralValue
|
||||
import prog8.ast.expressions.ReferenceLiteralValue
|
||||
import prog8.compiler.HeapValues
|
||||
import prog8.compiler.target.c64.Petscii
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.pow
|
||||
|
||||
@ -154,12 +155,7 @@ open class RuntimeValue(val type: DataType, num: Number?=null, val str: String?=
|
||||
}
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
val bh = byteval?.hashCode() ?: 0x10001234
|
||||
val wh = wordval?.hashCode() ?: 0x01002345
|
||||
val fh = floatval?.hashCode() ?: 0x00103456
|
||||
return bh xor wh xor fh xor heapId.hashCode() xor type.hashCode()
|
||||
}
|
||||
override fun hashCode(): Int = Objects.hash(byteval, wordval, floatval, type)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if(other==null || other !is RuntimeValue)
|
||||
|
Loading…
Reference in New Issue
Block a user