Files
hello-algo/ru/codes/rust/chapter_hashing/build_in_hash.rs
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

50 lines
1.6 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* File: build_in_hash.rs
* Created Time: 2023-7-6
* Author: WSL0809 (wslzzy@outlook.com)
*/
use hello_algo_rust::include::ListNode;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
/* Driver Code */
fn main() {
let num = 3;
let mut num_hasher = DefaultHasher::new();
num.hash(&mut num_hasher);
let hash_num = num_hasher.finish();
println!("Хеш-значение целого числа {} = {}", num, hash_num);
let bol = true;
let mut bol_hasher = DefaultHasher::new();
bol.hash(&mut bol_hasher);
let hash_bol = bol_hasher.finish();
println!("Хеш-значение булева значения {} = {}", bol, hash_bol);
let dec: f32 = 3.14159;
let mut dec_hasher = DefaultHasher::new();
dec.to_bits().hash(&mut dec_hasher);
let hash_dec = dec_hasher.finish();
println!("Хеш-значение десятичного числа {} = {}", dec, hash_dec);
let str = "Hello Algo";
let mut str_hasher = DefaultHasher::new();
str.hash(&mut str_hasher);
let hash_str = str_hasher.finish();
println!("Хеш-значение строки {} = {}", str, hash_str);
let arr = (&12836, &"Сяо Ха");
let mut tup_hasher = DefaultHasher::new();
arr.hash(&mut tup_hasher);
let hash_tup = tup_hasher.finish();
println!("Хеш-значение кортежа {:?} = {}", arr, hash_tup);
let node = ListNode::new(42);
let mut hasher = DefaultHasher::new();
node.borrow().val.hash(&mut hasher);
let hash = hasher.finish();
println!("Хеш-значение объекта узла {:?} = {}", node, hash);
}