mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-14 18:31:08 +08:00
feat: Add Ruby code - chapter "Hashing" (#1276)
* feat: add ruby code - chapter hashing * feat: add ruby code blocks - chapter hashing * fix: comments
This commit is contained in:
@@ -299,7 +299,7 @@ $$
|
||||
```rust title="built_in_hash.rs"
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
|
||||
let num = 3;
|
||||
let mut num_hasher = DefaultHasher::new();
|
||||
num.hash(&mut num_hasher);
|
||||
@@ -374,7 +374,29 @@ $$
|
||||
=== "Ruby"
|
||||
|
||||
```ruby title="built_in_hash.rb"
|
||||
num = 3
|
||||
hash_num = num.hash
|
||||
# 整数 3 的哈希值为 -4385856518450339636
|
||||
|
||||
bol = true
|
||||
hash_bol = bol.hash
|
||||
# 布尔量 true 的哈希值为 -1617938112149317027
|
||||
|
||||
dec = 3.14159
|
||||
hash_dec = dec.hash
|
||||
# 小数 3.14159 的哈希值为 -1479186995943067893
|
||||
|
||||
str = "Hello 算法"
|
||||
hash_str = str.hash
|
||||
# 字符串“Hello 算法”的哈希值为 -4075943250025831763
|
||||
|
||||
tup = [12836, '小哈']
|
||||
hash_tup = tup.hash
|
||||
# 元组 (12836, '小哈') 的哈希值为 1999544809202288822
|
||||
|
||||
obj = ListNode.new(0)
|
||||
hash_obj = obj.hash
|
||||
# 节点对象 #<ListNode:0x000078133140ab70> 的哈希值为 4302940560806366381
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
Reference in New Issue
Block a user