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

75 lines
2.2 KiB
Go
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: hash_map_test.go
// Created Time: 2022-12-14
// Author: msk397 (machangxinq@gmail.com)
package chapter_hashing
import (
"fmt"
"strconv"
"testing"
. "github.com/krahets/hello-algo/pkg"
)
func TestHashMap(t *testing.T) {
/* Инициализация хеш-таблицы */
hmap := make(map[int]string)
/* Операция добавления */
// Добавить пару (key, value) в хеш-таблицу
hmap[12836] = "Сяо Ха"
hmap[15937] = "Сяо Ло"
hmap[16750] = "Сяо Суань"
hmap[13276] = "Сяо Фа"
hmap[10583] = "Сяо Я"
fmt.Println("\nПосле добавления хеш-таблица имеет вид\nКлюч -> Значение")
PrintMap(hmap)
/* Операция поиска */
// Ввести в хеш-таблицу ключ key и получить значение value
name := hmap[15937]
fmt.Println("\nДля номера 15937 найдено имя", name)
/* Операция удаления */
// Удалить пару (key, value) из хеш-таблицы
delete(hmap, 10583)
fmt.Println("\nПосле удаления 10583 хеш-таблица имеет вид\nКлюч -> Значение")
PrintMap(hmap)
/* Обход хеш-таблицы */
// Перебрать пары ключ-значение key->value
fmt.Println("\nОтдельный обход пар ключ-значение")
for key, value := range hmap {
fmt.Println(key, "->", value)
}
// Отдельно обходить ключи key
fmt.Println("\nОтдельный обход ключей")
for key := range hmap {
fmt.Println(key)
}
// Отдельно обходить значения value
fmt.Println("\nОтдельный обход значений")
for _, value := range hmap {
fmt.Println(value)
}
}
func TestSimpleHash(t *testing.T) {
var hash int
key := "Hello Algo"
hash = addHash(key)
fmt.Println("Хеш-сумма сложением = " + strconv.Itoa(hash))
hash = mulHash(key)
fmt.Println("Хеш-сумма умножением = " + strconv.Itoa(hash))
hash = xorHash(key)
fmt.Println("Хеш-сумма XOR = " + strconv.Itoa(hash))
hash = rotHash(key)
fmt.Println("Хеш-сумма с циклическим сдвигом = " + strconv.Itoa(hash))
}