scoop:scoop.core:0.1.0
src/types.scoop
Selected production source · src/types.scoop
1
/**2
* The operator protocol for same-domain value equality. Implementations used with Hash must assign3
* equal values equal hashes.4
*/5
public interface Equals<T> {6
/**7
* Returns whether this value and the operand are equal under the implementing type's contract.8
*/9
public operator fun equals(other: T): Boolean10
}12
/**13
* Provides a human-readable textual representation without prescribing a serialization format.14
*/15
public interface ToString {16
/**17
* Returns the value's textual representation.18
*/19
public fun toString(): String20
}22
/**23
* Provides a Long hash consistent with the type's value equality; it is not a cryptographic24
* digest.25
*/26
public interface Hash {27
/**28
* Returns the value's hash. Equal values must produce equal hashes.29
*/30
public fun hash(): Long31
}33
/**34
* A transparent alias for [Int8] with the same representation and operations.35
*/36
public typealias Byte = Int837
/**38
* A transparent alias for [Int16] with the same representation and operations.39
*/40
public typealias Short = Int1641
/**42
* A transparent alias for [Int] with the same representation and operations.43
*/44
public typealias Int32 = Int45
/**46
* A transparent alias for [Long] with the same representation and operations.47
*/48
public typealias Int64 = Long49
/**50
* A transparent alias for [UInt8] with the same representation and operations.51
*/52
public typealias UByte = UInt853
/**54
* A transparent alias for [UInt16] with the same representation and operations.55
*/56
public typealias UShort = UInt1657
/**58
* A transparent alias for [UInt] with the same representation and operations.59
*/60
public typealias UInt32 = UInt61
/**62
* A transparent alias for [ULong] with the same representation and operations.63
*/64
public typealias UInt64 = ULong66
/**67
* The two logical values true and false, with Boolean negation and scalar codec support.68
*/69
@Intrinsic("core_boolean")70
public struct Boolean : Not<Boolean>, Equals<Boolean>, ToString, Hash {71
/**72
* Compares the two logical values.73
*/74
public override operator fun equals(other: Boolean): Boolean =75
if (this) { other } else { !other }78
/**79
* Returns false for true and true for false.80
*/81
@Intrinsic("boolean_not")82
public override operator fun not(): Boolean84
/**85
* Returns `true` or `false`.86
*/87
public override fun toString(): String = if (this) { "true" } else { "false" }89
/**90
* Returns a hash consistent with Boolean equality.91
*/92
public override fun hash(): Long = if (this) { 1L } else { 0L }94
/**95
* Inspection and serialization operations for this value type.96
*/97
public companion object : ValueEncoder<Boolean>, ValueDecoder<Boolean>, ValueInspector<Boolean> {98
/**99
* Exposes the value as a typed scalar observation.100
*/101
public override fun inspect(value: Boolean): ValueView =102
ValueObservation(typeInfo<Boolean>().type, None, { ValueShape.Scalar(ScalarValue.Boolean(value)) })104
/**105
* Writes the scalar value through the corresponding single-value encoding operation.106
*/107
public override fun encode(value: Boolean, encoder: Encoder): Unit =108
encoder.singleValue().writeBoolean(value)110
/**111
* Reads the scalar through the corresponding decoding operation.112
*/113
public override fun decode(decoder: Decoder): Boolean =114
decoder.singleValue().readBoolean()115
}116
}118
// Preserve the existing word hash using fixed-width wrapping arithmetic.119
@NoGC120
internal fun coreLongHash(input: Long): Long = coreULongHash(input.toULong())122
@NoGC123
internal fun coreULongHash(input: ULong): Long {124
var value = input125
value = value.xor(value.shr(30L)) * 0xbf58476d1ce4e5b9uL126
value = value.xor(value.shr(27L)) * 0x94d049bb133111ebuL127
return value.xor(value.shr(31L)).toLong()128
}