feat(ko): add the Korean online edition (#2006)

* feat(ko): add the complete Korean online edition

* Use UTF-8 for Python CI output on Windows

* Remove print-book promotion from the Korean site

* fix(ko): preserve emphasis before Korean particles
This commit is contained in:
Yudong Jin
2026-10-29 03:46:43 +08:00
committed by GitHub
parent 71a773df64
commit 2f561d3d51
2072 changed files with 110884 additions and 102 deletions

View File

@@ -0,0 +1,128 @@
/**
* File: array_hash_map.js
* Created Time: 2022-12-26
* Author: Justin (xiefahit@gmail.com)
*/
/* 키-값 쌍 Number -> String */
class Pair {
constructor(key, val) {
this.key = key;
this.val = val;
}
}
/* 배열로 구현한 해시 테이블 */
class ArrayHashMap {
#buckets;
constructor() {
// 버킷 100개를 포함하는 배열을 초기화한다
this.#buckets = new Array(100).fill(null);
}
/* 해시 함수 */
#hashFunc(key) {
return key % 100;
}
/* 조회 연산 */
get(key) {
let index = this.#hashFunc(key);
let pair = this.#buckets[index];
if (pair === null) return null;
return pair.val;
}
/* 추가 연산 */
set(key, val) {
let index = this.#hashFunc(key);
this.#buckets[index] = new Pair(key, val);
}
/* 삭제 연산 */
delete(key) {
let index = this.#hashFunc(key);
// null로 설정하여 삭제를 나타낸다
this.#buckets[index] = null;
}
/* 모든 키-값 쌍 반환 */
entries() {
let arr = [];
for (let i = 0; i < this.#buckets.length; i++) {
if (this.#buckets[i]) {
arr.push(this.#buckets[i]);
}
}
return arr;
}
/* 모든 키 반환 */
keys() {
let arr = [];
for (let i = 0; i < this.#buckets.length; i++) {
if (this.#buckets[i]) {
arr.push(this.#buckets[i].key);
}
}
return arr;
}
/* 모든 값 반환 */
values() {
let arr = [];
for (let i = 0; i < this.#buckets.length; i++) {
if (this.#buckets[i]) {
arr.push(this.#buckets[i].val);
}
}
return arr;
}
/* 해시 테이블 출력 */
print() {
let pairSet = this.entries();
for (const pair of pairSet) {
console.info(`${pair.key} -> ${pair.val}`);
}
}
}
/* 실행 코드 */
/* 해시 테이블 초기화 */
const map = new ArrayHashMap();
/* 추가 연산 */
// 해시 테이블에 (key, value) 키-값 쌍을 추가한다
map.set(12836, '小哈');
map.set(15937, '小啰');
map.set(16750, '小算');
map.set(13276, '小法');
map.set(10583, '小鸭');
console.info('\n추가를 마친 후의 해시 테이블\n키 -> 값');
map.print();
/* 조회 연산 */
// 해시 테이블에 키 key를 입력하여 값 value를 얻는다
let name = map.get(15937);
console.info('\n학번 15937을 입력하여 조회한 이름 ' + name);
/* 삭제 연산 */
// 해시 테이블에서 (key, value) 키-값 쌍을 삭제한다
map.delete(10583);
console.info('\n10583을 삭제한 후의 해시 테이블\n키 -> 값');
map.print();
/* 해시 테이블 순회 */
console.info('\n키-값 쌍(키->값) 순회');
for (const pair of map.entries()) {
if (!pair) continue;
console.info(pair.key + ' -> ' + pair.val);
}
console.info('\n키 Key만 순회');
for (const key of map.keys()) {
console.info(key);
}
console.info('\n값 Value만 순회');
for (const val of map.values()) {
console.info(val);
}

View File

@@ -0,0 +1,44 @@
/**
* File: hash_map.js
* Created Time: 2022-12-26
* Author: Justin (xiefahit@gmail.com)
*/
/* 실행 코드 */
/* 해시 테이블 초기화 */
const map = new Map();
/* 추가 연산 */
// 해시 테이블에 (key, value) 키-값 쌍을 추가한다
map.set(12836, '小哈');
map.set(15937, '小啰');
map.set(16750, '小算');
map.set(13276, '小法');
map.set(10583, '小鸭');
console.info('\n추가를 마친 후의 해시 테이블\n키 -> 값');
console.info(map);
/* 조회 연산 */
// 해시 테이블에 키 key를 입력하여 값 value를 얻는다
let name = map.get(15937);
console.info('\n학번 15937을 입력하여 조회한 이름 ' + name);
/* 삭제 연산 */
// 해시 테이블에서 (key, value) 키-값 쌍을 삭제한다
map.delete(10583);
console.info('\n10583을 삭제한 후의 해시 테이블\n키 -> 값');
console.info(map);
/* 해시 테이블 순회 */
console.info('\n키-값 쌍(키->값) 순회');
for (const [k, v] of map.entries()) {
console.info(k + ' -> ' + v);
}
console.info('\n키 Key만 순회');
for (const k of map.keys()) {
console.info(k);
}
console.info('\n값 Value만 순회');
for (const v of map.values()) {
console.info(v);
}

View File

@@ -0,0 +1,142 @@
/**
* File: hash_map_chaining.js
* Created Time: 2023-08-06
* Author: yuan0221 (yl1452491917@gmail.com)
*/
/* 키-값 쌍 Number -> String */
class Pair {
constructor(key, val) {
this.key = key;
this.val = val;
}
}
/* 체이닝 해시 테이블 */
class HashMapChaining {
#size; // 키-값 쌍 개수
#capacity; // 해시 테이블 용량
#loadThres; // 용량 확장을 수행하는 적재율 임계값
#extendRatio; // 용량 확장 배수
#buckets; // 버킷 배열
/* 생성자 */
constructor() {
this.#size = 0;
this.#capacity = 4;
this.#loadThres = 2.0 / 3.0;
this.#extendRatio = 2;
this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);
}
/* 해시 함수 */
#hashFunc(key) {
return key % this.#capacity;
}
/* 적재율 */
#loadFactor() {
return this.#size / this.#capacity;
}
/* 조회 연산 */
get(key) {
const index = this.#hashFunc(key);
const bucket = this.#buckets[index];
// 버킷을 순회하다 key를 찾으면 해당 val을 반환한다
for (const pair of bucket) {
if (pair.key === key) {
return pair.val;
}
}
// key를 찾지 못하면 null을 반환한다
return null;
}
/* 추가 연산 */
put(key, val) {
// 적재율이 임계값을 초과하면 용량을 확장한다
if (this.#loadFactor() > this.#loadThres) {
this.#extend();
}
const index = this.#hashFunc(key);
const bucket = this.#buckets[index];
// 버킷을 순회하다 지정한 key를 만나면 해당 val을 갱신하고 반환한다
for (const pair of bucket) {
if (pair.key === key) {
pair.val = val;
return;
}
}
// 해당 key가 없으면 키-값 쌍을 맨 뒤에 추가한다
const pair = new Pair(key, val);
bucket.push(pair);
this.#size++;
}
/* 삭제 연산 */
remove(key) {
const index = this.#hashFunc(key);
let bucket = this.#buckets[index];
// 버킷을 순회하며 키-값 쌍을 삭제한다
for (let i = 0; i < bucket.length; i++) {
if (bucket[i].key === key) {
bucket.splice(i, 1);
this.#size--;
break;
}
}
}
/* 해시 테이블 용량 확장 */
#extend() {
// 원래 해시 테이블을 임시로 저장한다
const bucketsTmp = this.#buckets;
// 용량을 확장한 새 해시 테이블을 초기화한다
this.#capacity *= this.#extendRatio;
this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);
this.#size = 0;
// 원래 해시 테이블의 키-값 쌍을 새 해시 테이블로 옮긴다
for (const bucket of bucketsTmp) {
for (const pair of bucket) {
this.put(pair.key, pair.val);
}
}
}
/* 해시 테이블 출력 */
print() {
for (const bucket of this.#buckets) {
let res = [];
for (const pair of bucket) {
res.push(pair.key + ' -> ' + pair.val);
}
console.log(res);
}
}
}
/* 실행 코드 */
/* 해시 테이블 초기화 */
const map = new HashMapChaining();
/* 추가 연산 */
// 해시 테이블에 (key, value) 키-값 쌍을 추가한다
map.put(12836, '小哈');
map.put(15937, '小啰');
map.put(16750, '小算');
map.put(13276, '小法');
map.put(10583, '小鸭');
console.log('\n추가를 마친 후의 해시 테이블\n키 -> 값');
map.print();
/* 조회 연산 */
// 해시 테이블에 키 key를 입력하여 값 value를 얻는다
const name = map.get(13276);
console.log('\n학번 13276을 입력하여 조회한 이름 ' + name);
/* 삭제 연산 */
// 해시 테이블에서 (key, value) 키-값 쌍을 삭제한다
map.remove(12836);
console.log('\n12836을 삭제한 뒤의 해시 테이블\n키 -> 값');
map.print();

