Files
hello-algo/ru/codes/rust/chapter_hashing/hash_map.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

49 lines
1.7 KiB
Rust
Raw 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: hash_map.rs
* Created Time: 2023-02-05
* Author: codingonion (coderonion@gmail.com)
*/
use hello_algo_rust::include::print_util;
use std::collections::HashMap;
/* Driver Code */
pub fn main() {
// Инициализация хеш-таблицы
let mut map = HashMap::new();
// Операция добавления
// Добавить пару (key, value) в хеш-таблицу
map.insert(12836, "Сяо Ха");
map.insert(15937, "Сяо Ло");
map.insert(16750, "Сяо Суань");
map.insert(13276, "Сяо Фа");
map.insert(10583, "Сяо Я");
println!("\nПосле добавления хеш-таблица имеет вид\nКлюч -> Значение");
print_util::print_hash_map(&map);
// Операция поиска
// Передать ключ key в хеш-таблицу и получить значение value
let name = map.get(&15937).copied().unwrap();
println!("\nДля номера 15937 найдено имя {name}");
// Операция удаления
// Удалить пару (key, value) из хеш-таблицы
_ = map.remove(&10583);
println!("\nПосле удаления 10583 хеш-таблица имеет вид\nКлюч -> Значение");
print_util::print_hash_map(&map);
// Обход хеш-таблицы
println!("\nОтдельный обход пар ключ-значение");
print_util::print_hash_map(&map);
println!("\nОтдельный обход ключей");
for key in map.keys() {
println!("{key}");
}
println!("\nОтдельный обход значений");
for value in map.values() {
println!("{value}");
}
}