2024-04-06 02:30:11 +08:00
|
|
|
/**
|
|
|
|
* File: built_in_hash.kt
|
|
|
|
* Created Time: 2024-01-25
|
|
|
|
* Author: curtishd (1023632660@qq.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
package chapter_hashing
|
|
|
|
|
|
|
|
import utils.ListNode
|
|
|
|
|
|
|
|
/* Driver Code */
|
|
|
|
fun main() {
|
|
|
|
val num = 3
|
2024-04-11 20:18:19 +08:00
|
|
|
val hashNum = num.hashCode()
|
2024-04-06 02:30:11 +08:00
|
|
|
println("整數 $num 的雜湊值為 $hashNum")
|
|
|
|
|
|
|
|
val bol = true
|
2024-04-11 20:18:19 +08:00
|
|
|
val hashBol = bol.hashCode()
|
2024-04-06 02:30:11 +08:00
|
|
|
println("布林量 $bol 的雜湊值為 $hashBol")
|
|
|
|
|
|
|
|
val dec = 3.14159
|
2024-04-11 20:18:19 +08:00
|
|
|
val hashDec = dec.hashCode()
|
2024-04-06 02:30:11 +08:00
|
|
|
println("小數 $dec 的雜湊值為 $hashDec")
|
|
|
|
|
|
|
|
val str = "Hello 演算法"
|
|
|
|
val hashStr = str.hashCode()
|
|
|
|
println("字串 $str 的雜湊值為 $hashStr")
|
|
|
|
|
|
|
|
val arr = arrayOf<Any>(12836, "小哈")
|
|
|
|
val hashTup = arr.contentHashCode()
|
2024-04-14 20:46:20 +08:00
|
|
|
println("陣列 ${arr.contentToString()} 的雜湊值為 $hashTup")
|
2024-04-06 02:30:11 +08:00
|
|
|
|
|
|
|
val obj = ListNode(0)
|
|
|
|
val hashObj = obj.hashCode()
|
|
|
|
println("節點物件 $obj 的雜湊值為 $hashObj")
|
|
|
|
}
|