Retranslate the complete Japanese online edition from Chinese (#2008)

* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
This commit is contained in:
Yudong Jin
2026-10-30 02:12:26 +08:00
committed by GitHub
parent 455e8c1281
commit 7257641e0e
1987 changed files with 23531 additions and 23261 deletions
+10 -10
View File
@@ -6,7 +6,7 @@
#include "../utils/common.hpp"
/* キーと値の組 */
/* キーと値のペア */
struct Pair {
public:
int key;
@@ -17,14 +17,14 @@ struct Pair {
}
};
/* 配列ベースのハッシュテーブル */
/* 配列で実装したハッシュテーブル */
class ArrayHashMap {
private:
vector<Pair *> buckets;
public:
ArrayHashMap() {
// 100 個のバケットを含む配列を初期化
// 100 個のバケットを含む配列を初期化する
buckets = vector<Pair *>(100);
}
@@ -42,7 +42,7 @@ class ArrayHashMap {
return index;
}
/* 検索操作 */
/* 取得操作 */
string get(int key) {
int index = hashFunc(key);
Pair *pair = buckets[index];
@@ -61,12 +61,12 @@ class ArrayHashMap {
/* 削除操作 */
void remove(int key) {
int index = hashFunc(key);
// メモリを解放して nullptr に設定する
// メモリを解放し、nullptr に設定する
delete buckets[index];
buckets[index] = nullptr;
}
/* すべてのキーと値のペアを取得 */
/* キーと値のペアをすべて取得する */
vector<Pair *> pairSet() {
vector<Pair *> pairSet;
for (Pair *pair : buckets) {
@@ -77,7 +77,7 @@ class ArrayHashMap {
return pairSet;
}
/* すべてのキーを取得 */
/* すべてのキーを取得する */
vector<int> keySet() {
vector<int> keySet;
for (Pair *pair : buckets) {
@@ -88,7 +88,7 @@ class ArrayHashMap {
return keySet;
}
/* すべての値を取得 */
/* すべての値を取得する */
vector<string> valueSet() {
vector<string> valueSet;
for (Pair *pair : buckets) {
@@ -99,7 +99,7 @@ class ArrayHashMap {
return valueSet;
}
/* ハッシュテーブルを出力 */
/* ハッシュテーブルを表示する */
void print() {
for (Pair *kv : pairSet()) {
cout << kv->key << " -> " << kv->val << endl;
@@ -107,4 +107,4 @@ class ArrayHashMap {
}
};
// テストケースは `array_hash_map_test.cpp` を参照
// テストケースは array_hash_map_test.cpp を参照
@@ -6,44 +6,44 @@
#include "./array_hash_map.cpp"
/* Driver Code */
/* 実行用コード */
int main() {
/* ハッシュテーブルを初期化 */
/* ハッシュテーブルを初期化する */
ArrayHashMap map = ArrayHashMap();
/* 追加操作 */
// ハッシュテーブルにキーと値のペア (key, value) を追加
map.put(12836, "シャオハー");
map.put(15937, "シャオルオ");
map.put(16750, "シャオスワン");
map.put(13276, "シャオファー");
map.put(10583, "シャオヤー");
cout << "\n追加完了後、ハッシュテーブルは\nKey -> Value" << endl;
// ハッシュテーブルにキーと値のペア (key, value) を追加する
map.put(12836, "小哈");
map.put(15937, "小啰");
map.put(16750, "小算");
map.put(13276, "小法");
map.put(10583, "小鸭");
cout << "\n追加後のハッシュテーブル\nKey -> Value" << endl;
map.print();
/* 検索操作 */
// キー key をハッシュテーブルに渡し、値 value を取得
/* 取得操作 */
// ハッシュテーブルにキー key を渡し、値 value を取得する
string name = map.get(15937);
cout << "\n学籍番号 15937 を入力すると、氏名 " << name << endl;
cout << "\n学生番号 15937 に対応する氏名は " << name << endl;
/* 削除操作 */
// ハッシュテーブルからキーと値のペア (key, value) を削除
// ハッシュテーブルからキーと値のペア (key, value) を削除する
map.remove(10583);
cout << "\n10583 を削除した後、ハッシュテーブルは\nKey -> Value" << endl;
cout << "\n10583 を削除した後のハッシュテーブル\nKey -> Value" << endl;
map.print();
/* ハッシュテーブルを走査 */
cout << "\nキーと値のペア Key->Value を走査" << endl;
/* ハッシュテーブルを走査する */
cout << "\nキーと値のペア Key->Value を走査する" << endl;
for (auto kv : map.pairSet()) {
cout << kv->key << " -> " << kv->val << endl;
}
cout << "\nキー Key のみを走査" << endl;
cout << "\nキー Key だけを走査する" << endl;
for (auto key : map.keySet()) {
cout << key << endl;
}
cout << "\n値 Value のみを走査" << endl;
cout << "\n値 Value だけを走査する" << endl;
for (auto val : map.valueSet()) {
cout << val << endl;
}
@@ -6,7 +6,7 @@
#include "../utils/common.hpp"
/* Driver Code */
/* 実行用コード */
int main() {
int num = 3;
size_t hashNum = hash<int>()(num);
@@ -20,10 +20,10 @@ int main() {
size_t hashDec = hash<double>()(dec);
cout << "小数 " << dec << " のハッシュ値は " << hashDec << "\n";
string str = "Hello アルゴリズム";
string str = "Hello 算法";
size_t hashStr = hash<string>()(str);
cout << "文字列 " << str << " のハッシュ値は " << hashStr << "\n";
// C++ では、組み込みの std::hash() は基本データ型のハッシュ値計算しか提供しない
// 配列やオブジェクトのハッシュ値計算は自分で実装する必要がある
// C++ の組み込み std::hash() は、基本データ型のハッシュ値の計算にのみ対応する
// 配列やオブジェクトのハッシュ値の計算は自分で実装する必要がある
}
+17 -17
View File
@@ -6,38 +6,38 @@
#include "../utils/common.hpp"
/* Driver Code */
/* 実行用コード */
int main() {
/* ハッシュテーブルを初期化 */
/* ハッシュテーブルを初期化する */
unordered_map<int, string> map;
/* 追加操作 */
// ハッシュテーブルにキーと値のペア (key, value) を追加
map[12836] = "シャオハー";
map[15937] = "シャオルオ";
map[16750] = "シャオスワン";
map[13276] = "シャオファー";
map[10583] = "シャオヤー";
cout << "\n追加完了後、ハッシュテーブルは\nKey -> Value" << endl;
// ハッシュテーブルにキーと値のペア (key, value) を追加する
map[12836] = "小哈";
map[15937] = "小啰";
map[16750] = "小算";
map[13276] = "小法";
map[10583] = "小鸭";
cout << "\n追加後のハッシュテーブル\nKey -> Value" << endl;
printHashMap(map);
/* 検索操作 */
// キー key をハッシュテーブルに渡し、値 value を取得
/* 取得操作 */
// ハッシュテーブルにキー key を渡し、値 value を取得する
string name = map[15937];
cout << "\n学籍番号 15937 を入力すると、氏名 " << name << endl;
cout << "\n学生番号 15937 に対応する氏名は " << name << endl;
/* 削除操作 */
// ハッシュテーブルからキーと値のペア (key, value) を削除
// ハッシュテーブルからキーと値のペア (key, value) を削除する
map.erase(10583);
cout << "\n10583 を削除した後、ハッシュテーブルは\nKey -> Value" << endl;
cout << "\n10583 を削除した後のハッシュテーブル\nKey -> Value" << endl;
printHashMap(map);
/* ハッシュテーブルを走査 */
cout << "\nキーと値のペア Key->Value を走査" << endl;
/* ハッシュテーブルを走査する */
cout << "\nキーと値のペア Key->Value を走査する" << endl;
for (auto kv : map) {
cout << kv.first << " -> " << kv.second << endl;
}
cout << "\nイテレータで Key->Value を走査" << endl;
cout << "\nイテレータで Key->Value を走査する" << endl;
for (auto iter = map.begin(); iter != map.end(); iter++) {
cout << iter->first << "->" << iter->second << endl;
}
@@ -6,13 +6,13 @@
#include "./array_hash_map.cpp"
/* チェイン法ハッシュテーブル */
/* チェイン法のハッシュテーブル */
class HashMapChaining {
private:
int size; // キーと値のペア数
int capacity; // ハッシュテーブル容量
double loadThres; // リサイズを発動する負荷率のしきい値
int extendRatio; // 拡張倍率
int size; // キーと値のペアの数
int capacity; // ハッシュテーブルの容量
double loadThres; // 容量の拡張を開始する負荷率のしきい値
int extendRatio; // 容量の拡張倍率
vector<vector<Pair *>> buckets; // バケット配列
public:
@@ -21,7 +21,7 @@ class HashMapChaining {
buckets.resize(capacity);
}
/* デストラクタメソッド */
/* デストラクタ */
~HashMapChaining() {
for (auto &bucket : buckets) {
for (Pair *pair : bucket) {
@@ -41,34 +41,34 @@ class HashMapChaining {
return (double)size / (double)capacity;
}
/* 検索操作 */
/* 取得操作 */
string get(int key) {
int index = hashFunc(key);
// バケットを走査し、key が見つかれば対応する val を返す
// バケットを走査し、key が見つかったら対応する val を返す
for (Pair *pair : buckets[index]) {
if (pair->key == key) {
return pair->val;
}
}
// key が見つからない場合は空文字列を返す
// key が見つからなかった場合、空文字列を返す
return "";
}
/* 追加操作 */
void put(int key, string val) {
// 負荷率がしきい値を超えたら、リサイズを実行
// 負荷率がしきい値を超えた場合、容量を拡張する
if (loadFactor() > loadThres) {
extend();
}
int index = hashFunc(key);
// バケットを走査し、指定した key が見つかれば対応する val を更新して返す
// バケットを走査し、指定された key が見つかったら、対応する val を更新して戻る
for (Pair *pair : buckets[index]) {
if (pair->key == key) {
pair->val = val;
return;
}
}
// その key が存在しなければ、キーと値のペアを末尾に追加
// key が存在しない場合、キーと値のペアを末尾に追加する
buckets[index].push_back(new Pair(key, val));
size++;
}
@@ -77,11 +77,11 @@ class HashMapChaining {
void remove(int key) {
int index = hashFunc(key);
auto &bucket = buckets[index];
// バケットを走査してキーと値のペアを削除
// バケットを走査し、キーと値のペアを削除する
for (int i = 0; i < bucket.size(); i++) {
if (bucket[i]->key == key) {
Pair *tmp = bucket[i];
bucket.erase(bucket.begin() + i); // そこからキーと値の組を削除する
bucket.erase(bucket.begin() + i); // キーと値のペアを削除する
delete tmp; // メモリを解放する
size--;
return;
@@ -89,16 +89,16 @@ class HashMapChaining {
}
}
/* ハッシュテーブルを拡張 */
/* ハッシュテーブルの容量を拡張する */
void extend() {
// 元のハッシュテーブルを一時保存
// 元のハッシュテーブルを一時保存する
vector<vector<Pair *>> bucketsTmp = buckets;
// リサイズ後の新しいハッシュテーブルを初期化
// 拡張後の新しいハッシュテーブルを初期化する
capacity *= extendRatio;
buckets.clear();
buckets.resize(capacity);
size = 0;
// キーと値のペアを元のハッシュテーブルから新しいハッシュテーブルへ移す
// キーと値のペアを元のハッシュテーブルから新しいハッシュテーブルに移す
for (auto &bucket : bucketsTmp) {
for (Pair *pair : bucket) {
put(pair->key, pair->val);
@@ -108,7 +108,7 @@ class HashMapChaining {
}
}
/* ハッシュテーブルを出力 */
/* ハッシュテーブルを表示する */
void print() {
for (auto &bucket : buckets) {
cout << "[";
@@ -120,30 +120,30 @@ class HashMapChaining {
}
};
/* Driver Code */
/* 実行用コード */
int main() {
/* ハッシュテーブルを初期化 */
/* ハッシュテーブルを初期化する */
HashMapChaining map = HashMapChaining();
/* 追加操作 */
// ハッシュテーブルにキーと値のペア (key, value) を追加
map.put(12836, "シャオハー");
map.put(15937, "シャオルオ");
map.put(16750, "シャオスワン");
map.put(13276, "シャオファー");
map.put(10583, "シャオヤー");
cout << "\n追加完了後、ハッシュテーブルは\nKey -> Value" << endl;
// ハッシュテーブルにキーと値のペア (key, value) を追加する
map.put(12836, "小哈");
map.put(15937, "小啰");
map.put(16750, "小算");
map.put(13276, "小法");
map.put(10583, "小鸭");
cout << "\n追加後のハッシュテーブル\nKey -> Value" << endl;
map.print();
/* 検索操作 */
// キー key をハッシュテーブルに渡し、値 value を取得
/* 取得操作 */
// ハッシュテーブルにキー key を渡し、値 value を取得する
string name = map.get(13276);
cout << "\n学籍番号 13276 を入力すると、氏名 " << name << endl;
cout << "\n学生番号 13276 に対応する氏名は " << name << endl;
/* 削除操作 */
// ハッシュテーブルからキーと値のペア (key, value) を削除
// ハッシュテーブルからキーと値のペア (key, value) を削除する
map.remove(12836);
cout << "\n12836 を削除した後、ハッシュテーブルは\nKey -> Value" << endl;
cout << "\n12836 を削除した後のハッシュテーブル\nKey -> Value" << endl;
map.print();
return 0;
@@ -6,22 +6,22 @@
#include "./array_hash_map.cpp"
/* オープンアドレス法ハッシュテーブル */
/* オープンアドレス法のハッシュテーブル */
class HashMapOpenAddressing {
private:
int size; // キーと値のペア数
int capacity = 4; // ハッシュテーブル容量
const double loadThres = 2.0 / 3.0; // リサイズを発動する負荷率のしきい値
const int extendRatio = 2; // 拡張倍率
int size; // キーと値のペアの数
int capacity = 4; // ハッシュテーブルの容量
const double loadThres = 2.0 / 3.0; // 容量の拡張を開始する負荷率のしきい値
const int extendRatio = 2; // 容量の拡張倍率
vector<Pair *> buckets; // バケット配列
Pair *TOMBSTONE = new Pair(-1, "-1"); // 削除済みマーク
Pair *TOMBSTONE = new Pair(-1, "-1"); // 削除マーカー
public:
/* コンストラクタ */
HashMapOpenAddressing() : size(0), buckets(capacity, nullptr) {
}
/* デストラクタメソッド */
/* デストラクタ */
~HashMapOpenAddressing() {
for (Pair *pair : buckets) {
if (pair != nullptr && pair != TOMBSTONE) {
@@ -41,68 +41,68 @@ class HashMapOpenAddressing {
return (double)size / capacity;
}
/* key に対応するバケットインデックスを探す */
/* key に対応するバケットのインデックスを探索する */
int findBucket(int key) {
int index = hashFunc(key);
int firstTombstone = -1;
// 線形プロービングを行い、空バケットに達したら終了
// 線形探索法で探索し、空のバケットに到達したら終了する
while (buckets[index] != nullptr) {
// key が見つかったら、対応するバケットのインデックスを返す
// key が見つかった場合、対応するバケットのインデックスを返す
if (buckets[index]->key == key) {
// 以前に削除マークが見つかっていれば、そのインデックスへキーと値のペアを移動
// それ以前に削除マーカーが見つかっていれば、そのインデックスにキーと値のペアを移す
if (firstTombstone != -1) {
buckets[firstTombstone] = buckets[index];
buckets[index] = TOMBSTONE;
return firstTombstone; // 移動後のバケットインデックスを返す
return firstTombstone; // 移動後のバケットのインデックスを返す
}
return index; // バケットのインデックスを返す
}
// 最初に見つかった削除マークを記録
// 最初に見つかった削除マーカーを記録する
if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {
firstTombstone = index;
}
// バケットのインデックスを計算し、末尾を越えたら先頭に戻る
index = (index + 1) % capacity;
}
// key が存在しない場合は追加位置のインデックスを返す
// key が存在しない場合、追加位置のインデックスを返す
return firstTombstone == -1 ? index : firstTombstone;
}
/* 検索操作 */
/* 取得操作 */
string get(int key) {
// key に対応するバケットインデックスを探す
// key に対応するバケットのインデックスを探索する
int index = findBucket(key);
// キーと値の組が見つかったら、対応する val を返す
// キーと値のペアが見つかった場合、対応する val を返す
if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {
return buckets[index]->val;
}
// キーと値の組が存在しない場合は空文字列を返す
// キーと値のペアが存在しない場合、空文字列を返す
return "";
}
/* 追加操作 */
void put(int key, string val) {
// 負荷率がしきい値を超えたら、リサイズを実行
// 負荷率がしきい値を超えた場合、容量を拡張する
if (loadFactor() > loadThres) {
extend();
}
// key に対応するバケットインデックスを探す
// key に対応するバケットのインデックスを探索する
int index = findBucket(key);
// キーと値の組が見つかったら、val を上書きして返す
// キーと値のペアが見つかった場合、val を上書きして戻る
if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {
buckets[index]->val = val;
return;
}
// キーと値の組が存在しない場合は、その組を追加する
// キーと値のペアが存在しない場合、そのペアを追加する
buckets[index] = new Pair(key, val);
size++;
}
/* 削除操作 */
void remove(int key) {
// key に対応するバケットインデックスを探す
// key に対応するバケットのインデックスを探索する
int index = findBucket(key);
// キーと値の組が見つかったら、削除マーカーで上書きする
// キーと値のペアが見つかった場合、削除マーカーで上書きする
if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {
delete buckets[index];
buckets[index] = TOMBSTONE;
@@ -110,15 +110,15 @@ class HashMapOpenAddressing {
}
}
/* ハッシュテーブルを拡張 */
/* ハッシュテーブルの容量を拡張する */
void extend() {
// 元のハッシュテーブルを一時保存
// 元のハッシュテーブルを一時保存する
vector<Pair *> bucketsTmp = buckets;
// リサイズ後の新しいハッシュテーブルを初期化
// 拡張後の新しいハッシュテーブルを初期化する
capacity *= extendRatio;
buckets = vector<Pair *>(capacity, nullptr);
size = 0;
// キーと値のペアを元のハッシュテーブルから新しいハッシュテーブルへ移す
// キーと値のペアを元のハッシュテーブルから新しいハッシュテーブルに移す
for (Pair *pair : bucketsTmp) {
if (pair != nullptr && pair != TOMBSTONE) {
put(pair->key, pair->val);
@@ -127,7 +127,7 @@ class HashMapOpenAddressing {
}
}
/* ハッシュテーブルを出力 */
/* ハッシュテーブルを表示する */
void print() {
for (Pair *pair : buckets) {
if (pair == nullptr) {
@@ -141,30 +141,30 @@ class HashMapOpenAddressing {
}
};
/* Driver Code */
/* 実行用コード */
int main() {
// ハッシュテーブルを初期化
// ハッシュテーブルを初期化する
HashMapOpenAddressing hashmap;
// 追加操作
// ハッシュテーブルにキーと値の組 (key, val) を追加する
hashmap.put(12836, "シャオハー");
hashmap.put(15937, "シャオルオ");
hashmap.put(16750, "シャオスワン");
hashmap.put(13276, "シャオファー");
hashmap.put(10583, "シャオヤー");
cout << "\n追加完了後、ハッシュテーブルは\nKey -> Value" << endl;
// ハッシュテーブルにキーと値のペア (key, val) を追加する
hashmap.put(12836, "小哈");
hashmap.put(15937, "小啰");
hashmap.put(16750, "小算");
hashmap.put(13276, "小法");
hashmap.put(10583, "小鸭");
cout << "\n追加後のハッシュテーブル\nKey -> Value" << endl;
hashmap.print();
// 検索操作
// ハッシュテーブルにキー key を入力し、値 val を得る
// 取得操作
// ハッシュテーブルにキー key を渡し、値 val を取得する
string name = hashmap.get(13276);
cout << "\n学籍番号 13276 を入力すると、氏名 " << name << endl;
cout << "\n学生番号 13276 に対応する氏名は " << name << endl;
// 削除操作
// ハッシュテーブルからキーと値の組 (key, val) を削除する
// ハッシュテーブルからキーと値のペア (key, val) を削除する
hashmap.remove(16750);
cout << "\n16750 を削除した後、ハッシュテーブルは\nKey -> Value" << endl;
cout << "\n16750 を削除した後のハッシュテーブル\nKey -> Value" << endl;
hashmap.print();
return 0;
+7 -7
View File
@@ -26,7 +26,7 @@ int mulHash(string key) {
return (int)hash;
}
/* XOR ハッシュ */
/* 排他的論理和ハッシュ */
int xorHash(string key) {
int hash = 0;
const int MODULUS = 1000000007;
@@ -46,21 +46,21 @@ int rotHash(string key) {
return (int)hash;
}
/* Driver Code */
/* 実行用コード */
int main() {
string key = "Hello アルゴリズム";
string key = "Hello 算法";
int hash = addHash(key);
cout << "加算ハッシュ値は " << hash << endl;
cout << "加算ハッシュの値は " << hash << endl;
hash = mulHash(key);
cout << "乗算ハッシュ値は " << hash << endl;
cout << "乗算ハッシュの値は " << hash << endl;
hash = xorHash(key);
cout << "XORハッシュ値は " << hash << endl;
cout << "排他的論理和ハッシュの値は " << hash << endl;
hash = rotHash(key);
cout << "回転ハッシュ値は " << hash << endl;
cout << "回転ハッシュの値は " << hash << endl;
return 0;
}