View File

@@ -0,0 +1,177 @@
/**
* File: hashMapOpenAddressing.js
* Created Time: 2023-06-13
* Author: yuan0221 (yl1452491917@gmail.com), krahets (krahets@163.com)
*/
/* 키-값 쌍 Number -> String */
class Pair {
constructor(key, val) {
this.key = key;
this.val = val;
}
}
/* 개방 주소법 해시 테이블 */
class HashMapOpenAddressing {
#size; // 키-값 쌍 개수
#capacity; // 해시 테이블 용량
#loadThres; // 용량 확장을 수행하는 적재율 임계값
#extendRatio; // 용량 확장 배수
#buckets; // 버킷 배열
#TOMBSTONE; // 삭제 표시
/* 생성자 */
constructor() {
this.#size = 0; // 키-값 쌍 개수
this.#capacity = 4; // 해시 테이블 용량
this.#loadThres = 2.0 / 3.0; // 용량 확장을 수행하는 적재율 임계값
this.#extendRatio = 2; // 용량 확장 배수
this.#buckets = Array(this.#capacity).fill(null); // 버킷 배열
this.#TOMBSTONE = new Pair(-1, '-1'); // 삭제 표시
}
/* 해시 함수 */
#hashFunc(key) {
return key % this.#capacity;
}
/* 적재율 */
#loadFactor() {
return this.#size / this.#capacity;
}
/* key에 해당하는 버킷 인덱스 탐색 */
#findBucket(key) {
let index = this.#hashFunc(key);
let firstTombstone = -1;
// 선형 탐사로 탐색하고, 빈 버킷을 만나면 반복문을 종료한다
while (this.#buckets[index] !== null) {
// key를 만나면 해당 버킷 인덱스를 반환한다
if (this.#buckets[index].key === key) {
// 이전에 삭제 표시를 만났으면 키-값 쌍을 그 인덱스로 옮긴다
if (firstTombstone !== -1) {
this.#buckets[firstTombstone] = this.#buckets[index];
this.#buckets[index] = this.#TOMBSTONE;
return firstTombstone; // 옮긴 후의 버킷 인덱스를 반환한다
}
return index; // 버킷 인덱스를 반환한다
}
// 처음 만난 삭제 표시를 기록한다
if (
firstTombstone === -1 &&
this.#buckets[index] === this.#TOMBSTONE
) {
firstTombstone = index;
}
// 버킷 인덱스를 계산하고, 끝을 넘어가면 처음으로 돌아온다
index = (index + 1) % this.#capacity;
}
// key가 없으면 추가할 위치의 인덱스를 반환한다
return firstTombstone === -1 ? index : firstTombstone;
}
/* 조회 연산 */
get(key) {
// key에 해당하는 버킷 인덱스 탐색
const index = this.#findBucket(key);
// 키-값 쌍을 찾으면 해당 val을 반환한다
if (
this.#buckets[index] !== null &&
this.#buckets[index] !== this.#TOMBSTONE
) {
return this.#buckets[index].val;
}
// 키-값 쌍이 없으면 null을 반환한다
return null;
}
/* 추가 연산 */
put(key, val) {
// 적재율이 임계값을 초과하면 용량을 확장한다
if (this.#loadFactor() > this.#loadThres) {
this.#extend();
}
// key에 해당하는 버킷 인덱스 탐색
const index = this.#findBucket(key);
// 키-값 쌍을 찾으면 val을 덮어쓰고 반환한다
if (
this.#buckets[index] !== null &&
this.#buckets[index] !== this.#TOMBSTONE
) {
this.#buckets[index].val = val;
return;
}
// 키-값 쌍이 없으면 해당 키-값 쌍을 추가한다
this.#buckets[index] = new Pair(key, val);
this.#size++;
}
/* 삭제 연산 */
remove(key) {
// key에 해당하는 버킷 인덱스 탐색
const index = this.#findBucket(key);
// 키-값 쌍을 찾으면 삭제 표시로 덮어쓴다
if (
this.#buckets[index] !== null &&
this.#buckets[index] !== this.#TOMBSTONE
) {
this.#buckets[index] = this.#TOMBSTONE;
this.#size--;
}
}
/* 해시 테이블 용량 확장 */
#extend() {
// 원래 해시 테이블을 임시로 저장한다
const bucketsTmp = this.#buckets;
// 용량을 확장한 새 해시 테이블을 초기화한다
this.#capacity *= this.#extendRatio;
this.#buckets = Array(this.#capacity).fill(null);
this.#size = 0;
// 원래 해시 테이블의 키-값 쌍을 새 해시 테이블로 옮긴다
for (const pair of bucketsTmp) {
if (pair !== null && pair !== this.#TOMBSTONE) {
this.put(pair.key, pair.val);
}
}
}
/* 해시 테이블 출력 */
print() {
for (const pair of this.#buckets) {
if (pair === null) {
console.log('null');
} else if (pair === this.#TOMBSTONE) {
console.log('TOMBSTONE');
} else {
console.log(pair.key + ' -> ' + pair.val);
}
}
}
}
/* 실행 코드 */
// 해시 테이블 초기화
const hashmap = new HashMapOpenAddressing();
// 추가 연산
// 해시 테이블에 키-값 쌍 (key, val)을 추가한다
hashmap.put(12836, '小哈');
hashmap.put(15937, '小啰');
hashmap.put(16750, '小算');
hashmap.put(13276, '小法');
hashmap.put(10583, '小鸭');
console.log('\n추가를 마친 후의 해시 테이블\n키 -> 값');
hashmap.print();
// 조회 연산
// 해시 테이블에 키 key를 입력하여 값 val을 얻는다
const name = hashmap.get(13276);
console.log('\n학번 13276을 입력하여 조회한 이름 ' + name);
// 삭제 연산
// 해시 테이블에서 키-값 쌍 (key, val)을 삭제한다
hashmap.remove(16750);
console.log('\n16750을 삭제한 후의 해시 테이블\n키 -> 값');
hashmap.print();

