mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-26 04:56:06 +00:00
Improve the consistency between code and comments in Kotlin (#1268)
* style(kotlin): Make code and comments consistent. * style(kotlin): convert comment location. * style(c): Add missing comment. * style(kotlin): Remove redundant semicolon, parenthesis and brace * style(kotlin): Put constants inside the function. * style(kotlin): fix unnecessary indentation. * style(swift): Add missing comment. * style(kotlin): Add missing comment. * style(kotlin): Remove redundant comment. * style(kotlin): Add missing comment. * Update linked_list.kt * style(csharp,js,ts): Add missing comment. * style(kotlin): Remove empty lines. * Update list.cs * Update list.js * Update list.ts * roll back to commit 1 * style(cs,js,ts): Add missing comment in docfile. * style(kotlin): Use normal element swapping instead of scope functions.
This commit is contained in:
@@ -68,7 +68,8 @@ class ArrayHashMap {
|
||||
fun valueSet(): MutableList<String> {
|
||||
val valueSet = mutableListOf<String>()
|
||||
for (pair in buckets) {
|
||||
pair?.let { valueSet.add(it._val) }
|
||||
if (pair != null)
|
||||
valueSet.add(pair._val)
|
||||
}
|
||||
return valueSet
|
||||
}
|
||||
@@ -78,7 +79,7 @@ class ArrayHashMap {
|
||||
for (kv in pairSet()) {
|
||||
val key = kv.key
|
||||
val _val = kv._val
|
||||
println("${key} -> ${_val}")
|
||||
println("$key -> $_val")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ fun main() {
|
||||
|
||||
val arr = arrayOf<Any>(12836, "小哈")
|
||||
val hashTup = arr.contentHashCode()
|
||||
println("数组 ${arr.contentToString()} 的哈希值为 ${hashTup}")
|
||||
println("数组 ${arr.contentToString()} 的哈希值为 $hashTup")
|
||||
|
||||
val obj = ListNode(0)
|
||||
val hashObj = obj.hashCode()
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
package chapter_hashing
|
||||
|
||||
/* 链式地址哈希表 */
|
||||
class HashMapChaining() {
|
||||
class HashMapChaining {
|
||||
var size: Int // 键值对数量
|
||||
var capacity: Int // 哈希表容量
|
||||
val loadThres: Double // 触发扩容的负载因子阈值
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
|
||||
package chapter_hashing
|
||||
|
||||
const val MODULUS = 1000000007
|
||||
|
||||
/* 加法哈希 */
|
||||
fun addHash(key: String): Int {
|
||||
var hash = 0L
|
||||
val MODULUS = 1000000007
|
||||
for (c in key.toCharArray()) {
|
||||
hash = (hash + c.code) % MODULUS
|
||||
}
|
||||
@@ -20,6 +19,7 @@ fun addHash(key: String): Int {
|
||||
/* 乘法哈希 */
|
||||
fun mulHash(key: String): Int {
|
||||
var hash = 0L
|
||||
val MODULUS = 1000000007
|
||||
for (c in key.toCharArray()) {
|
||||
hash = (31 * hash + c.code) % MODULUS
|
||||
}
|
||||
@@ -29,6 +29,7 @@ fun mulHash(key: String): Int {
|
||||
/* 异或哈希 */
|
||||
fun xorHash(key: String): Int {
|
||||
var hash = 0
|
||||
val MODULUS = 1000000007
|
||||
for (c in key.toCharArray()) {
|
||||
hash = hash xor c.code
|
||||
}
|
||||
@@ -38,6 +39,7 @@ fun xorHash(key: String): Int {
|
||||
/* 旋转哈希 */
|
||||
fun rotHash(key: String): Int {
|
||||
var hash = 0L
|
||||
val MODULUS = 1000000007
|
||||
for (c in key.toCharArray()) {
|
||||
hash = ((hash shl 4) xor (hash shr 28) xor c.code.toLong()) % MODULUS
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user