mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-23 17:54:27 +08:00
build
This commit is contained in:
@ -594,6 +594,18 @@ index = hash(key) % capacity
|
||||
}
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="simple_hash.rb"
|
||||
[class]{}-[func]{add_hash}
|
||||
|
||||
[class]{}-[func]{mul_hash}
|
||||
|
||||
[class]{}-[func]{xor_hash}
|
||||
|
||||
[class]{}-[func]{rot_hash}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="simple_hash.zig"
|
||||
@ -911,6 +923,34 @@ $$
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="built_in_hash.kt"
|
||||
val num = 3
|
||||
val hashNum = num.hashCode()
|
||||
// 整数 3 的哈希值为 3
|
||||
|
||||
val bol = true
|
||||
val hashBol = bol.hashCode()
|
||||
// 布尔量 true 的哈希值为 1231
|
||||
|
||||
val dec = 3.14159
|
||||
val hashDec = dec.hashCode()
|
||||
// 小数 3.14159 的哈希值为 -1340954729
|
||||
|
||||
val str = "Hello 算法"
|
||||
val hashStr = str.hashCode()
|
||||
// 字符串“Hello 算法”的哈希值为 -727081396
|
||||
|
||||
val arr = arrayOf<Any>(12836, "小哈")
|
||||
val hashTup = arr.hashCode()
|
||||
// 数组 [12836, 小哈] 的哈希值为 189568618
|
||||
|
||||
val obj = ListNode(0)
|
||||
val hashObj = obj.hashCode()
|
||||
// 节点对象 utils.ListNode@1d81eb93 的哈希值为 495053715
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="built_in_hash.rb"
|
||||
|
||||
```
|
||||
|
||||
|
@ -1426,6 +1426,12 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="hash_map_chaining.rb"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="hash_map_chaining.zig"
|
||||
@ -3072,6 +3078,12 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="hash_map_open_addressing.rb"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="hash_map_open_addressing.zig"
|
||||
|
@ -280,6 +280,29 @@ comments: true
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="hash_map.kt"
|
||||
/* 初始化哈希表 */
|
||||
val map = HashMap<Int,String>()
|
||||
|
||||
/* 添加操作 */
|
||||
// 在哈希表中添加键值对 (key, value)
|
||||
map[12836] = "小哈"
|
||||
map[15937] = "小啰"
|
||||
map[16750] = "小算"
|
||||
map[13276] = "小法"
|
||||
map[10583] = "小鸭"
|
||||
|
||||
/* 查询操作 */
|
||||
// 向哈希表中输入键 key ,得到值 value
|
||||
val name = map[15937]
|
||||
|
||||
/* 删除操作 */
|
||||
// 在哈希表中删除键值对 (key, value)
|
||||
map.remove(10583)
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="hash_map.rb"
|
||||
|
||||
```
|
||||
|
||||
@ -482,6 +505,24 @@ comments: true
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title="hash_map.kt"
|
||||
/* 遍历哈希表 */
|
||||
// 遍历键值对 key->value
|
||||
for ((key, value) in map) {
|
||||
println("$key -> $value")
|
||||
}
|
||||
// 单独遍历键 key
|
||||
for (key in map.keys) {
|
||||
println(key)
|
||||
}
|
||||
// 单独遍历值 value
|
||||
for (_val in map.values) {
|
||||
println(_val)
|
||||
}
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="hash_map.rb"
|
||||
|
||||
```
|
||||
|
||||
@ -1697,6 +1738,14 @@ index = hash(key) % capacity
|
||||
}
|
||||
```
|
||||
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="array_hash_map.rb"
|
||||
[class]{Pair}-[func]{}
|
||||
|
||||
[class]{ArrayHashMap}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="array_hash_map.zig"
|
||||
|
Reference in New Issue
Block a user