View File

@@ -0,0 +1,60 @@
/**
* File: simple_hash.js
* Created Time: 2023-08-06
* Author: yuan0221 (yl1452491917@gmail.com)
*/
/* 덧셈 해시 */
function addHash(key) {
let hash = 0;
const MODULUS = 1000000007;
for (const c of key) {
hash = (hash + c.charCodeAt(0)) % MODULUS;
}
return hash;
}
/* 곱셈 해시 */
function mulHash(key) {
let hash = 0;
const MODULUS = 1000000007;
for (const c of key) {
hash = (31 * hash + c.charCodeAt(0)) % MODULUS;
}
return hash;
}
/* XOR 해시 */
function xorHash(key) {
let hash = 0;
const MODULUS = 1000000007;
for (const c of key) {
hash ^= c.charCodeAt(0);
}
return hash % MODULUS;
}
/* 회전 해시 */
function rotHash(key) {
let hash = 0;
const MODULUS = 1000000007;
for (const c of key) {
hash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;
}
return hash;
}
/* 실행 코드 */
const key = 'Hello 算法';
let hash = addHash(key);
console.log('덧셈 해시값: ' + hash);
hash = mulHash(key);
console.log('곱셈 해시값: ' + hash);
hash = xorHash(key);
console.log('XOR 해시값: ' + hash);
hash = rotHash(key);
console.log('회전 해시값: ' + hash);