์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿš€ ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๋„๊ตฌ ๊ฐœ๋ฐœ: ์ž‘์—… ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„์œผ๋กœ ์™„์„ฑํ•˜๋Š” ๋™์‹œ ํŽธ์ง‘ ์‹œ์Šคํ…œ

๐Ÿš€ ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๋„๊ตฌ ๊ฐœ๋ฐœ: ์ž‘์—… ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„์œผ๋กœ ์™„์„ฑํ•˜๋Š” ๋™์‹œ ํŽธ์ง‘ ์‹œ์Šคํ…œ

์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ๋™์‹œ์— ๋ฌธ์„œ๋ฅผ ํŽธ์ง‘ํ•ด๋„ ์ถฉ๋Œ ์—†์ด ์ž‘๋™ํ•˜๋Š” ๋งˆ๋ฒ• ๊ฐ™์€ ๊ธฐ์ˆ ์˜ ๋น„๋ฐ€ ๐ŸŽฏ

์‚ฌ์šฉ์ž A ํŽธ์ง‘์ค‘ ์‚ฌ์šฉ์ž B ํŽธ์ง‘์ค‘ ์‚ฌ์šฉ์ž C ํŽธ์ง‘์ค‘ ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ OT Engine ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ์‹œ์Šคํ…œ

์•ˆ๋…•! ์˜ค๋Š˜์€ ์ •๋ง ํฅ๋ฏธ์ง„์ง„ํ•œ ์ฃผ์ œ๋ฅผ ๊ฐ€์ง€๊ณ  ์™”์–ด. ๐Ÿ˜Š ๊ตฌ๊ธ€ ๋…์Šค๋‚˜ ๋…ธ์…˜ ๊ฐ™์€ ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•ด๋ณธ ์  ์žˆ์ง€? ์—ฌ๋Ÿฌ ๋ช…์ด ๋™์‹œ์— ๊ฐ™์€ ๋ฌธ์„œ๋ฅผ ํŽธ์ง‘ํ•˜๋Š”๋ฐ๋„ ์‹ ๊ธฐํ•˜๊ฒŒ ์ถฉ๋Œ์ด ์•ˆ ๋‚˜๊ณ  ๋ชจ๋“  ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ฐ˜์˜๋˜์ž–์•„. ์ด๊ฒŒ ์–ด๋–ป๊ฒŒ ๊ฐ€๋Šฅํ•œ์ง€ ๊ถ๊ธˆํ•˜์ง€ ์•Š์•˜์–ด? ๋ฐ”๋กœ ์ž‘์—… ๋ณ€ํ™˜(Operational Transformation) ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋•๋ถ„์ด์•ผ!

์ด ๊ธฐ์ˆ ์€ ๋‹จ์ˆœํ•ด ๋ณด์ด์ง€๋งŒ ์‹ค์ œ๋กœ๋Š” ์—„์ฒญ๋‚˜๊ฒŒ ๋ณต์žกํ•œ ์ˆ˜ํ•™์  ์›๋ฆฌ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ˆจ์–ด์žˆ์–ด. ํ•˜์ง€๋งŒ ๊ฑฑ์ • ๋งˆ! ์นœ๊ตฌํ•œํ…Œ ์„ค๋ช…ํ•˜๋“ฏ์ด ์‰ฝ๊ณ  ์žฌ๋ฏธ์žˆ๊ฒŒ ํ’€์–ด์„œ ์„ค๋ช…ํ•ด์ค„๊ฒŒ. ์ด ๊ธ€์„ ๋‹ค ์ฝ๊ณ  ๋‚˜๋ฉด ๋„ˆ๋„ ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์„ ๊ฑฐ์•ผ! ๐ŸŽ‰

๐Ÿค” ์™œ ์ž‘์—… ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ํ•„์š”ํ• ๊นŒ?

๋จผ์ € ๋ฌธ์ œ ์ƒํ™ฉ๋ถ€ํ„ฐ ์ดํ•ดํ•ด๋ณด์ž. ์ƒ์ƒํ•ด๋ด, ์ฒ ์ˆ˜์™€ ์˜ํฌ๊ฐ€ ๋™์‹œ์— ๊ฐ™์€ ๋ฌธ์„œ๋ฅผ ํŽธ์ง‘ํ•˜๊ณ  ์žˆ์–ด. ๋ฌธ์„œ์˜ ์ดˆ๊ธฐ ์ƒํƒœ๋Š” "Hello"์•ผ.

๐Ÿ“ ์‹œ๋‚˜๋ฆฌ์˜ค: ์ดˆ๊ธฐ ๋ฌธ์„œ: "Hello"
์ฒ ์ˆ˜์˜ ์ž‘์—…: ์œ„์น˜ 5์— " World" ์‚ฝ์ž… โ†’ "Hello World"
์˜ํฌ์˜ ์ž‘์—…: ์œ„์น˜ 0์— "Hi " ์‚ฝ์ž… โ†’ "Hi Hello"

๋ฌธ์ œ๋Š” ์ด ๋‘ ์ž‘์—…์ด ๊ฑฐ์˜ ๋™์‹œ์— ๋ฐœ์ƒํ–ˆ๋‹ค๋Š” ๊ฑฐ์•ผ. ๋„คํŠธ์›Œํฌ ์ง€์—ฐ ๋•Œ๋ฌธ์— ์ฒ ์ˆ˜์˜ ์ž‘์—…์ด ์˜ํฌ์—๊ฒŒ ๋„์ฐฉํ•˜๊ณ , ์˜ํฌ์˜ ์ž‘์—…์ด ์ฒ ์ˆ˜์—๊ฒŒ ๋„์ฐฉํ•˜๋Š”๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ ค. ์ด๋•Œ ๋‹จ์ˆœํžˆ ์ž‘์—…์„ ๊ทธ๋Œ€๋กœ ์ ์šฉํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ?

โš ๏ธ ๋ฌธ์ œ ๋ฐœ์ƒ! ์ฒ ์ˆ˜ ์ž…์žฅ์—์„œ๋Š”: "Hello" โ†’ "Hello World" โ†’ "Hi Hello World" (์˜ํฌ ์ž‘์—… ์ ์šฉ)
์˜ํฌ ์ž…์žฅ์—์„œ๋Š”: "Hello" โ†’ "Hi Hello" โ†’ "Hi Hello World" (์ฒ ์ˆ˜ ์ž‘์—… ์ ์šฉ)

๊ฒฐ๊ณผ๋Š” ๊ฐ™์ง€๋งŒ, ๋งŒ์•ฝ ์œ„์น˜ ์ •๋ณด๊ฐ€ ์ž˜๋ชป๋˜๋ฉด ์™„์ „ํžˆ ๋‹ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ์–ด!

๋ฐ”๋กœ ์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ž‘์—… ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ํ•„์š”ํ•œ ๊ฑฐ์•ผ. ์ด ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๋™์‹œ์— ๋ฐœ์ƒํ•œ ์ž‘์—…๋“ค์„ ์ ์ ˆํžˆ ๋ณ€ํ™˜ํ•ด์„œ ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋™์ผํ•œ ์ตœ์ข… ์ƒํƒœ์— ๋„๋‹ฌํ•˜๋„๋ก ๋ณด์žฅํ•ด์ค˜. ๐ŸŽฏ

๐Ÿง  ์ž‘์—… ๋ณ€ํ™˜(OT) ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํ•ต์‹ฌ ๊ฐœ๋…

์ž‘์—… ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ 1989๋…„ Ellis์™€ Gibbs๊ฐ€ ์ฒ˜์Œ ์ œ์•ˆํ–ˆ์–ด. ํ•ต์‹ฌ ์•„์ด๋””์–ด๋Š” ๊ฐ„๋‹จํ•ด: "๋™์‹œ์— ๋ฐœ์ƒํ•œ ์ž‘์—…๋“ค์„ ์„œ๋กœ์˜ ์ปจํ…์ŠคํŠธ์— ๋งž๊ฒŒ ๋ณ€ํ™˜ํ•˜์ž!" ๐Ÿ”„

๐Ÿ“Œ OT์˜ 3๊ฐ€์ง€ ํ•ต์‹ฌ ์†์„ฑ
1๏ธโƒฃ ์ˆ˜๋ ด์„ฑ(Convergence) ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋™์ผํ•œ ์ž‘์—… ์ˆœ์„œ๋ฅผ ์ ์šฉํ•˜๋ฉด ๋™์ผํ•œ ์ตœ์ข… ์ƒํƒœ์— ๋„๋‹ฌํ•ด์•ผ ํ•ด. ์ด๊ฒŒ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์†์„ฑ์ด์•ผ!
2๏ธโƒฃ ์ธ๊ณผ์„ฑ ๋ณด์กด(Causality Preservation) ์ž‘์—… ๊ฐ„์˜ ์ธ๊ณผ ๊ด€๊ณ„๊ฐ€ ์œ ์ง€๋˜์–ด์•ผ ํ•ด. ์˜ˆ๋ฅผ ๋“ค์–ด, A ์ž‘์—…์ด B ์ž‘์—…๋ณด๋‹ค ๋จผ์ € ๋ฐœ์ƒํ–ˆ๋‹ค๋ฉด, ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ์—์„œ A๊ฐ€ B๋ณด๋‹ค ๋จผ์ € ์‹คํ–‰๋˜์–ด์•ผ ํ•ด.
3๏ธโƒฃ ์˜๋„ ๋ณด์กด(Intention Preservation) ์‚ฌ์šฉ์ž์˜ ์›๋ž˜ ์˜๋„๊ฐ€ ์ตœ์ข… ๊ฒฐ๊ณผ์— ๋ฐ˜์˜๋˜์–ด์•ผ ํ•ด. ์˜ˆ๋ฅผ ๋“ค์–ด, "Hello" ๋์— " World"๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค๋Š” ์˜๋„๋Š” ๋‹ค๋ฅธ ์ž‘์—…์ด ์žˆ์–ด๋„ ์œ ์ง€๋˜์–ด์•ผ ํ•ด.
๐Ÿ”ง ๊ธฐ๋ณธ ์ž‘์—… ํƒ€์ž…

๋Œ€๋ถ€๋ถ„์˜ OT ์‹œ์Šคํ…œ์€ ๋‘ ๊ฐ€์ง€ ๊ธฐ๋ณธ ์ž‘์—…์œผ๋กœ ์‹œ์ž‘ํ•ด:

์ž‘์—… ํƒ€์ž… ์„ค๋ช… ์˜ˆ์‹œ
Insert(pos, char) ํŠน์ • ์œ„์น˜์— ๋ฌธ์ž ์‚ฝ์ž… Insert(5, "!") โ†’ "Hello" โ†’ "Hello!"
Delete(pos, length) ํŠน์ • ์œ„์น˜์—์„œ ๋ฌธ์ž ์‚ญ์ œ Delete(0, 2) โ†’ "Hello" โ†’ "llo"

โš™๏ธ ๋ณ€ํ™˜ ํ•จ์ˆ˜์˜ ๊ตฌํ˜„ ์›๋ฆฌ

์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ๋ณ€ํ™˜ ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด์ž! ๋ณ€ํ™˜ ํ•จ์ˆ˜๋Š” ๋‘ ๊ฐœ์˜ ๋™์‹œ ์ž‘์—…์„ ๋ฐ›์•„์„œ, ํ•œ ์ž‘์—…์„ ๋‹ค๋ฅธ ์ž‘์—…์˜ ํšจ๊ณผ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ๋ณ€ํ™˜ํ•ด์ค˜. ์ˆ˜ํ•™์ ์œผ๋กœ ํ‘œํ˜„ํ•˜๋ฉด ์ด๋ ‡๊ฒŒ ๋ผ:

๋ณ€ํ™˜ ํ•จ์ˆ˜ ์ •์˜: Transform(Op1, Op2) โ†’ Op1'

Op1๊ณผ Op2๊ฐ€ ๋™์‹œ์— ๋ฐœ์ƒํ–ˆ์„ ๋•Œ, Op2์˜ ํšจ๊ณผ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ Op1์„ Op1'๋กœ ๋ณ€ํ™˜
๐ŸŽฏ Insert vs Insert ๋ณ€ํ™˜

๋‘ ๊ฐœ์˜ ์‚ฝ์ž… ์ž‘์—…์ด ๋™์‹œ์— ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•ด๋ณด์ž:

function transformInsertInsert(op1, op2) {
    // op1: Insert(pos1, char1)
    // op2: Insert(pos2, char2)
    
    if (op1.position < op2.position) {
        // op1์ด op2๋ณด๋‹ค ์•ž์—์„œ ๋ฐœ์ƒ
        // op2์˜ ์œ„์น˜๋ฅผ ์กฐ์ •ํ•  ํ•„์š” ์—†์Œ
        return op1;
    } else if (op1.position > op2.position) {
        // op1์ด op2๋ณด๋‹ค ๋’ค์—์„œ ๋ฐœ์ƒ
        // op2๊ฐ€ ์‚ฝ์ž…๋˜๋ฉด์„œ op1์˜ ์œ„์น˜๊ฐ€ ๋ฐ€๋ฆผ
        return Insert(op1.position + op2.length, op1.char);
    } else {
        // ๊ฐ™์€ ์œ„์น˜์—์„œ ๋ฐœ์ƒ
        // ํƒ€์ด๋ธŒ๋ ˆ์ด์ปค ๊ทœ์น™ ์ ์šฉ (์˜ˆ: ํด๋ผ์ด์–ธํŠธ ID ๋น„๊ต)
        if (op1.clientId < op2.clientId) {
            return op1;
        } else {
            return Insert(op1.position + op2.length, op1.char);
        }
    }
}
๐Ÿ’ก ์‹ค์ „ ํŒ: ๊ฐ™์€ ์œ„์น˜์—์„œ ๋™์‹œ ์‚ฝ์ž…์ด ๋ฐœ์ƒํ•˜๋ฉด ํด๋ผ์ด์–ธํŠธ ID๋‚˜ ํƒ€์ž„์Šคํƒฌํ”„๋กœ ์šฐ์„ ์ˆœ์œ„๋ฅผ ์ •ํ•ด์•ผ ํ•ด. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋™์ผํ•œ ์ˆœ์„œ๋กœ ์ž‘์—…์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์–ด!
โœ‚๏ธ Insert vs Delete ๋ณ€ํ™˜

์‚ฝ์ž…๊ณผ ์‚ญ์ œ๊ฐ€ ๋™์‹œ์— ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๊ฐ€์žฅ ๋ณต์žกํ•ด. ์—ฌ๋Ÿฌ ์ผ€์ด์Šค๋ฅผ ๊ณ ๋ คํ•ด์•ผ ํ•˜๊ฑฐ๋“ :

function transformInsertDelete(insert, delete) {
    // insert: Insert(pos, char)
    // delete: Delete(pos, length)
    
    if (insert.position <= delete.position) {
        // ์‚ฝ์ž…์ด ์‚ญ์ œ ๋ฒ”์œ„๋ณด๋‹ค ์•ž์—์„œ ๋ฐœ์ƒ
        return insert;
    } else if (insert.position >= delete.position + delete.length) {
        // ์‚ฝ์ž…์ด ์‚ญ์ œ ๋ฒ”์œ„๋ณด๋‹ค ๋’ค์—์„œ ๋ฐœ์ƒ
        // ์‚ญ์ œ๋œ ๋งŒํผ ์œ„์น˜๋ฅผ ์•ž์œผ๋กœ ๋‹น๊น€
        return Insert(insert.position - delete.length, insert.char);
    } else {
        // ์‚ฝ์ž…์ด ์‚ญ์ œ ๋ฒ”์œ„ ์•ˆ์—์„œ ๋ฐœ์ƒ
        // ์‚ญ์ œ ์‹œ์ž‘ ์œ„์น˜๋กœ ์ด๋™
        return Insert(delete.position, insert.char);
    }
}

function transformDeleteInsert(delete, insert) {
    // delete: Delete(pos, length)
    // insert: Insert(pos, char)
    
    if (delete.position >= insert.position + insert.length) {
        // ์‚ญ์ œ๊ฐ€ ์‚ฝ์ž…๋ณด๋‹ค ๋’ค์—์„œ ๋ฐœ์ƒ
        // ์‚ฝ์ž…๋œ ๋งŒํผ ์œ„์น˜๋ฅผ ๋’ค๋กœ ๋ฐ€๋ฆผ
        return Delete(delete.position + insert.length, delete.length);
    } else if (delete.position + delete.length <= insert.position) {
        // ์‚ญ์ œ๊ฐ€ ์‚ฝ์ž…๋ณด๋‹ค ์•ž์—์„œ ๋ฐœ์ƒ
        return delete;
    } else {
        // ์‚ญ์ œ ๋ฒ”์œ„์™€ ์‚ฝ์ž… ์œ„์น˜๊ฐ€ ๊ฒน์นจ
        // ์‚ฝ์ž…๋œ ๋งŒํผ ์‚ญ์ œ ๊ธธ์ด ์กฐ์ •
        return Delete(delete.position, delete.length + insert.length);
    }
}
๐Ÿ—‘๏ธ Delete vs Delete ๋ณ€ํ™˜

๋‘ ๊ฐœ์˜ ์‚ญ์ œ ์ž‘์—…์ด ๋™์‹œ์— ๋ฐœ์ƒํ•˜๋ฉด ๋ฒ”์œ„๊ฐ€ ๊ฒน์น  ์ˆ˜ ์žˆ์–ด. ์ด ๊ฒฝ์šฐ ์กฐ์‹ฌ์Šค๋Ÿฝ๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•ด:

function transformDeleteDelete(op1, op2) {
    // op1: Delete(pos1, len1)
    // op2: Delete(pos2, len2)
    
    if (op1.position + op1.length <= op2.position) {
        // op1์ด op2๋ณด๋‹ค ์™„์ „ํžˆ ์•ž์— ์žˆ์Œ
        return op1;
    } else if (op1.position >= op2.position + op2.length) {
        // op1์ด op2๋ณด๋‹ค ์™„์ „ํžˆ ๋’ค์— ์žˆ์Œ
        return Delete(op1.position - op2.length, op1.length);
    } else {
        // ๋ฒ”์œ„๊ฐ€ ๊ฒน์นจ - ๋ณต์žกํ•œ ์ผ€์ด์Šค!
        let newPos = Math.min(op1.position, op2.position);
        let end1 = op1.position + op1.length;
        let end2 = op2.position + op2.length;
        
        // ๊ฒน์น˜์ง€ ์•Š๋Š” ๋ถ€๋ถ„๋งŒ ์‚ญ์ œ
        if (op1.position < op2.position) {
            let newLength = op2.position - op1.position;
            return Delete(newPos, newLength);
        } else if (end1 > end2) {
            let newLength = end1 - end2;
            return Delete(op2.position, newLength);
        } else {
            // ์™„์ „ํžˆ ํฌํ•จ๋˜์–ด ์‚ญ์ œํ•  ๊ฒƒ์ด ์—†์Œ
            return null; // ์ž‘์—… ์ทจ์†Œ
        }
    }
}
๋ณ€ํ™˜ ํ•จ์ˆ˜ ๋™์ž‘ ํ๋ฆ„ ์ž‘์—… A Insert(5, "X") ์ž‘์—… B Insert(3, "Y") Transform(A, B) A' = Insert(6, "X") ์œ„์น˜๊ฐ€ 1 ์ฆ๊ฐ€

๐Ÿ—๏ธ ์‹ค์ „ ๊ตฌํ˜„: OT ์‹œ์Šคํ…œ ์•„ํ‚คํ…์ฒ˜

์ด๋ก ์€ ์ถฉ๋ถ„ํžˆ ๋ดค์œผ๋‹ˆ ์ด์ œ ์‹ค์ œ๋กœ ๋™์ž‘ํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๋งŒ๋“ค์–ด๋ณด์ž! ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ์‹œ์Šคํ…œ์€ ํฌ๊ฒŒ ์„ธ ๊ฐ€์ง€ ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌ์„ฑ๋ผ:

๐ŸŽจ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๊ตฌ์กฐ

ํด๋ผ์ด์–ธํŠธ๋Š” ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๋ฐ›์•„ ์ž‘์—…์„ ์ƒ์„ฑํ•˜๊ณ , ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ์ž‘์—…์„ ๋ณ€ํ™˜ํ•ด์„œ ์ ์šฉํ•ด์•ผ ํ•ด:

class OTClient {
    constructor(documentId, userId) {
        this.documentId = documentId;
        this.userId = userId;
        this.document = "";
        this.revision = 0;
        this.pendingOperations = [];
        this.buffer = [];
    }
    
    // ๋กœ์ปฌ ์ž‘์—… ์ƒ์„ฑ
    applyLocalOperation(operation) {
        // 1. ๋ฌธ์„œ์— ์ฆ‰์‹œ ์ ์šฉ (๋‚™๊ด€์  ์—…๋ฐ์ดํŠธ)
        this.document = this.applyOperation(this.document, operation);
        
        // 2. ์ž‘์—…์„ ๋Œ€๊ธฐ ํ์— ์ถ”๊ฐ€
        operation.revision = this.revision;
        this.pendingOperations.push(operation);
        
        // 3. ์„œ๋ฒ„๋กœ ์ „์†ก
        this.sendToServer(operation);
    }
    
    // ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์ž‘์—… ์ˆ˜์‹ 
    receiveRemoteOperation(operation) {
        // 1. ๋Œ€๊ธฐ ์ค‘์ธ ์ž‘์—…๋“ค์— ๋Œ€ํ•ด ๋ณ€ํ™˜
        let transformedOp = operation;
        
        for (let pending of this.pendingOperations) {
            transformedOp = this.transform(transformedOp, pending);
        }
        
        // 2. ๋ฒ„ํผ์— ์žˆ๋Š” ์ž‘์—…๋“ค์— ๋Œ€ํ•ด์„œ๋„ ๋ณ€ํ™˜
        for (let buffered of this.buffer) {
            transformedOp = this.transform(transformedOp, buffered);
        }
        
        // 3. ๋ณ€ํ™˜๋œ ์ž‘์—…์„ ๋ฌธ์„œ์— ์ ์šฉ
        this.document = this.applyOperation(this.document, transformedOp);
        this.revision++;
    }
    
    // ์„œ๋ฒ„ ํ™•์ธ ์ˆ˜์‹ 
    receiveAcknowledgement(operationId) {
        // ํ™•์ธ๋œ ์ž‘์—…์„ ๋Œ€๊ธฐ ํ์—์„œ ์ œ๊ฑฐ
        this.pendingOperations = this.pendingOperations.filter(
            op => op.id !== operationId
        );
    }
    
    // ์ž‘์—… ์ ์šฉ
    applyOperation(document, operation) {
        if (operation.type === 'insert') {
            return document.slice(0, operation.position) + 
                   operation.char + 
                   document.slice(operation.position);
        } else if (operation.type === 'delete') {
            return document.slice(0, operation.position) + 
                   document.slice(operation.position + operation.length);
        }
        return document;
    }
    
    // ๋ณ€ํ™˜ ํ•จ์ˆ˜ (์•ž์—์„œ ๊ตฌํ˜„ํ•œ ๋กœ์ง ์‚ฌ์šฉ)
    transform(op1, op2) {
        if (op1.type === 'insert' && op2.type === 'insert') {
            return this.transformInsertInsert(op1, op2);
        } else if (op1.type === 'insert' && op2.type === 'delete') {
            return this.transformInsertDelete(op1, op2);
        } else if (op1.type === 'delete' && op2.type === 'insert') {
            return this.transformDeleteInsert(op1, op2);
        } else if (op1.type === 'delete' && op2.type === 'delete') {
            return this.transformDeleteDelete(op1, op2);
        }
        return op1;
    }
}
๐Ÿ’ก ๋‚™๊ด€์  ์—…๋ฐ์ดํŠธ(Optimistic Update): ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•˜๋ฉด ์„œ๋ฒ„ ์‘๋‹ต์„ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ์ฆ‰์‹œ ํ™”๋ฉด์— ๋ฐ˜์˜ํ•ด. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ํ›จ์”ฌ ๋ถ€๋“œ๋Ÿฌ์›Œ์ ธ! ๋‚˜์ค‘์— ์„œ๋ฒ„์—์„œ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜๋ฉด ๊ทธ๋•Œ ์กฐ์ •ํ•˜๋ฉด ๋ผ.
๐Ÿ–ฅ๏ธ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๊ตฌ์กฐ

์„œ๋ฒ„๋Š” ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ์˜ ์ž‘์—…์„ ์กฐ์œจํ•˜๋Š” ์ค‘์•™ ํ—ˆ๋ธŒ ์—ญํ• ์„ ํ•ด. ์„œ๋ฒ„์˜ ์ฃผ์š” ์ฑ…์ž„์€:

class OTServer {
    constructor() {
        this.documents = new Map(); // documentId -> DocumentState
        this.clients = new Map();   // clientId -> WebSocket
    }
    
    // ๋ฌธ์„œ ์ƒํƒœ ๊ด€๋ฆฌ
    class DocumentState {
        constructor() {
            this.content = "";
            this.revision = 0;
            this.history = [];
        }
    }
    
    // ํด๋ผ์ด์–ธํŠธ ์ž‘์—… ์ˆ˜์‹ 
    handleOperation(clientId, operation) {
        const doc = this.documents.get(operation.documentId);
        
        // 1. ์ž‘์—… ๊ฒ€์ฆ
        if (operation.revision !== doc.revision) {
            // ๋ฆฌ๋น„์ „์ด ๋งž์ง€ ์•Š์œผ๋ฉด ์žฌ๋™๊ธฐํ™” ํ•„์š”
            this.requestResync(clientId, operation.documentId);
            return;
        }
        
        // 2. ์ž‘์—…์„ ๋ฌธ์„œ์— ์ ์šฉ
        doc.content = this.applyOperation(doc.content, operation);
        doc.revision++;
        doc.history.push(operation);
        
        // 3. ์ž‘์—…์„ ์ƒ์„ฑํ•œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ํ™•์ธ ์ „์†ก
        this.sendAcknowledgement(clientId, operation.id);
        
        // 4. ๋‹ค๋ฅธ ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ธŒ๋กœ๋“œ์บ์ŠคํŠธ
        this.broadcastOperation(operation, clientId);
    }
    
    // ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ๋“ค์—๊ฒŒ ๋ธŒ๋กœ๋“œ์บ์ŠคํŠธ
    broadcastOperation(operation, excludeClientId) {
        for (let [clientId, socket] of this.clients) {
            if (clientId !== excludeClientId) {
                socket.send(JSON.stringify({
                    type: 'operation',
                    operation: operation
                }));
            }
        }
    }
    
    // ์ƒˆ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ
    handleNewClient(clientId, documentId) {
        const doc = this.documents.get(documentId);
        
        // ํ˜„์žฌ ๋ฌธ์„œ ์ƒํƒœ ์ „์†ก
        this.clients.get(clientId).send(JSON.stringify({
            type: 'init',
            content: doc.content,
            revision: doc.revision
        }));
    }
    
    // ์žฌ๋™๊ธฐํ™” ์š”์ฒญ
    requestResync(clientId, documentId) {
        const doc = this.documents.get(documentId);
        
        this.clients.get(clientId).send(JSON.stringify({
            type: 'resync',
            content: doc.content,
            revision: doc.revision,
            history: doc.history
        }));
    }
}
โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: ์„œ๋ฒ„๋Š” ๋ฐ˜๋“œ์‹œ ์ž‘์—…์˜ ์ˆœ์„œ๋ฅผ ๋ณด์žฅํ•ด์•ผ ํ•ด. ์—ฌ๋Ÿฌ ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ๋™์‹œ์— ์ž‘์—…์ด ๋“ค์–ด์˜ค๋ฉด ํ์— ๋„ฃ์–ด์„œ ์ˆœ์ฐจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•ด. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ํด๋ผ์ด์–ธํŠธ๋“ค์˜ ์ƒํƒœ๊ฐ€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์–ด!

๐Ÿ”„ WebSocket์„ ํ™œ์šฉํ•œ ์‹ค์‹œ๊ฐ„ ํ†ต์‹ 

์‹ค์‹œ๊ฐ„ ํ˜‘์—…์„ ์œ„ํ•ด์„œ๋Š” ๋น ๋ฅธ ์–‘๋ฐฉํ–ฅ ํ†ต์‹ ์ด ํ•„์ˆ˜์•ผ. WebSocket์ด ์™„๋ฒฝํ•œ ์„ ํƒ์ด์ง€! HTTP ํด๋ง๋ณด๋‹ค ํ›จ์”ฌ ํšจ์œจ์ ์ด๊ฑฐ๋“ . ๐Ÿ˜Ž

๐Ÿ“ก WebSocket ํด๋ผ์ด์–ธํŠธ ๊ตฌํ˜„
class CollaborationClient {
    constructor(serverUrl, documentId, userId) {
        this.serverUrl = serverUrl;
        this.documentId = documentId;
        this.userId = userId;
        this.otClient = new OTClient(documentId, userId);
        this.ws = null;
        this.reconnectAttempts = 0;
        this.maxReconnectAttempts = 5;
    }
    
    connect() {
        this.ws = new WebSocket(this.serverUrl);
        
        this.ws.onopen = () => {
            console.log('WebSocket ์—ฐ๊ฒฐ ์„ฑ๊ณต! ๐ŸŽ‰');
            this.reconnectAttempts = 0;
            
            // ๋ฌธ์„œ ์ฐธ์—ฌ ์š”์ฒญ
            this.ws.send(JSON.stringify({
                type: 'join',
                documentId: this.documentId,
                userId: this.userId
            }));
        };
        
        this.ws.onmessage = (event) => {
            const message = JSON.parse(event.data);
            this.handleMessage(message);
        };
        
        this.ws.onerror = (error) => {
            console.error('WebSocket ์—๋Ÿฌ:', error);
        };
        
        this.ws.onclose = () => {
            console.log('WebSocket ์—ฐ๊ฒฐ ์ข…๋ฃŒ');
            this.attemptReconnect();
        };
    }
    
    handleMessage(message) {
        switch(message.type) {
            case 'init':
                // ์ดˆ๊ธฐ ๋ฌธ์„œ ์ƒํƒœ ์ˆ˜์‹ 
                this.otClient.document = message.content;
                this.otClient.revision = message.revision;
                this.renderDocument();
                break;
                
            case 'operation':
                // ์›๊ฒฉ ์ž‘์—… ์ˆ˜์‹ 
                this.otClient.receiveRemoteOperation(message.operation);
                this.renderDocument();
                break;
                
            case 'acknowledgement':
                // ์ž‘์—… ํ™•์ธ ์ˆ˜์‹ 
                this.otClient.receiveAcknowledgement(message.operationId);
                break;
                
            case 'resync':
                // ์žฌ๋™๊ธฐํ™”
                this.otClient.document = message.content;
                this.otClient.revision = message.revision;
                this.otClient.pendingOperations = [];
                this.renderDocument();
                break;
                
            case 'cursor':
                // ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์˜ ์ปค์„œ ์œ„์น˜
                this.updateRemoteCursor(message.userId, message.position);
                break;
        }
    }
    
    // ๋กœ์ปฌ ํŽธ์ง‘ ์ฒ˜๋ฆฌ
    handleLocalEdit(operation) {
        this.otClient.applyLocalOperation(operation);
        this.renderDocument();
        
        // ์„œ๋ฒ„๋กœ ์ „์†ก
        this.ws.send(JSON.stringify({
            type: 'operation',
            operation: operation
        }));
    }
    
    // ์žฌ์—ฐ๊ฒฐ ์‹œ๋„
    attemptReconnect() {
        if (this.reconnectAttempts < this.maxReconnectAttempts) {
            this.reconnectAttempts++;
            const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
            
            console.log(`${delay}ms ํ›„ ์žฌ์—ฐ๊ฒฐ ์‹œ๋„... (${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
            
            setTimeout(() => {
                this.connect();
            }, delay);
        } else {
            console.error('์ตœ๋Œ€ ์žฌ์—ฐ๊ฒฐ ์‹œ๋„ ํšŸ์ˆ˜ ์ดˆ๊ณผ');
            this.showReconnectError();
        }
    }
    
    // ๋ฌธ์„œ ๋ Œ๋”๋ง
    renderDocument() {
        const editor = document.getElementById('editor');
        editor.value = this.otClient.document;
    }
    
    // ์›๊ฒฉ ์ปค์„œ ์—…๋ฐ์ดํŠธ
    updateRemoteCursor(userId, position) {
        // ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์˜ ์ปค์„œ๋ฅผ ํ™”๋ฉด์— ํ‘œ์‹œ
        const cursorElement = document.getElementById(`cursor-${userId}`);
        if (cursorElement) {
            cursorElement.style.left = this.calculateCursorPosition(position);
        }
    }
}
๐Ÿ’ก ์žฌ์—ฐ๊ฒฐ ์ „๋žต: ๋„คํŠธ์›Œํฌ๊ฐ€ ๋ถˆ์•ˆ์ •ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ exponential backoff ๋ฐฉ์‹์œผ๋กœ ์žฌ์—ฐ๊ฒฐ์„ ์‹œ๋„ํ•ด. ์ฒ˜์Œ์—” 1์ดˆ ํ›„, ๊ทธ ๋‹ค์Œ์—” 2์ดˆ, 4์ดˆ, 8์ดˆ... ์ด๋Ÿฐ ์‹์œผ๋กœ ์ ์  ๊ฐ„๊ฒฉ์„ ๋Š˜๋ ค๊ฐ€๋Š” ๊ฑฐ์•ผ. ๋„ˆ๋ฌด ์ž์ฃผ ์‹œ๋„ํ•˜๋ฉด ์„œ๋ฒ„์— ๋ถ€๋‹ด์ด ๋˜๊ฑฐ๋“ !
๐ŸŽฏ ์—๋””ํ„ฐ UI ํ†ตํ•ฉ

์ด์ œ ์‹ค์ œ ํ…์ŠคํŠธ ์—๋””ํ„ฐ์™€ ํ†ตํ•ฉํ•ด๋ณด์ž. ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๊ฐ์ง€ํ•˜๊ณ  ์ž‘์—…์œผ๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•ด:

class CollaborativeEditor {
    constructor(editorElement, client) {
        this.editor = editorElement;
        this.client = client;
        this.lastContent = "";
        this.setupEventListeners();
    }
    
    setupEventListeners() {
        // ์ž…๋ ฅ ์ด๋ฒคํŠธ ๊ฐ์ง€
        this.editor.addEventListener('input', (e) => {
            this.handleInput(e);
        });
        
        // ์ปค์„œ ์ด๋™ ๊ฐ์ง€
        this.editor.addEventListener('selectionchange', () => {
            this.handleCursorMove();
        });
        
        // ๋ถ™์—ฌ๋„ฃ๊ธฐ ์ฒ˜๋ฆฌ
        this.editor.addEventListener('paste', (e) => {
            e.preventDefault();
            const text = e.clipboardData.getData('text/plain');
            this.handlePaste(text);
        });
    }
    
    handleInput(event) {
        const currentContent = this.editor.value;
        const operations = this.diffContent(this.lastContent, currentContent);
        
        // ๊ฐ ์ž‘์—…์„ ํด๋ผ์ด์–ธํŠธ๋กœ ์ „์†ก
        for (let op of operations) {
            this.client.handleLocalEdit(op);
        }
        
        this.lastContent = currentContent;
    }
    
    // ๋‚ด์šฉ ์ฐจ์ด ๊ณ„์‚ฐ (๊ฐ„๋‹จํ•œ diff ์•Œ๊ณ ๋ฆฌ์ฆ˜)
    diffContent(oldContent, newContent) {
        const operations = [];
        
        // ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•: ํ•œ ๊ธ€์ž์”ฉ ๋น„๊ต
        let i = 0;
        while (i < Math.min(oldContent.length, newContent.length) && 
               oldContent[i] === newContent[i]) {
            i++;
        }
        
        // ์‚ญ์ œ ๊ฐ์ง€
        if (oldContent.length > newContent.length) {
            const deleteLength = oldContent.length - newContent.length;
            operations.push({
                type: 'delete',
                position: i,
                length: deleteLength,
                id: this.generateOperationId(),
                userId: this.client.userId,
                timestamp: Date.now()
            });
        }
        
        // ์‚ฝ์ž… ๊ฐ์ง€
        if (newContent.length > oldContent.length) {
            const insertedText = newContent.slice(i, i + (newContent.length - oldContent.length));
            for (let char of insertedText) {
                operations.push({
                    type: 'insert',
                    position: i,
                    char: char,
                    id: this.generateOperationId(),
                    userId: this.client.userId,
                    timestamp: Date.now()
                });
                i++;
            }
        }
        
        return operations;
    }
    
    handleCursorMove() {
        const position = this.editor.selectionStart;
        
        // ์ปค์„œ ์œ„์น˜๋ฅผ ์„œ๋ฒ„๋กœ ์ „์†ก
        this.client.ws.send(JSON.stringify({
            type: 'cursor',
            position: position,
            userId: this.client.userId
        }));
    }
    
    handlePaste(text) {
        const position = this.editor.selectionStart;
        
        // ๋ถ™์—ฌ๋„ฃ๊ธฐ๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์‚ฝ์ž… ์ž‘์—…์œผ๋กœ ๋ถ„ํ• 
        for (let i = 0; i < text.length; i++) {
            const operation = {
                type: 'insert',
                position: position + i,
                char: text[i],
                id: this.generateOperationId(),
                userId: this.client.userId,
                timestamp: Date.now()
            };
            this.client.handleLocalEdit(operation);
        }
    }
    
    generateOperationId() {
        return `${this.client.userId}-${Date.now()}-${Math.random()}`;
    }
}

๐ŸŽจ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ: ๋ฆฌ์น˜ ํ…์ŠคํŠธ ํŽธ์ง‘ ์ง€์›

์ง€๊ธˆ๊นŒ์ง€๋Š” ํ‰๋ฌธ ํ…์ŠคํŠธ๋งŒ ๋‹ค๋ค˜๋Š”๋ฐ, ์‹ค์ œ ํ˜‘์—… ๋„๊ตฌ๋Š” ๋ณผ๋“œ, ์ดํƒค๋ฆญ, ์ƒ‰์ƒ ๊ฐ™์€ ์„œ์‹๋„ ์ง€์›ํ•ด์•ผ ํ•˜์ง€? ์ด๊ฑธ ์œ„ํ•ด ์ž‘์—… ํƒ€์ž…์„ ํ™•์žฅํ•ด๋ณด์ž! โœจ

๐Ÿ“ ์„œ์‹ ์ž‘์—… ์ •์˜
// ์„œ์‹ ์ž‘์—… ํƒ€์ž…
class FormatOperation {
    constructor(start, end, format, value) {
        this.type = 'format';
        this.start = start;
        this.end = end;
        this.format = format;  // 'bold', 'italic', 'color', 'fontSize' ๋“ฑ
        this.value = value;    // true/false ๋˜๋Š” ์ƒ‰์ƒ๊ฐ’, ํฌ๊ธฐ๊ฐ’ ๋“ฑ
        this.id = generateId();
    }
}

// ์„œ์‹ ๋ณ€ํ™˜ ํ•จ์ˆ˜
function transformFormatInsert(formatOp, insertOp) {
    if (insertOp.position < formatOp.start) {
        // ์‚ฝ์ž…์ด ์„œ์‹ ๋ฒ”์œ„๋ณด๋‹ค ์•ž์—์„œ ๋ฐœ์ƒ
        return new FormatOperation(
            formatOp.start + 1,
            formatOp.end + 1,
            formatOp.format,
            formatOp.value
        );
    } else if (insertOp.position > formatOp.end) {
        // ์‚ฝ์ž…์ด ์„œ์‹ ๋ฒ”์œ„๋ณด๋‹ค ๋’ค์—์„œ ๋ฐœ์ƒ
        return formatOp;
    } else {
        // ์‚ฝ์ž…์ด ์„œ์‹ ๋ฒ”์œ„ ์•ˆ์—์„œ ๋ฐœ์ƒ
        return new FormatOperation(
            formatOp.start,
            formatOp.end + 1,  // ๋ฒ”์œ„ ํ™•์žฅ
            formatOp.format,
            formatOp.value
        );
    }
}

function transformFormatDelete(formatOp, deleteOp) {
    const deleteEnd = deleteOp.position + deleteOp.length;
    
    if (deleteEnd <= formatOp.start) {
        // ์‚ญ์ œ๊ฐ€ ์„œ์‹ ๋ฒ”์œ„๋ณด๋‹ค ์•ž์—์„œ ๋ฐœ์ƒ
        return new FormatOperation(
            formatOp.start - deleteOp.length,
            formatOp.end - deleteOp.length,
            formatOp.format,
            formatOp.value
        );
    } else if (deleteOp.position >= formatOp.end) {
        // ์‚ญ์ œ๊ฐ€ ์„œ์‹ ๋ฒ”์œ„๋ณด๋‹ค ๋’ค์—์„œ ๋ฐœ์ƒ
        return formatOp;
    } else {
        // ์‚ญ์ œ๊ฐ€ ์„œ์‹ ๋ฒ”์œ„์™€ ๊ฒน์นจ
        const newStart = Math.min(formatOp.start, deleteOp.position);
        const newEnd = Math.max(
            newStart,
            formatOp.end - Math.min(deleteOp.length, formatOp.end - deleteOp.position)
        );
        
        if (newEnd <= newStart) {
            return null; // ์„œ์‹ ๋ฒ”์œ„๊ฐ€ ์™„์ „ํžˆ ์‚ญ์ œ๋จ
        }
        
        return new FormatOperation(
            newStart,
            newEnd,
            formatOp.format,
            formatOp.value
        );
    }
}
๐ŸŽจ ๋ฌธ์„œ ๋ชจ๋ธ ํ™•์žฅ

์„œ์‹์„ ์ง€์›ํ•˜๋ ค๋ฉด ๋ฌธ์„œ๋ฅผ ๋‹จ์ˆœ ๋ฌธ์ž์—ด์ด ์•„๋‹Œ ๊ตฌ์กฐํ™”๋œ ๋ฐ์ดํ„ฐ๋กœ ๊ด€๋ฆฌํ•ด์•ผ ํ•ด:

class RichTextDocument {
    constructor() {
        this.text = "";
        this.formats = [];  // ์„œ์‹ ์ •๋ณด ๋ฐฐ์—ด
    }
    
    // ์„œ์‹ ์ •๋ณด ๊ตฌ์กฐ
    class FormatSpan {
        constructor(start, end, attributes) {
            this.start = start;
            this.end = end;
            this.attributes = attributes;  // {bold: true, color: '#ff0000', ...}
        }
    }
    
    // ์„œ์‹ ์ ์šฉ
    applyFormat(start, end, format, value) {
        // ๊ธฐ์กด ์„œ์‹๊ณผ ๋ณ‘ํ•ฉ
        const newSpan = new FormatSpan(start, end, {[format]: value});
        this.formats.push(newSpan);
        this.mergeOverlappingFormats();
    }
    
    // ๊ฒน์น˜๋Š” ์„œ์‹ ๋ณ‘ํ•ฉ
    mergeOverlappingFormats() {
        // ์œ„์น˜ ์ˆœ์œผ๋กœ ์ •๋ ฌ
        this.formats.sort((a, b) => a.start - b.start);
        
        const merged = [];
        let current = null;
        
        for (let span of this.formats) {
            if (!current) {
                current = span;
                continue;
            }
            
            if (span.start <= current.end) {
                // ๊ฒน์นจ - ๋ณ‘ํ•ฉ
                current.end = Math.max(current.end, span.end);
                current.attributes = {...current.attributes, ...span.attributes};
            } else {
                merged.push(current);
                current = span;
            }
        }
        
        if (current) {
            merged.push(current);
        }
        
        this.formats = merged;
    }
    
    // HTML๋กœ ๋ Œ๋”๋ง
    toHTML() {
        let html = "";
        let lastPos = 0;
        
        for (let span of this.formats) {
            // ์„œ์‹ ์—†๋Š” ๋ถ€๋ถ„
            if (span.start > lastPos) {
                html += this.escapeHTML(this.text.slice(lastPos, span.start));
            }
            
            // ์„œ์‹ ์žˆ๋Š” ๋ถ€๋ถ„
            const styles = this.attributesToCSS(span.attributes);
            html += `<span style="${styles}">`;
            html += this.escapeHTML(this.text.slice(span.start, span.end));
            html += '</span>';
            
            lastPos = span.end;
        }
        
        // ๋‚˜๋จธ์ง€ ๋ถ€๋ถ„
        if (lastPos < this.text.length) {
            html += this.escapeHTML(this.text.slice(lastPos));
        }
        
        return html;
    }
    
    attributesToCSS(attributes) {
        const css = [];
        
        if (attributes.bold) css.push('font-weight: bold');
        if (attributes.italic) css.push('font-style: italic');
        if (attributes.underline) css.push('text-decoration: underline');
        if (attributes.color) css.push(`color: ${attributes.color}`);
        if (attributes.fontSize) css.push(`font-size: ${attributes.fontSize}px`);
        if (attributes.backgroundColor) css.push(`background-color: ${attributes.backgroundColor}`);
        
        return css.join('; ');
    }
    
    escapeHTML(text) {
        return text
            .replace(/&/g, '&')
            .replace(/</g, '<')
            .replace(/>/g, '>')
            .replace(/"/g, '"')
            .replace(/'/g, ''');
    }
}

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ „๋žต

์‹ค์‹œ๊ฐ„ ํ˜‘์—… ์‹œ์Šคํ…œ์€ ์„ฑ๋Šฅ์ด ์ƒ๋ช…์ด์•ผ! ์‚ฌ์šฉ์ž๊ฐ€ ํƒ€์ดํ•‘ํ•  ๋•Œ๋งˆ๋‹ค ์ž‘์—…์ด ์ƒ์„ฑ๋˜๊ณ  ์ „์†ก๋˜๋‹ˆ๊นŒ ์ตœ์ ํ™”๊ฐ€ ํ•„์ˆ˜์ง€. ๋ช‡ ๊ฐ€์ง€ ํ•ต์‹ฌ ์ „๋žต์„ ์•Œ์•„๋ณด์ž! ๐Ÿš€

๐ŸŽฏ ์ž‘์—… ๋ฐฐ์นญ(Operation Batching)

์‚ฌ์šฉ์ž๊ฐ€ ๋น ๋ฅด๊ฒŒ ํƒ€์ดํ•‘ํ•˜๋ฉด ์ž‘์—…์ด ํญ๋ฐœ์ ์œผ๋กœ ์ฆ๊ฐ€ํ•ด. ์ด๊ฑธ ๋ฌถ์–ด์„œ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋„คํŠธ์›Œํฌ ๋ถ€ํ•˜๋ฅผ ํฌ๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ์–ด:

class OperationBatcher {
    constructor(client, batchInterval = 50) {
        this.client = client;
        this.batchInterval = batchInterval;
        this.pendingBatch = [];
        this.batchTimer = null;
    }
    
    addOperation(operation) {
        this.pendingBatch.push(operation);
        
        // ํƒ€์ด๋จธ๊ฐ€ ์—†์œผ๋ฉด ์‹œ์ž‘
        if (!this.batchTimer) {
            this.batchTimer = setTimeout(() => {
                this.flush();
            }, this.batchInterval);
        }
    }
    
    flush() {
        if (this.pendingBatch.length === 0) return;
        
        // ์—ฐ์†๋œ ์‚ฝ์ž… ์ž‘์—…์„ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๊ธฐ
        const optimized = this.optimizeBatch(this.pendingBatch);
        
        // ์„œ๋ฒ„๋กœ ์ „์†ก
        this.client.ws.send(JSON.stringify({
            type: 'batch',
            operations: optimized
        }));
        
        this.pendingBatch = [];
        this.batchTimer = null;
    }
    
    optimizeBatch(operations) {
        const optimized = [];
        let currentInsert = null;
        
        for (let op of operations) {
            if (op.type === 'insert') {
                if (currentInsert && 
                    op.position === currentInsert.position + currentInsert.text.length) {
                    // ์—ฐ์†๋œ ์‚ฝ์ž… - ํ•ฉ์น˜๊ธฐ
                    currentInsert.text += op.char;
                } else {
                    if (currentInsert) {
                        optimized.push(currentInsert);
                    }
                    currentInsert = {
                        type: 'insert',
                        position: op.position,
                        text: op.char,
                        id: op.id,
                        userId: op.userId
                    };
                }
            } else {
                if (currentInsert) {
                    optimized.push(currentInsert);
                    currentInsert = null;
                }
                optimized.push(op);
            }
        }
        
        if (currentInsert) {
            optimized.push(currentInsert);
        }
        
        return optimized;
    }
    
    // ์ฆ‰์‹œ ์ „์†ก (์ค‘์š”ํ•œ ์ž‘์—…์˜ ๊ฒฝ์šฐ)
    flushImmediate() {
        if (this.batchTimer) {
            clearTimeout(this.batchTimer);
            this.batchTimer = null;
        }
        this.flush();
    }
}
๐Ÿ’ก ๋ฐฐ์นญ ์ „๋žต: 50ms ์ •๋„์˜ ์งง์€ ๊ฐ„๊ฒฉ์œผ๋กœ ๋ฐฐ์นญํ•˜๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์œผ๋ฉด์„œ๋„ ๋„คํŠธ์›Œํฌ ํŠธ๋ž˜ํ”ฝ์„ ํฌ๊ฒŒ ์ค„์ผ ์ˆ˜ ์žˆ์–ด. ํ•˜์ง€๋งŒ Enter ํ‚ค๋‚˜ ์ €์žฅ ๊ฐ™์€ ์ค‘์š”ํ•œ ์ด๋ฒคํŠธ๋Š” ์ฆ‰์‹œ ์ „์†กํ•˜๋Š” ๊ฒŒ ์ข‹์•„!
๐Ÿ—œ๏ธ ๋ธํƒ€ ์••์ถ•(Delta Compression)

ํฐ ๋ฌธ์„œ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ๋Š” ์ „์ฒด ๋‚ด์šฉ ๋Œ€์‹  ๋ณ€๊ฒฝ์‚ฌํ•ญ๋งŒ ์ „์†กํ•˜๋Š” ๊ฒŒ ํšจ์œจ์ ์ด์•ผ:

class DeltaCompressor {
    // Myers diff ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๊ฐ„๋‹จํ•œ ๊ตฌํ˜„
    static computeDiff(oldText, newText) {
        const n = oldText.length;
        const m = newText.length;
        const max = n + m;
        
        const v = new Array(2 * max + 1);
        const trace = [];
        
        for (let d = 0; d <= max; d++) {
            trace.push([...v]);
            
            for (let k = -d; k <= d; k += 2) {
                let x;
                if (k === -d || (k !== d && v[k - 1] < v[k + 1])) {
                    x = v[k + 1];
                } else {
                    x = v[k - 1] + 1;
                }
                
                let y = x - k;
                
                while (x < n && y < m && oldText[x] === newText[y]) {
                    x++;
                    y++;
                }
                
                v[k] = x;
                
                if (x >= n && y >= m) {
                    return this.backtrack(trace, oldText, newText, d);
                }
            }
        }
        
        return [];
    }
    
    static backtrack(trace, oldText, newText, d) {
        const operations = [];
        let x = oldText.length;
        let y = newText.length;
        
        for (let i = d; i >= 0; i--) {
            const v = trace[i];
            const k = x - y;
            
            let prevK;
            if (k === -i || (k !== i && v[k - 1] < v[k + 1])) {
                prevK = k + 1;
            } else {
                prevK = k - 1;
            }
            
            const prevX = v[prevK];
            const prevY = prevX - prevK;
            
            while (x > prevX && y > prevY) {
                x--;
                y--;
                // ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„ - ์ž‘์—… ์—†์Œ
            }
            
            if (i > 0) {
                if (x === prevX) {
                    // ์‚ฝ์ž…
                    operations.unshift({
                        type: 'insert',
                        position: x,
                        char: newText[y - 1]
                    });
                    y--;
                } else {
                    // ์‚ญ์ œ
                    operations.unshift({
                        type: 'delete',
                        position: x - 1,
                        length: 1
                    });
                    x--;
                }
            }
        }
        
        return operations;
    }
    
    // ๋ธํƒ€๋ฅผ ๋ฐ”์ด๋„ˆ๋ฆฌ๋กœ ์••์ถ•
    static compressDelta(operations) {
        const buffer = [];
        
        for (let op of operations) {
            if (op.type === 'insert') {
                buffer.push(0x01);  // ์‚ฝ์ž… ๋งˆ์ปค
                this.writeVarInt(buffer, op.position);
                this.writeString(buffer, op.char);
            } else if (op.type === 'delete') {
                buffer.push(0x02);  // ์‚ญ์ œ ๋งˆ์ปค
                this.writeVarInt(buffer, op.position);
                this.writeVarInt(buffer, op.length);
            }
        }
        
        return new Uint8Array(buffer);
    }
    
    static writeVarInt(buffer, value) {
        while (value > 127) {
            buffer.push((value & 0x7F) | 0x80);
            value >>= 7;
        }
        buffer.push(value & 0x7F);
    }
    
    static writeString(buffer, str) {
        const bytes = new TextEncoder().encode(str);
        this.writeVarInt(buffer, bytes.length);
        buffer.push(...bytes);
    }
}
๐Ÿ’พ ๋ฉ”๋ชจ๋ฆฌ ์ตœ์ ํ™”

์ž‘์—… ํžˆ์Šคํ† ๋ฆฌ๊ฐ€ ๊ณ„์† ์Œ“์ด๋ฉด ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•ด์งˆ ์ˆ˜ ์žˆ์–ด. ์ฃผ๊ธฐ์ ์œผ๋กœ ์ •๋ฆฌํ•ด์•ผ ํ•ด:

class HistoryManager {
    constructor(maxHistorySize = 1000) {
        this.history = [];
        this.maxHistorySize = maxHistorySize;
        this.snapshots = [];
        this.snapshotInterval = 100;  // 100๊ฐœ ์ž‘์—…๋งˆ๋‹ค ์Šค๋ƒ…์ƒท
    }
    
    addOperation(operation) {
        this.history.push(operation);
        
        // ์Šค๋ƒ…์ƒท ์ƒ์„ฑ ์‹œ์  ์ฒดํฌ
        if (this.history.length % this.snapshotInterval === 0) {
            this.createSnapshot();
        }
        
        // ํžˆ์Šคํ† ๋ฆฌ ํฌ๊ธฐ ์ œํ•œ
        if (this.history.length > this.maxHistorySize) {
            this.compactHistory();
        }
    }
    
    createSnapshot() {
        const snapshot = {
            revision: this.history.length,
            document: this.getCurrentDocument(),
            timestamp: Date.now()
        };
        
        this.snapshots.push(snapshot);
        
        // ์˜ค๋ž˜๋œ ์Šค๋ƒ…์ƒท ์ œ๊ฑฐ (์ตœ๊ทผ 5๊ฐœ๋งŒ ์œ ์ง€)
        if (this.snapshots.length > 5) {
            this.snapshots.shift();
        }
    }
    
    compactHistory() {
        // ๊ฐ€์žฅ ์ตœ๊ทผ ์Šค๋ƒ…์ƒท ์ด์ „์˜ ํžˆ์Šคํ† ๋ฆฌ ์ œ๊ฑฐ
        if (this.snapshots.length > 0) {
            const lastSnapshot = this.snapshots[this.snapshots.length - 1];
            const cutoff = lastSnapshot.revision;
            
            this.history = this.history.slice(cutoff);
            
            console.log(`ํžˆ์Šคํ† ๋ฆฌ ์••์ถ•: ${cutoff}๊ฐœ ์ž‘์—… ์ œ๊ฑฐ`);
        }
    }
    
    // ํŠน์ • ์‹œ์ ์œผ๋กœ ๋ณต์›
    restoreToRevision(targetRevision) {
        // ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์Šค๋ƒ…์ƒท ์ฐพ๊ธฐ
        let baseSnapshot = null;
        for (let snapshot of this.snapshots) {
            if (snapshot.revision <= targetRevision) {
                baseSnapshot = snapshot;
            } else {
                break;
            }
        }
        
        if (!baseSnapshot) {
            // ์Šค๋ƒ…์ƒท์ด ์—†์œผ๋ฉด ์ฒ˜์Œ๋ถ€ํ„ฐ ์žฌ์ƒ
            return this.replayOperations(0, targetRevision);
        }
        
        // ์Šค๋ƒ…์ƒท๋ถ€ํ„ฐ ์žฌ์ƒ
        let document = baseSnapshot.document;
        const operations = this.history.slice(
            baseSnapshot.revision,
            targetRevision
        );
        
        for (let op of operations) {
            document = this.applyOperation(document, op);
        }
        
        return document;
    }
}
์„ฑ๋Šฅ ์ตœ์ ํ™” ํŒŒ์ดํ”„๋ผ์ธ ์ž‘์—… ๋ฐฐ์นญ 50ms ๊ฐ„๊ฒฉ ๋ธํƒ€ ์••์ถ• ํฌ๊ธฐ 60% ๊ฐ์†Œ ์ „์†ก WebSocket ์ ์šฉ ๋ณ€ํ™˜ ํ›„ ๋ Œ๋”๋ง ํ‰๊ท  ์ฒ˜๋ฆฌ ์‹œ๊ฐ„: 15ms ๋„คํŠธ์›Œํฌ ๋Œ€์—ญํญ: 70% ์ ˆ๊ฐ

๐Ÿ”’ ์ถฉ๋Œ ํ•ด๊ฒฐ๊ณผ ์ผ๊ด€์„ฑ ๋ณด์žฅ

์•„๋ฌด๋ฆฌ ์ข‹์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ผ๋„ ์˜ˆ์™ธ ์ƒํ™ฉ์€ ๋ฐœ์ƒํ•ด. ๋„คํŠธ์›Œํฌ ํŒŒํ‹ฐ์…˜, ์„œ๋ฒ„ ์žฅ์• , ํด๋ผ์ด์–ธํŠธ ๋ฒ„๊ทธ ๋“ฑ๋“ฑ... ์ด๋Ÿฐ ์ƒํ™ฉ์—์„œ๋„ ๋ฐ์ดํ„ฐ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž! ๐Ÿ›ก๏ธ

๐ŸŽฏ ๋ฒกํ„ฐ ํด๋ก(Vector Clock) ํ™œ์šฉ

์ž‘์—…์˜ ์ธ๊ณผ ๊ด€๊ณ„๋ฅผ ์ถ”์ ํ•˜๊ธฐ ์œ„ํ•ด ๋ฒกํ„ฐ ํด๋ก์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด:

class VectorClock {
    constructor(clientId) {
        this.clientId = clientId;
        this.clock = {};
    }
    
    // ๋กœ์ปฌ ์ด๋ฒคํŠธ ๋ฐœ์ƒ
    tick() {
        if (!this.clock[this.clientId]) {
            this.clock[this.clientId] = 0;
        }
        this.clock[this.clientId]++;
        return this.getCopy();
    }
    
    // ์›๊ฒฉ ์ด๋ฒคํŠธ ์ˆ˜์‹ 
    update(remoteClock) {
        for (let clientId in remoteClock) {
            if (!this.clock[clientId] || this.clock[clientId] < remoteClock[clientId]) {
                this.clock[clientId] = remoteClock[clientId];
            }
        }
        this.tick();
    }
    
    // ์ธ๊ณผ ๊ด€๊ณ„ ๋น„๊ต
    happensBefore(otherClock) {
        let allLessOrEqual = true;
        let someLess = false;
        
        for (let clientId in this.clock) {
            if (!otherClock[clientId] || this.clock[clientId] > otherClock[clientId]) {
                allLessOrEqual = false;
                break;
            }
            if (this.clock[clientId] < otherClock[clientId]) {
                someLess = true;
            }
        }
        
        return allLessOrEqual && someLess;
    }
    
    // ๋™์‹œ ๋ฐœ์ƒ ์—ฌ๋ถ€
    isConcurrent(otherClock) {
        return !this.happensBefore(otherClock) && 
               !this.happensAfter(otherClock);
    }
    
    happensAfter(otherClock) {
        return new VectorClock().update(otherClock).happensBefore(this.clock);
    }
    
    getCopy() {
        return {...this.clock};
    }
}

// ์ž‘์—…์— ๋ฒกํ„ฐ ํด๋ก ์ถ”๊ฐ€
class TimestampedOperation {
    constructor(operation, vectorClock) {
        this.operation = operation;
        this.vectorClock = vectorClock;
        this.id = generateId();
    }
}

// OT ํด๋ผ์ด์–ธํŠธ์— ๋ฒกํ„ฐ ํด๋ก ํ†ตํ•ฉ
class OTClientWithVC extends OTClient {
    constructor(documentId, userId) {
        super(documentId, userId);
        this.vectorClock = new VectorClock(userId);
    }
    
    applyLocalOperation(operation) {
        // ๋ฒกํ„ฐ ํด๋ก ์ฆ๊ฐ€
        const clock = this.vectorClock.tick();
        
        // ํƒ€์ž„์Šคํƒฌํ”„ ์ถ”๊ฐ€
        const timestamped = new TimestampedOperation(operation, clock);
        
        // ๊ธฐ์กด ๋กœ์ง ์‹คํ–‰
        super.applyLocalOperation(timestamped);
    }
    
    receiveRemoteOperation(timestampedOp) {
        // ๋ฒกํ„ฐ ํด๋ก ์—…๋ฐ์ดํŠธ
        this.vectorClock.update(timestampedOp.vectorClock);
        
        // ์ธ๊ณผ ๊ด€๊ณ„ ํ™•์ธ
        if (this.checkCausality(timestampedOp)) {
            super.receiveRemoteOperation(timestampedOp.operation);
        } else {
            // ์ธ๊ณผ์„ฑ ์œ„๋ฐ˜ - ๋ฒ„ํผ์— ์ €์žฅ
            this.bufferOperation(timestampedOp);
        }
    }
    
    checkCausality(timestampedOp) {
        // ๋ชจ๋“  ์˜์กด์„ฑ์ด ์ถฉ์กฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
        for (let clientId in timestampedOp.vectorClock) {
            if (clientId === this.userId) continue;
            
            const required = timestampedOp.vectorClock[clientId];
            const current = this.vectorClock.clock[clientId] || 0;
            
            if (current < required - 1) {
                return false;  // ์˜์กด์„ฑ ๋ฏธ์ถฉ์กฑ
            }
        }
        return true;
    }
    
    bufferOperation(timestampedOp) {
        this.buffer.push(timestampedOp);
        
        // ๋ฒ„ํผ ์ •๋ ฌ (๋ฒกํ„ฐ ํด๋ก ์ˆœ์„œ)
        this.buffer.sort((a, b) => {
            if (a.vectorClock.happensBefore(b.vectorClock)) return -1;
            if (b.vectorClock.happensBefore(a.vectorClock)) return 1;
            return 0;
        });
        
        // ์ ์šฉ ๊ฐ€๋Šฅํ•œ ์ž‘์—… ์ฒ˜๋ฆฌ
        this.processBuffer();
    }
    
    processBuffer() {
        let processed = 0;
        
        for (let timestampedOp of this.buffer) {
            if (this.checkCausality(timestampedOp)) {
                this.receiveRemoteOperation(timestampedOp);
                processed++;
            } else {
                break;  // ์ˆœ์„œ๋Œ€๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋ฏ€๋กœ ์ค‘๋‹จ
            }
        }
        
        this.buffer = this.buffer.slice(processed);
    }
}
๐Ÿ”„ ์ถฉ๋Œ ๊ฐ์ง€ ๋ฐ ํ•ด๊ฒฐ

๋•Œ๋กœ๋Š” ์ž๋™ ๋ณ€ํ™˜์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์—†๋Š” ์˜๋ฏธ์  ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด. ์˜ˆ๋ฅผ ๋“ค์–ด, ํ•œ ์‚ฌ์šฉ์ž๊ฐ€ ๋ฌธ๋‹จ์„ ์‚ญ์ œํ•˜๊ณ  ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ™์€ ๋ฌธ๋‹จ์„ ํŽธ์ง‘ํ•˜๋Š” ๊ฒฝ์šฐ:

class ConflictDetector {
    constructor() {
        this.conflicts = [];
    }
    
    // ์ถฉ๋Œ ๊ฐ์ง€
    detectConflict(op1, op2) {
        // ์˜๋ฏธ์  ์ถฉ๋Œ ์ฒดํฌ
        if (this.isSemanticConflict(op1, op2)) {
            const conflict = {
                id: generateId(),
                operations: [op1, op2],
                type: this.classifyConflict(op1, op2),
                timestamp: Date.now(),
                resolved: false
            };
            
            this.conflicts.push(conflict);
            return conflict;
        }
        
        return null;
    }
    
    isSemanticConflict(op1, op2) {
        // ์‚ญ์ œ์™€ ํŽธ์ง‘์ด ๊ฐ™์€ ์˜์—ญ์—์„œ ๋ฐœ์ƒ
        if (op1.type === 'delete' && op2.type === 'insert') {
            const deleteEnd = op1.position + op1.length;
            if (op2.position >= op1.position && op2.position < deleteEnd) {
                return true;
            }
        }
        
        // ์„œ๋กœ ๋‹ค๋ฅธ ์„œ์‹์„ ๊ฐ™์€ ์˜์—ญ์— ์ ์šฉ
        if (op1.type === 'format' && op2.type === 'format') {
            if (this.rangesOverlap(op1, op2) && op1.format === op2.format) {
                return true;
            }
        }
        
        return false;
    }
    
    classifyConflict(op1, op2) {
        if (op1.type === 'delete' && op2.type === 'insert') {
            return 'delete-edit';
        }
        if (op1.type === 'format' && op2.type === 'format') {
            return 'format-format';
        }
        return 'unknown';
    }
    
    // ์ถฉ๋Œ ํ•ด๊ฒฐ ์ „๋žต
    resolveConflict(conflict, strategy = 'last-write-wins') {
        switch(strategy) {
            case 'last-write-wins':
                return this.resolveByTimestamp(conflict);
            
            case 'user-priority':
                return this.resolveByUserPriority(conflict);
            
            case 'manual':
                return this.requestManualResolution(conflict);
            
            default:
                return this.resolveByTimestamp(conflict);
        }
    }
    
    resolveByTimestamp(conflict) {
        // ๊ฐ€์žฅ ์ตœ๊ทผ ์ž‘์—…์„ ์šฐ์„ 
        const sorted = conflict.operations.sort((a, b) => 
            b.timestamp - a.timestamp
        );
        
        conflict.resolved = true;
        conflict.winner = sorted[0];
        
        return sorted[0];
    }
    
    resolveByUserPriority(conflict) {
        // ์‚ฌ์šฉ์ž ๊ถŒํ•œ์— ๋”ฐ๋ผ ํ•ด๊ฒฐ
        const sorted = conflict.operations.sort((a, b) => 
            this.getUserPriority(b.userId) - this.getUserPriority(a.userId)
        );
        
        conflict.resolved = true;
        conflict.winner = sorted[0];
        
        return sorted[0];
    }
    
    requestManualResolution(conflict) {
        // UI์— ์ถฉ๋Œ ์•Œ๋ฆผ ํ‘œ์‹œ
        this.showConflictDialog(conflict);
        return null;  // ์‚ฌ์šฉ์ž ์„ ํƒ ๋Œ€๊ธฐ
    }
    
    getUserPriority(userId) {
        // ์‚ฌ์šฉ์ž ์—ญํ• ์— ๋”ฐ๋ฅธ ์šฐ์„ ์ˆœ์œ„
        const priorities = {
            'admin': 100,
            'editor': 50,
            'viewer': 10
        };
        
        const role = this.getUserRole(userId);
        return priorities[role] || 0;
    }
    
    rangesOverlap(op1, op2) {
        return !(op1.end <= op2.start || op2.end <= op1.start);
    }
}
โš ๏ธ ์ถฉ๋Œ ํ•ด๊ฒฐ ์ฃผ์˜์‚ฌํ•ญ: ์ž๋™ ์ถฉ๋Œ ํ•ด๊ฒฐ์€ ํŽธ๋ฆฌํ•˜์ง€๋งŒ ๋•Œ๋กœ๋Š” ์‚ฌ์šฉ์ž์˜ ์˜๋„์™€ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์–ด. ์ค‘์š”ํ•œ ์ถฉ๋Œ์€ ์‚ฌ์šฉ์ž์—๊ฒŒ ์•Œ๋ฆฌ๊ณ  ์ง์ ‘ ์„ ํƒํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒŒ ์ข‹์•„. ํŠนํžˆ ๋ฌธ์„œ ์ž‘์„ฑ์ด๋‚˜ ์ฝ”๋“œ ํŽธ์ง‘ ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š” ๋”์šฑ ๊ทธ๋ž˜!

๐ŸŒ ์‹ค์ „ ์˜ˆ์ œ: ๊ฐ„๋‹จํ•œ ํ˜‘์—… ์—๋””ํ„ฐ ๋งŒ๋“ค๊ธฐ

์ด์ œ ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ชจ๋‘ ํ•ฉ์ณ์„œ ์‹ค์ œ๋กœ ๋™์ž‘ํ•˜๋Š” ํ˜‘์—… ์—๋””ํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ์™„์ „ํ•œ ์ฝ”๋“œ๋ฅผ ๋‹จ๊ณ„๋ณ„๋กœ ๊ตฌํ˜„ํ•ด๋ณผ๊ฒŒ. ๐Ÿ˜Š

๐Ÿ“ฆ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ
ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ: collaborative-editor/
โ”œโ”€โ”€ client/
โ”‚ โ”œโ”€โ”€ index.html
โ”‚ โ”œโ”€โ”€ editor.js
โ”‚ โ”œโ”€โ”€ ot-client.js
โ”‚ โ””โ”€โ”€ styles.css
โ”œโ”€โ”€ server/
โ”‚ โ”œโ”€โ”€ server.js
โ”‚ โ”œโ”€โ”€ ot-server.js
โ”‚ โ””โ”€โ”€ document-manager.js
โ””โ”€โ”€ shared/
โ”œโ”€โ”€ operations.js
โ””โ”€โ”€ transform.js
๐Ÿ–ฅ๏ธ ์„œ๋ฒ„ ๊ตฌํ˜„ (Node.js + WebSocket)
// server/server.js
const WebSocket = require('ws');
const http = require('http');
const OTServer = require('./ot-server');

const server = http.createServer();
const wss = new WebSocket.Server({ server });

const otServer = new OTServer();

wss.on('connection', (ws, req) => {
    const clientId = generateClientId();
    console.log(`์ƒˆ ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ: ${clientId}`);
    
    ws.on('message', (message) => {
        try {
            const data = JSON.parse(message);
            handleMessage(ws, clientId, data);
        } catch (error) {
            console.error('๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ์˜ค๋ฅ˜:', error);
            ws.send(JSON.stringify({
                type: 'error',
                message: error.message
            }));
        }
    });
    
    ws.on('close', () => {
        console.log(`ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ ์ข…๋ฃŒ: ${clientId}`);
        otServer.removeClient(clientId);
    });
    
    ws.on('error', (error) => {
        console.error('WebSocket ์˜ค๋ฅ˜:', error);
    });
});

function handleMessage(ws, clientId, data) {
    switch(data.type) {
        case 'join':
            otServer.addClient(clientId, ws, data.documentId);
            
            // ํ˜„์žฌ ๋ฌธ์„œ ์ƒํƒœ ์ „์†ก
            const doc = otServer.getDocument(data.documentId);
            ws.send(JSON.stringify({
                type: 'init',
                content: doc.content,
                revision: doc.revision,
                clients: otServer.getActiveClients(data.documentId)
            }));
            
            // ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ๋“ค์—๊ฒŒ ์•Œ๋ฆผ
            otServer.broadcast(data.documentId, {
                type: 'client-joined',
                clientId: clientId
            }, clientId);
            break;
            
        case 'operation':
            const result = otServer.handleOperation(clientId, data.operation);
            
            if (result.success) {
                // ์ž‘์—… ์ƒ์„ฑ์ž์—๊ฒŒ ํ™•์ธ
                ws.send(JSON.stringify({
                    type: 'acknowledgement',
                    operationId: data.operation.id
                }));
                
                // ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ๋“ค์—๊ฒŒ ๋ธŒ๋กœ๋“œ์บ์ŠคํŠธ
                otServer.broadcast(data.operation.documentId, {
                    type: 'operation',
                    operation: result.operation
                }, clientId);
            } else {
                // ์˜ค๋ฅ˜ ๋ฐœ์ƒ
                ws.send(JSON.stringify({
                    type: 'error',
                    message: result.error
                }));
            }
            break;
            
        case 'cursor':
            // ์ปค์„œ ์œ„์น˜ ๋ธŒ๋กœ๋“œ์บ์ŠคํŠธ
            otServer.broadcast(data.documentId, {
                type: 'cursor',
                clientId: clientId,
                position: data.position,
                selection: data.selection
            }, clientId);
            break;
            
        case 'ping':
            ws.send(JSON.stringify({ type: 'pong' }));
            break;
    }
}

server.listen(8080, () => {
    console.log('์„œ๋ฒ„ ์‹œ์ž‘: http://localhost:8080');
});

function generateClientId() {
    return `client-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
}
// server/ot-server.js
class OTServer {
    constructor() {
        this.documents = new Map();
        this.clients = new Map();
    }
    
    addClient(clientId, ws, documentId) {
        this.clients.set(clientId, {
            ws: ws,
            documentId: documentId
        });
        
        // ๋ฌธ์„œ๊ฐ€ ์—†์œผ๋ฉด ์ƒ์„ฑ
        if (!this.documents.has(documentId)) {
            this.documents.set(documentId, {
                content: "",
                revision: 0,
                history: [],
                activeClients: new Set()
            });
        }
        
        this.documents.get(documentId).activeClients.add(clientId);
    }
    
    removeClient(clientId) {
        const client = this.clients.get(clientId);
        if (client) {
            const doc = this.documents.get(client.documentId);
            if (doc) {
                doc.activeClients.delete(clientId);
                
                // ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ๋“ค์—๊ฒŒ ์•Œ๋ฆผ
                this.broadcast(client.documentId, {
                    type: 'client-left',
                    clientId: clientId
                });
            }
        }
        this.clients.delete(clientId);
    }
    
    getDocument(documentId) {
        return this.documents.get(documentId);
    }
    
    getActiveClients(documentId) {
        const doc = this.documents.get(documentId);
        return doc ? Array.from(doc.activeClients) : [];
    }
    
    handleOperation(clientId, operation) {
        const doc = this.documents.get(operation.documentId);
        
        if (!doc) {
            return {
                success: false,
                error: '๋ฌธ์„œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค'
            };
        }
        
        // ๋ฆฌ๋น„์ „ ํ™•์ธ
        if (operation.revision !== doc.revision) {
            return {
                success: false,
                error: '๋ฆฌ๋น„์ „ ๋ถˆ์ผ์น˜'
            };
        }
        
        try {
            // ์ž‘์—… ์ ์šฉ
            doc.content = this.applyOperation(doc.content, operation);
            doc.revision++;
            doc.history.push({
                operation: operation,
                clientId: clientId,
                timestamp: Date.now()
            });
            
            // ํžˆ์Šคํ† ๋ฆฌ ํฌ๊ธฐ ์ œํ•œ
            if (doc.history.length > 1000) {
                doc.history = doc.history.slice(-500);
            }
            
            return {
                success: true,
                operation: operation
            };
        } catch (error) {
            return {
                success: false,
                error: error.message
            };
        }
    }
    
    applyOperation(content, operation) {
        if (operation.type === 'insert') {
            return content.slice(0, operation.position) + 
                   operation.char + 
                   content.slice(operation.position);
        } else if (operation.type === 'delete') {
            return content.slice(0, operation.position) + 
                   content.slice(operation.position + operation.length);
        }
        return content;
    }
    
    broadcast(documentId, message, excludeClientId = null) {
        const doc = this.documents.get(documentId);
        if (!doc) return;
        
        for (let clientId of doc.activeClients) {
            if (clientId === excludeClientId) continue;
            
            const client = this.clients.get(clientId);
            if (client && client.ws.readyState === 1) {  // OPEN
                client.ws.send(JSON.stringify(message));
            }
        }
    }
}

module.exports = OTServer;
๐Ÿ’ป ํด๋ผ์ด์–ธํŠธ ๊ตฌํ˜„ (HTML + JavaScript)
// client/editor.js
class CollaborativeEditor {
    constructor(editorElement, documentId) {
        this.editor = editorElement;
        this.documentId = documentId;
        this.client = null;
        this.remoteCursors = new Map();
        
        this.init();
    }
    
    async init() {
        // WebSocket ์—ฐ๊ฒฐ
        this.client = new OTClient(
            `ws://localhost:8080`,
            this.documentId,
            this.generateUserId()
        );
        
        await this.client.connect();
        
        // ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์„ค์ •
        this.setupEventListeners();
        
        // UI ์ดˆ๊ธฐํ™”
        this.setupUI();
    }
    
    setupEventListeners() {
        // ์ž…๋ ฅ ์ด๋ฒคํŠธ
        this.editor.addEventListener('input', (e) => {
            this.handleInput(e);
        });
        
        // ์„ ํƒ ๋ณ€๊ฒฝ
        this.editor.addEventListener('select', () => {
            this.handleSelectionChange();
        });
        
        // ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ
        this.editor.addEventListener('keydown', (e) => {
            this.handleKeyDown(e);
        });
        
        // ๋ฌธ์„œ ์—…๋ฐ์ดํŠธ ์ด๋ฒคํŠธ
        this.client.on('document-updated', () => {
            this.renderDocument();
        });
        
        // ์›๊ฒฉ ์ปค์„œ ์ด๋ฒคํŠธ
        this.client.on('remote-cursor', (data) => {
            this.updateRemoteCursor(data.clientId, data.position);
        });
        
        // ํด๋ผ์ด์–ธํŠธ ์ฐธ์—ฌ/ํ‡ด์žฅ
        this.client.on('client-joined', (clientId) => {
            this.showNotification(`์‚ฌ์šฉ์ž๊ฐ€ ์ฐธ์—ฌํ–ˆ์Šต๋‹ˆ๋‹ค`);
        });
        
        this.client.on('client-left', (clientId) => {
            this.removeRemoteCursor(clientId);
            this.showNotification(`์‚ฌ์šฉ์ž๊ฐ€ ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค`);
        });
    }
    
    handleInput(event) {
        const currentContent = this.editor.value;
        const cursorPosition = this.editor.selectionStart;
        
        // ๋ณ€๊ฒฝ์‚ฌํ•ญ ๊ฐ์ง€
        const operations = this.detectChanges(
            this.client.document,
            currentContent,
            cursorPosition
        );
        
        // ๊ฐ ์ž‘์—… ์ ์šฉ
        for (let op of operations) {
            this.client.applyLocalOperation(op);
        }
    }
    
    detectChanges(oldContent, newContent, cursorPosition) {
        const operations = [];
        
        // ๊ฐ„๋‹จํ•œ diff (์‹ค์ œ๋กœ๋Š” ๋” ์ •๊ตํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ•„์š”)
        if (newContent.length > oldContent.length) {
            // ์‚ฝ์ž…
            const insertedText = newContent.slice(
                cursorPosition - (newContent.length - oldContent.length),
                cursorPosition
            );
            
            for (let i = 0; i < insertedText.length; i++) {
                operations.push({
                    type: 'insert',
                    position: cursorPosition - insertedText.length + i,
                    char: insertedText[i],
                    id: this.generateOperationId(),
                    userId: this.client.userId,
                    timestamp: Date.now(),
                    revision: this.client.revision
                });
            }
        } else if (newContent.length < oldContent.length) {
            // ์‚ญ์ œ
            const deleteLength = oldContent.length - newContent.length;
            operations.push({
                type: 'delete',
                position: cursorPosition,
                length: deleteLength,
                id: this.generateOperationId(),
                userId: this.client.userId,
                timestamp: Date.now(),
                revision: this.client.revision
            });
        }
        
        return operations;
    }
    
    handleSelectionChange() {
        const position = this.editor.selectionStart;
        const selection = {
            start: this.editor.selectionStart,
            end: this.editor.selectionEnd
        };
        
        // ์ปค์„œ ์œ„์น˜ ์ „์†ก
        this.client.sendCursorPosition(position, selection);
    }
    
    renderDocument() {
        const cursorPosition = this.editor.selectionStart;
        this.editor.value = this.client.document;
        this.editor.setSelectionRange(cursorPosition, cursorPosition);
    }
    
    updateRemoteCursor(clientId, position) {
        let cursor = this.remoteCursors.get(clientId);
        
        if (!cursor) {
            cursor = this.createCursorElement(clientId);
            this.remoteCursors.set(clientId, cursor);
        }
        
        // ์ปค์„œ ์œ„์น˜ ๊ณ„์‚ฐ ๋ฐ ์—…๋ฐ์ดํŠธ
        const coords = this.getCoordinatesForPosition(position);
        cursor.style.left = `${coords.x}px`;
        cursor.style.top = `${coords.y}px`;
    }
    
    createCursorElement(clientId) {
        const cursor = document.createElement('div');
        cursor.className = 'remote-cursor';
        cursor.style.position = 'absolute';
        cursor.style.width = '2px';
        cursor.style.height = '20px';
        cursor.style.backgroundColor = this.getColorForClient(clientId);
        cursor.style.zIndex = '1000';
        
        const label = document.createElement('div');
        label.className = 'cursor-label';
        label.textContent = `User ${clientId.substr(0, 8)}`;
        cursor.appendChild(label);
        
        this.editor.parentElement.appendChild(cursor);
        return cursor;
    }
    
    removeRemoteCursor(clientId) {
        const cursor = this.remoteCursors.get(clientId);
        if (cursor) {
            cursor.remove();
            this.remoteCursors.delete(clientId);
        }
    }
    
    getColorForClient(clientId) {
        // ํด๋ผ์ด์–ธํŠธ๋ณ„ ๊ณ ์œ  ์ƒ‰์ƒ ์ƒ์„ฑ
        const colors = [
            '#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A',
            '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E2'
        ];
        const hash = clientId.split('').reduce((acc, char) => 
            acc + char.charCodeAt(0), 0
        );
        return colors[hash % colors.length];
    }
    
    getCoordinatesForPosition(position) {
        // ํ…์ŠคํŠธ ์œ„์น˜๋ฅผ ํ™”๋ฉด ์ขŒํ‘œ๋กœ ๋ณ€ํ™˜
        // ์‹ค์ œ ๊ตฌํ˜„์€ ๋” ๋ณต์žกํ•จ
        const lineHeight = 20;
        const charWidth = 8;
        
        const lines = this.editor.value.substr(0, position).split('\n');
        const line = lines.length - 1;
        const col = lines[lines.length - 1].length;
        
        return {
            x: col * charWidth,
            y: line * lineHeight
        };
    }
    
    setupUI() {
        // ํˆด๋ฐ” ์ถ”๊ฐ€
        const toolbar = document.createElement('div');
        toolbar.className = 'toolbar';
        toolbar.innerHTML = `
            <button onclick="editor.formatText('bold')">Bold</button>
            <button onclick="editor.formatText('italic')">Italic</button>
            <button onclick="editor.undo()">Undo</button>
            <button onclick="editor.redo()">Redo</button>
            <span class="status">์—ฐ๊ฒฐ๋จ โœ“</span>
        `;
        this.editor.parentElement.insertBefore(toolbar, this.editor);
    }
    
    showNotification(message) {
        const notification = document.createElement('div');
        notification.className = 'notification';
        notification.textContent = message;
        document.body.appendChild(notification);
        
        setTimeout(() => {
            notification.remove();
        }, 3000);
    }
    
    generateUserId() {
        return `user-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
    }
    
    generateOperationId() {
        return `op-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
    }
}

// ์ดˆ๊ธฐํ™”
document.addEventListener('DOMContentLoaded', () => {
    const editor = document.getElementById('editor');
    const documentId = new URLSearchParams(window.location.search).get('doc') || 'default';
    
    window.editor = new CollaborativeEditor(editor, documentId);
});
๐Ÿ’ก ์‹ค์ „ ํŒ: ์ด ์˜ˆ์ œ๋Š” ๊ธฐ๋ณธ์ ์ธ ๊ตฌํ˜„์ด์•ผ. ์‹ค์ œ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ๋Š” ๋” ๋งŽ์€ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•ด:
- ์ธ์ฆ ๋ฐ ๊ถŒํ•œ ๊ด€๋ฆฌ
- ๋ฌธ์„œ ์ €์žฅ ๋ฐ ๋กœ๋”ฉ
- ์˜คํ”„๋ผ์ธ ์ง€์›
- ๋” ์ •๊ตํ•œ diff ์•Œ๊ณ ๋ฆฌ์ฆ˜
- ์„ฑ๋Šฅ ๋ชจ๋‹ˆํ„ฐ๋ง
- ์—๋Ÿฌ ๋ณต๊ตฌ ๋ฉ”์ปค๋‹ˆ์ฆ˜

๐Ÿš€ ๊ณ ๊ธ‰ ์ฃผ์ œ: CRDT์™€์˜ ๋น„๊ต

OT ๋ง๊ณ ๋„ ์‹ค์‹œ๊ฐ„ ํ˜‘์—…์„ ๊ตฌํ˜„ํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ด ์žˆ์–ด. ๋ฐ”๋กœ CRDT(Conflict-free Replicated Data Types)์•ผ! ๋‘ ์ ‘๊ทผ ๋ฐฉ์‹์„ ๋น„๊ตํ•ด๋ณด์ž. ๐Ÿค”

๐Ÿ“Š OT vs CRDT ๋น„๊ต
ํŠน์„ฑ OT (Operational Transformation) CRDT
์ค‘์•™ ์„œ๋ฒ„ ํ•„์š” (์ž‘์—… ์ˆœ์„œ ์กฐ์œจ) ๋ถˆํ•„์š” (P2P ๊ฐ€๋Šฅ)
๋ณต์žก๋„ ๋ณ€ํ™˜ ํ•จ์ˆ˜ ๊ตฌํ˜„์ด ๋ณต์žก ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๊ฐ€ ๋ณต์žก
๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ ์ƒ๋Œ€์ ์œผ๋กœ ์ ์Œ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋กœ ์ธํ•ด ๋งŽ์Œ
์ˆ˜๋ ด ๋ณด์žฅ ๋ณ€ํ™˜ ํ•จ์ˆ˜๊ฐ€ ์ •ํ™•ํ•ด์•ผ ํ•จ ์ˆ˜ํ•™์ ์œผ๋กœ ๋ณด์žฅ๋จ
์˜คํ”„๋ผ์ธ ์ง€์› ์–ด๋ ค์›€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ง€์›
์„ฑ๋Šฅ ๋น ๋ฆ„ ์ƒ๋Œ€์ ์œผ๋กœ ๋А๋ฆผ
๐Ÿ”ง CRDT ๊ฐ„๋‹จ ์˜ˆ์ œ

CRDT์˜ ๊ธฐ๋ณธ ์•„์ด๋””์–ด๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ๋ด๋ณด์ž:

// CRDT ๊ธฐ๋ฐ˜ ํ…์ŠคํŠธ ์—๋””ํ„ฐ (๊ฐ„๋‹จํ•œ ๋ฒ„์ „)
class CRDTText {
    constructor(siteId) {
        this.siteId = siteId;
        this.chars = [];  // ๊ฐ ๋ฌธ์ž๋Š” ๊ณ ์œ  ID๋ฅผ ๊ฐ€์ง
        this.clock = 0;
    }
    
    // ๋ฌธ์ž ์‚ฝ์ž…
    insert(position, char) {
        this.clock++;
        
        // ๊ณ ์œ  ID ์ƒ์„ฑ (์‚ฌ์ดํŠธ ID + ๋…ผ๋ฆฌ์  ์‹œ๊ณ„)
        const id = {
            site: this.siteId,
            clock: this.clock,
            position: position
        };
        
        const charObj = {
            id: id,
            char: char,
            visible: true
        };
        
        // ์œ„์น˜์— ์‚ฝ์ž…
        this.chars.splice(position, 0, charObj);
        
        return {
            type: 'insert',
            char: charObj
        };
    }
    
    // ๋ฌธ์ž ์‚ญ์ œ (์‹ค์ œ๋กœ๋Š” ์ˆจ๊น€ ์ฒ˜๋ฆฌ)
    delete(position) {
        if (position < this.chars.length) {
            this.chars[position].visible = false;
            
            return {
                type: 'delete',
                id: this.chars[position].id
            };
        }
        return null;
    }
    
    // ์›๊ฒฉ ์ž‘์—… ์ ์šฉ
    applyRemoteOperation(operation) {
        if (operation.type === 'insert') {
            // ID ๊ธฐ๋ฐ˜์œผ๋กœ ์˜ฌ๋ฐ”๋ฅธ ์œ„์น˜ ์ฐพ๊ธฐ
            const position = this.findInsertPosition(operation.char.id);
            this.chars.splice(position, 0, operation.char);
        } else if (operation.type === 'delete') {
            // ID๋กœ ๋ฌธ์ž ์ฐพ์•„์„œ ์ˆจ๊น€ ์ฒ˜๋ฆฌ
            const char = this.chars.find(c => 
                this.compareIds(c.id, operation.id)
            );
            if (char) {
                char.visible = false;
            }
        }
    }
    
    findInsertPosition(newId) {
        // ID ์ˆœ์„œ์— ๋”ฐ๋ผ ์œ„์น˜ ๊ฒฐ์ •
        for (let i = 0; i < this.chars.length; i++) {
            if (this.compareIds(newId, this.chars[i].id) < 0) {
                return i;
            }
        }
        return this.chars.length;
    }
    
    compareIds(id1, id2) {
        // ์‚ฌ์ดํŠธ ID ๋น„๊ต
        if (id1.site !== id2.site) {
            return id1.site - id2.site;
        }
        // ์‹œ๊ณ„ ๋น„๊ต
        if (id1.clock !== id2.clock) {
            return id1.clock - id2.clock;
        }
        // ์œ„์น˜ ๋น„๊ต
        return id1.position - id2.position;
    }
    
    // ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜
    toString() {
        return this.chars
            .filter(c => c.visible)
            .map(c => c.char)
            .join('');
    }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const site1 = new CRDTText('site1');
const site2 = new CRDTText('site2');

// Site 1์—์„œ "Hello" ์ž…๋ ฅ
const op1 = site1.insert(0, 'H');
const op2 = site1.insert(1, 'e');
const op3 = site1.insert(2, 'l');
const op4 = site1.insert(3, 'l');
const op5 = site1.insert(4, 'o');

// Site 2์— ์ž‘์—… ์ „ํŒŒ
site2.applyRemoteOperation(op1);
site2.applyRemoteOperation(op2);
site2.applyRemoteOperation(op3);
site2.applyRemoteOperation(op4);
site2.applyRemoteOperation(op5);

console.log(site1.toString());  // "Hello"
console.log(site2.toString());  // "Hello"

// ๋™์‹œ ํŽธ์ง‘
const op6 = site1.insert(5, '!');  // Site 1: "Hello!"
const op7 = site2.insert(0, 'Oh ');  // Site 2: "Oh Hello"

// ์„œ๋กœ ์ž‘์—… ์ „ํŒŒ
site1.applyRemoteOperation(op7);
site2.applyRemoteOperation(op6);

console.log(site1.toString());  // "Oh Hello!"
console.log(site2.toString());  // "Oh Hello!"
// ์ž๋™์œผ๋กœ ์ˆ˜๋ ด!
๐ŸŽฏ CRDT์˜ ์žฅ์ : 1. ์ˆ˜ํ•™์  ๋ณด์žฅ: ์ถฉ๋Œ ์—†์ด ์ž๋™์œผ๋กœ ์ˆ˜๋ ด
2. P2P ์ง€์›: ์ค‘์•™ ์„œ๋ฒ„ ์—†์ด๋„ ๋™์ž‘
3. ์˜คํ”„๋ผ์ธ ์นœํ™”์ : ๋‚˜์ค‘์— ๋™๊ธฐํ™” ๊ฐ€๋Šฅ
4. ๋‹จ์ˆœํ•œ ๋ณ‘ํ•ฉ: ๋ณต์žกํ•œ ๋ณ€ํ™˜ ๋กœ์ง ๋ถˆํ•„์š”
โš ๏ธ CRDT์˜ ๋‹จ์ : 1. ๋ฉ”๋ชจ๋ฆฌ ์˜ค๋ฒ„ํ—ค๋“œ: ๊ฐ ๋ฌธ์ž๋งˆ๋‹ค ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ํ•„์š”
2. ์„ฑ๋Šฅ: ํฐ ๋ฌธ์„œ์—์„œ ๋А๋ ค์งˆ ์ˆ˜ ์žˆ์Œ
3. ์˜๋„ ๋ณด์กด: ์‚ฌ์šฉ์ž ์˜๋„๊ฐ€ ํ•ญ์ƒ ์ •ํ™•ํžˆ ๋ฐ˜์˜๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ
4. ๊ฐ€๋น„์ง€ ์ปฌ๋ ‰์…˜: ์‚ญ์ œ๋œ ๋ฌธ์ž๋„ ๋ฉ”๋ชจ๋ฆฌ์— ๋‚จ์Œ

๐ŸŽ“ ์‹ค๋ฌด์—์„œ์˜ ํ™œ์šฉ ์‚ฌ๋ก€

์ด๋ก ์€ ์ถฉ๋ถ„ํžˆ ๋ดค์œผ๋‹ˆ ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ํ™œ์šฉ๋˜๋Š”์ง€ ์‚ดํŽด๋ณด์ž! ์œ ๋ช…ํ•œ ์„œ๋น„์Šค๋“ค์˜ ์‚ฌ๋ก€๋ฅผ ํ†ตํ•ด ๋ฐฐ์›Œ๋ณด์ž. ๐Ÿ’ผ

๐Ÿ“ Google Docs
๊ตฌ๊ธ€ ๋…์Šค์˜ ์ ‘๊ทผ ๋ฐฉ์‹: ๊ตฌ๊ธ€ ๋…์Šค๋Š” OT๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜์ง€๋งŒ ๋งŽ์€ ์ตœ์ ํ™”๋ฅผ ์ถ”๊ฐ€ํ–ˆ์–ด:

1. ๊ณ„์ธต์  OT: ๋ฌธ์„œ๋ฅผ ์ž‘์€ ๋ธ”๋ก์œผ๋กœ ๋‚˜๋ˆ ์„œ ๊ฐ๊ฐ ๋…๋ฆฝ์ ์œผ๋กœ OT ์ ์šฉ
2. ์Šค๋ƒ…์ƒท ์‹œ์Šคํ…œ: ์ฃผ๊ธฐ์ ์œผ๋กœ ๋ฌธ์„œ ์Šค๋ƒ…์ƒท์„ ์ €์žฅํ•ด์„œ ๋ณต๊ตฌ ์†๋„ ํ–ฅ์ƒ
3. ์ง€๋Šฅํ˜• ๋ฐฐ์นญ: ์‚ฌ์šฉ์ž ํ–‰๋™ ํŒจํ„ด์„ ํ•™์Šตํ•ด์„œ ์ตœ์ ์˜ ๋ฐฐ์นญ ์ „๋žต ์ ์šฉ
4. ํด๋ผ์ด์–ธํŠธ ์˜ˆ์ธก: ์„œ๋ฒ„ ์‘๋‹ต ์ „์— ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์ธกํ•ด์„œ ํ‘œ์‹œ
๐Ÿ’ฌ Figma
Figma์˜ ํ˜์‹ : Figma๋Š” ๋””์ž์ธ ๋„๊ตฌ์ง€๋งŒ ์‹ค์‹œ๊ฐ„ ํ˜‘์—…์˜ ์ข‹์€ ์˜ˆ์‹œ์•ผ:

1. WebAssembly ํ™œ์šฉ: ๋ณต์žกํ•œ ๋ณ€ํ™˜ ๋กœ์ง์„ WASM์œผ๋กœ ๊ตฌํ˜„ํ•ด์„œ ์„ฑ๋Šฅ ํ–ฅ์ƒ
2. ๋ ˆ์ด์–ด ๊ธฐ๋ฐ˜ OT: ๊ฐ ๋””์ž์ธ ๋ ˆ์ด์–ด๋ฅผ ๋…๋ฆฝ์ ์œผ๋กœ ์ฒ˜๋ฆฌ
3. ๋ฒกํ„ฐ ๊ทธ๋ž˜ํ”ฝ ์ตœ์ ํ™”: ๋ฒกํ„ฐ ๋ฐ์ดํ„ฐ์— ํŠนํ™”๋œ ๋ณ€ํ™˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜
4. ์‹ค์‹œ๊ฐ„ ์ปค์„œ: ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์˜ ๋งˆ์šฐ์Šค ์›€์ง์ž„๊นŒ์ง€ ์‹ค์‹œ๊ฐ„ ํ‘œ์‹œ
๐Ÿ“Š Notion
Notion์˜ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์ ‘๊ทผ: Notion์€ OT์™€ CRDT๋ฅผ ํ˜ผํ•ฉํ•ด์„œ ์‚ฌ์šฉํ•ด:

1. ๋ธ”๋ก ๋‹จ์œ„ CRDT: ๊ฐ ๋ธ”๋ก์€ CRDT๋กœ ๊ด€๋ฆฌ
2. ํ…์ŠคํŠธ OT: ๋ธ”๋ก ๋‚ด ํ…์ŠคํŠธ๋Š” OT๋กœ ์ฒ˜๋ฆฌ
3. ์˜คํ”„๋ผ์ธ ์šฐ์„ : ๋กœ์ปฌ์—์„œ ๋จผ์ € ์ž‘์—…ํ•˜๊ณ  ๋‚˜์ค‘์— ๋™๊ธฐํ™”
4. ์ถฉ๋Œ UI: ์ž๋™ ํ•ด๊ฒฐ์ด ์–ด๋ ค์šด ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž์—๊ฒŒ ์„ ํƒ๊ถŒ ์ œ๊ณต
๐Ÿ’ก ์žฌ๋Šฅ๋„ท ํ™œ์šฉ ์•„์ด๋””์–ด: ์žฌ๋Šฅ๋„ท(https://www.jaenung.net)์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์žฌ๋Šฅ์„ ๊ฑฐ๋ž˜ํ•  ๋•Œ, ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๋„๊ตฌ ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ๋ฅผ ์˜๋ขฐํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ฃผํ•  ์ˆ˜ ์žˆ์–ด! ํŠนํžˆ ์ด๋Ÿฐ ๊ณ ๊ธ‰ ๊ธฐ์ˆ ์ด ํ•„์š”ํ•œ ํ”„๋กœ์ ํŠธ๋Š” ๋†’์€ ๊ฐ€์น˜๋ฅผ ์ธ์ •๋ฐ›์„ ์ˆ˜ ์žˆ์ง€. ๋˜ํ•œ ์žฌ๋Šฅ๋„ท์˜ '์ง€์‹์ธ์˜ ์ˆฒ'์—์„œ ์ด๋Ÿฐ ๊ธฐ์ˆ  ์ง€์‹์„ ๊ณต์œ ํ•˜๋ฉด์„œ ์ „๋ฌธ์„ฑ์„ ์–ดํ•„ํ•  ์ˆ˜๋„ ์žˆ์–ด! ๐ŸŒŸ

๐Ÿ” ๋””๋ฒ„๊น…๊ณผ ํ…Œ์ŠคํŠธ ์ „๋žต

์‹ค์‹œ๊ฐ„ ํ˜‘์—… ์‹œ์Šคํ…œ์€ ๋””๋ฒ„๊น…์ด ์ •๋ง ์–ด๋ ค์›Œ. ํƒ€์ด๋ฐ ์ด์Šˆ, ๋„คํŠธ์›Œํฌ ์ง€์—ฐ, ๋™์‹œ์„ฑ ๋ฌธ์ œ ๋“ฑ๋“ฑ... ํšจ๊ณผ์ ์ธ ๋””๋ฒ„๊น… ์ „๋žต์„ ์•Œ์•„๋ณด์ž! ๐Ÿ›

๐ŸŽฏ ๋กœ๊น… ์‹œ์Šคํ…œ ๊ตฌ์ถ•
class OTLogger {
    constructor(level = 'info') {
        this.level = level;
        this.logs = [];
        this.maxLogs = 1000;
    }
    
    log(level, category, message, data = {}) {
        const logEntry = {
            timestamp: Date.now(),
            level: level,
            category: category,
            message: message,
            data: data,
            stackTrace: new Error().stack
        };
        
        this.logs.push(logEntry);
        
        // ๋กœ๊ทธ ํฌ๊ธฐ ์ œํ•œ
        if (this.logs.length > this.maxLogs) {
            this.logs.shift();
        }
        
        // ์ฝ˜์†” ์ถœ๋ ฅ
        if (this.shouldLog(level)) {
            console.log(`[${level}] ${category}: ${message}`, data);
        }
        
        // ์„œ๋ฒ„๋กœ ์ „์†ก (์ค‘์š”ํ•œ ๋กœ๊ทธ๋งŒ)
        if (level === 'error' || level === 'warning') {
            this.sendToServer(logEntry);
        }
    }
    
    debug(category, message, data) {
        this.log('debug', category, message, data);
    }
    
    info(category, message, data) {
        this.log('info', category, message, data);
    }
    
    warning(category, message, data) {
        this.log('warning', category, message, data);
    }
    
    error(category, message, data) {
        this.log('error', category, message, data);
    }
    
    shouldLog(level) {
        const levels = ['debug', 'info', 'warning', 'error'];
        const currentIndex = levels.indexOf(this.level);
        const logIndex = levels.indexOf(level);
        return logIndex >= currentIndex;
    }
    
    // ์ž‘์—… ์ถ”์ 
    traceOperation(operation, stage) {
        this.debug('operation', `Operation ${stage}`, {
            operationId: operation.id,
            type: operation.type,
            position: operation.position,
            revision: operation.revision,
            stage: stage
        });
    }
    
    // ๋ณ€ํ™˜ ์ถ”์ 
    traceTransform(op1, op2, result) {
        this.debug('transform', 'Operation transformed', {
            original: {
                type: op1.type,
                position: op1.position
            },
            against: {
                type: op2.type,
                position: op2.position
            },
            result: {
                type: result.type,
                position: result.position
            }
        });
    }
    
    // ์ƒํƒœ ์Šค๋ƒ…์ƒท
    captureState(client) {
        return {
            document: client.document,
            revision: client.revision,
            pendingOps: client.pendingOperations.length,
            bufferSize: client.buffer.length,
            timestamp: Date.now()
        };
    }
    
    // ๋กœ๊ทธ ๋ถ„์„
    analyzeConflicts() {
        const conflicts = this.logs.filter(log => 
            log.category === 'conflict'
        );
        
        return {
            total: conflicts.length,
            byType: this.groupBy(conflicts, 'data.type'),
            timeline: this.createTimeline(conflicts)
        };
    }
    
    groupBy(array, key) {
        return array.reduce((result, item) => {
            const value = key.split('.').reduce((obj, k) => obj[k], item);
            (result[value] = result[value] || []).push(item);
            return result;
        }, {});
    }
    
    createTimeline(logs) {
        return logs.map(log => ({
            time: new Date(log.timestamp).toISOString(),
            message: log.message
        }));
    }
    
    // ๋กœ๊ทธ ๋‚ด๋ณด๋‚ด๊ธฐ
    exportLogs(format = 'json') {
        if (format === 'json') {
            return JSON.stringify(this.logs, null, 2);
        } else if (format === 'csv') {
            return this.logsToCSV();
        }
    }
    
    logsToCSV() {
        const headers = ['timestamp', 'level', 'category', 'message'];
        const rows = this.logs.map(log => 
            headers.map(h => log[h]).join(',')
        );
        return [headers.join(','), ...rows].join('\n');
    }
    
    sendToServer(logEntry) {
        // ์„œ๋ฒ„๋กœ ๋กœ๊ทธ ์ „์†ก (์‹ค์ œ ๊ตฌํ˜„ ํ•„์š”)
        fetch('/api/logs', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(logEntry)
        }).catch(err => {
            console.error('๋กœ๊ทธ ์ „์†ก ์‹คํŒจ:', err);
        });
    }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const logger = new OTLogger('debug');

// ์ž‘์—… ๋กœ๊น…
logger.traceOperation(operation, 'created');
logger.traceOperation(operation, 'sent');
logger.traceOperation(operation, 'acknowledged');

// ๋ณ€ํ™˜ ๋กœ๊น…
logger.traceTransform(op1, op2, transformedOp);

// ์—๋Ÿฌ ๋กœ๊น…
logger.error('network', 'WebSocket connection failed', {
    url: wsUrl,
    error: error.message
});
๐Ÿงช ์ž๋™ํ™”๋œ ํ…Œ์ŠคํŠธ
// ๋ณ€ํ™˜ ํ•จ์ˆ˜ ํ…Œ์ŠคํŠธ
class OTTestSuite {
    constructor() {
        this.tests = [];
        this.results = [];
    }
    
    // ๊ธฐ๋ณธ ๋ณ€ํ™˜ ํ…Œ์ŠคํŠธ
    testInsertInsert() {
        const op1 = { type: 'insert', position: 5, char: 'A' };
        const op2 = { type: 'insert', position: 3, char: 'B' };
        
        const transformed = transform(op1, op2);
        
        // op2๊ฐ€ op1๋ณด๋‹ค ์•ž์—์„œ ๋ฐœ์ƒํ–ˆ์œผ๋ฏ€๋กœ op1์˜ ์œ„์น˜๊ฐ€ ๋ฐ€๋ ค์•ผ ํ•จ
        this.assert(
            transformed.position === 6,
            'Insert-Insert: ์œ„์น˜๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์กฐ์ •๋˜์–ด์•ผ ํ•จ'
        );
    }
    
    // ์ˆ˜๋ ด์„ฑ ํ…Œ์ŠคํŠธ
    testConvergence() {
        const doc1 = "Hello";
        const doc2 = "Hello";
        
        const op1 = { type: 'insert', position: 5, char: '!' };
        const op2 = { type: 'insert', position: 0, char: 'Oh ' };
        
        // ํด๋ผ์ด์–ธํŠธ 1: op1 ์ ์šฉ ํ›„ op2 ๋ณ€ํ™˜ ์ ์šฉ
        let result1 = applyOperation(doc1, op1);
        const op2_transformed = transform(op2, op1);
        result1 = applyOperation(result1, op2_transformed);
        
        // ํด๋ผ์ด์–ธํŠธ 2: op2 ์ ์šฉ ํ›„ op1 ๋ณ€ํ™˜ ์ ์šฉ
        let result2 = applyOperation(doc2, op2);
        const op1_transformed = transform(op1, op2);
        result2 = applyOperation(result2, op1_transformed);
        
        this.assert(
            result1 === result2,
            `์ˆ˜๋ ด์„ฑ: ์ตœ์ข… ๊ฒฐ๊ณผ๊ฐ€ ๋™์ผํ•ด์•ผ ํ•จ (${result1} === ${result2})`
        );
    }
    
    // ์˜๋„ ๋ณด์กด ํ…Œ์ŠคํŠธ
    testIntentionPreservation() {
        const doc = "Hello World";
        const op1 = { type: 'delete', position: 5, length: 6 };  // " World" ์‚ญ์ œ
        const op2 = { type: 'insert', position: 11, char: '!' };  // ๋์— ! ์ถ”๊ฐ€
        
        // op1 ์ ์šฉ ํ›„ op2 ๋ณ€ํ™˜
        const result = applyOperation(doc, op1);
        const op2_transformed = transform(op2, op1);
        const final = applyOperation(result, op2_transformed);
        
        // ์˜๋„: ๋ฌธ์žฅ ๋์— !๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค ํ–ˆ์Œ
        this.assert(
            final === "Hello!",
            `์˜๋„ ๋ณด์กด: ๋์— !๊ฐ€ ์ถ”๊ฐ€๋˜์–ด์•ผ ํ•จ (${final})`
        );
    }
    
    // ๋žœ๋ค ํ…Œ์ŠคํŠธ (Fuzzing)
    testRandomOperations(iterations = 1000) {
        for (let i = 0; i < iterations; i++) {
            const doc = this.generateRandomDocument();
            const op1 = this.generateRandomOperation(doc);
            const op2 = this.generateRandomOperation(doc);
            
            try {
                // ์–‘๋ฐฉํ–ฅ ๋ณ€ํ™˜ ํ…Œ์ŠคํŠธ
                const op1_t = transform(op1, op2);
                const op2_t = transform(op2, op1);
                
                // ๊ฒฐ๊ณผ ์ ์šฉ
                let result1 = applyOperation(applyOperation(doc, op1), op2_t);
                let result2 = applyOperation(applyOperation(doc, op2), op1_t);
                
                this.assert(
                    result1 === result2,
                    `๋žœ๋ค ํ…Œ์ŠคํŠธ ${i}: ์ˆ˜๋ ด์„ฑ ์‹คํŒจ`
                );
            } catch (error) {
                this.recordFailure(`๋žœ๋ค ํ…Œ์ŠคํŠธ ${i}`, error, { doc, op1, op2 });
            }
        }
    }
    
    // ๋™์‹œ์„ฑ ํ…Œ์ŠคํŠธ
    async testConcurrency() {
        const numClients = 10;
        const numOperations = 100;
        
        const clients = Array.from({ length: numClients }, (_, i) => 
            new OTClient(`doc-test`, `client-${i}`)
        );
        
        // ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋™์‹œ์— ์ž‘์—… ์ˆ˜ํ–‰
        const promises = clients.map(client => 
            this.performRandomOperations(client, numOperations)
        );
        
        await Promise.all(promises);
        
        // ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ์˜ ๋ฌธ์„œ๊ฐ€ ๋™์ผํ•œ์ง€ ํ™•์ธ
        const documents = clients.map(c => c.document);
        const allSame = documents.every(doc => doc === documents[0]);
        
        this.assert(
            allSame,
            '๋™์‹œ์„ฑ ํ…Œ์ŠคํŠธ: ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋™์ผํ•œ ๋ฌธ์„œ๋ฅผ ๊ฐ€์ ธ์•ผ ํ•จ'
        );
    }
    
    // ๋„คํŠธ์›Œํฌ ์ง€์—ฐ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
    async testWithNetworkDelay() {
        const client1 = new OTClient('doc-test', 'client-1');
        const client2 = new OTClient('doc-test', 'client-2');
        
        // ์ž‘์—… ์ƒ์„ฑ
        const op1 = client1.createOperation('insert', 0, 'A');
        const op2 = client2.createOperation('insert', 0, 'B');
        
        // ์ง€์—ฐ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
        await this.delay(Math.random() * 100);
        client2.receiveRemoteOperation(op1);
        
        await this.delay(Math.random() * 100);
        client1.receiveRemoteOperation(op2);
        
        this.assert(
            client1.document === client2.document,
            '๋„คํŠธ์›Œํฌ ์ง€์—ฐ ํ…Œ์ŠคํŠธ: ๋ฌธ์„œ๊ฐ€ ์ˆ˜๋ ดํ•ด์•ผ ํ•จ'
        );
    }
    
    // ํ—ฌํผ ํ•จ์ˆ˜๋“ค
    generateRandomDocument() {
        const length = Math.floor(Math.random() * 100);
        return Array.from({ length }, () => 
            String.fromCharCode(65 + Math.floor(Math.random() * 26))
        ).join('');
    }
    
    generateRandomOperation(doc) {
        const type = Math.random() > 0.5 ? 'insert' : 'delete';
        const position = Math.floor(Math.random() * (doc.length + 1));
        
        if (type === 'insert') {
            const char = String.fromCharCode(65 + Math.floor(Math.random() * 26));
            return { type, position, char };
        } else {
            const length = Math.min(
                Math.floor(Math.random() * 5) + 1,
                doc.length - position
            );
            return { type, position, length };
        }
    }
    
    async performRandomOperations(client, count) {
        for (let i = 0; i < count; i++) {
            const op = this.generateRandomOperation(client.document);
            client.applyLocalOperation(op);
            await this.delay(Math.random() * 10);
        }
    }
    
    delay(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
    
    assert(condition, message) {
        this.results.push({
            passed: condition,
            message: message,
            timestamp: Date.now()
        });
        
        if (!condition) {
            console.error(`โŒ ํ…Œ์ŠคํŠธ ์‹คํŒจ: ${message}`);
        } else {
            console.log(`โœ… ํ…Œ์ŠคํŠธ ํ†ต๊ณผ: ${message}`);
        }
    }
    
    recordFailure(testName, error, context) {
        this.results.push({
            passed: false,
            testName: testName,
            error: error.message,
            context: context,
            timestamp: Date.now()
        });
    }
    
    // ํ…Œ์ŠคํŠธ ์‹คํ–‰ ๋ฐ ๋ฆฌํฌํŠธ
    async runAll() {
        console.log('๐Ÿงช OT ํ…Œ์ŠคํŠธ ์‹œ์ž‘...\n');
        
        this.testInsertInsert();
        this.testConvergence();
        this.testIntentionPreservation();
        this.testRandomOperations(100);
        await this.testConcurrency();
        await this.testWithNetworkDelay();
        
        this.printReport();
    }
    
    printReport() {
        const passed = this.results.filter(r => r.passed).length;
        const failed = this.results.filter(r => !r.passed).length;
        const total = this.results.length;
        
        console.log('\n๐Ÿ“Š ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ:');
        console.log(`์ด ํ…Œ์ŠคํŠธ: ${total}`);
        console.log(`โœ… ํ†ต๊ณผ: ${passed}`);
        console.log(`โŒ ์‹คํŒจ: ${failed}`);
        console.log(`์„ฑ๊ณต๋ฅ : ${((passed / total) * 100).toFixed(2)}%`);
        
        if (failed > 0) {
            console.log('\n์‹คํŒจํ•œ ํ…Œ์ŠคํŠธ:');
            this.results.filter(r => !r.passed).forEach(r => {
                console.log(`- ${r.message || r.testName}`);
                if (r.context) {
                    console.log(`  ์ปจํ…์ŠคํŠธ:`, r.context);
                }
            });
        }
    }
}

// ํ…Œ์ŠคํŠธ ์‹คํ–‰
const testSuite = new OTTestSuite();
testSuite.runAll();

๐ŸŽฏ ์„ฑ๋Šฅ ๋ฒค์น˜๋งˆํฌ์™€ ์ตœ์ ํ™”

์‹ค์‹œ๊ฐ„ ํ˜‘์—… ์‹œ์Šคํ…œ์˜ ์„ฑ๋Šฅ์„ ์ธก์ •ํ•˜๊ณ  ๊ฐœ์„ ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž! ๐Ÿ“ˆ

โฑ๏ธ ์„ฑ๋Šฅ ์ธก์ • ๋„๊ตฌ
class PerformanceMonitor {
    constructor() {
        this.metrics = {
            operationLatency: [],
            transformTime: [],
            renderTime: [],
            networkLatency: [],
            memoryUsage: []
        };
        this.startTime = Date.now();
    }
    
    // ์ž‘์—… ์ง€์—ฐ์‹œ๊ฐ„ ์ธก์ •
    measureOperationLatency(startTime) {
        const latency = Date.now() - startTime;
        this.metrics.operationLatency.push(latency);
        
        if (latency > 100) {
            console.warn(`โš ๏ธ ๋†’์€ ์ž‘์—… ์ง€์—ฐ: ${latency}ms`);
        }
        
        return latency;
    }
    
    // ๋ณ€ํ™˜ ์‹œ๊ฐ„ ์ธก์ •
    measureTransform(fn, ...args) {
        const start = performance.now();
        const result = fn(...args);
        const duration = performance.now() - start;
        
        this.metrics.transformTime.push(duration);
        return result;
    }
    
    // ๋ Œ๋”๋ง ์‹œ๊ฐ„ ์ธก์ •
    measureRender(fn) {
        const start = performance.now();
        fn();
        const duration = performance.now() - start;
        
        this.metrics.renderTime.push(duration);
        
        if (duration > 16.67) {  // 60fps ๊ธฐ์ค€
            console.warn(`โš ๏ธ ๋А๋ฆฐ ๋ Œ๋”๋ง: ${duration.toFixed(2)}ms`);
        }
    }
    
    // ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰ ์ธก์ •
    measureMemory() {
        if (performance.memory) {
            const usage = {
                used: performance.memory.usedJSHeapSize,
                total: performance.memory.totalJSHeapSize,
                limit: performance.memory.jsHeapSizeLimit,
                timestamp: Date.now()
            };
            
            this.metrics.memoryUsage.push(usage);
            return usage;
        }
        return null;
    }
    
    // ํ†ต๊ณ„ ๊ณ„์‚ฐ
    getStatistics(metricName) {
        const data = this.metrics[metricName];
        if (!data || data.length === 0) return null;
        
        const sorted = [...data].sort((a, b) => a - b);
        const sum = data.reduce((a, b) => a + b, 0);
        
        return {
            count: data.length,
            min: sorted[0],
            max: sorted[sorted.length - 1],
            mean: sum / data.length,
            median: sorted[Math.floor(sorted.length / 2)],
            p95: sorted[Math.floor(sorted.length * 0.95)],
            p99: sorted[Math.floor(sorted.length * 0.99)]
        };
    }
    
    // ๋ฆฌํฌํŠธ ์ƒ์„ฑ
    generateReport() {
        const report = {
            duration: Date.now() - this.startTime,
            metrics: {}
        };
        
        for (let metricName in this.metrics) {
            report.metrics[metricName] = this.getStatistics(metricName);
        }
        
        return report;
    }
    
    // ์‹ค์‹œ๊ฐ„ ๋ชจ๋‹ˆํ„ฐ๋ง
    startRealTimeMonitoring(interval = 1000) {
        setInterval(() => {
            const memory = this.measureMemory();
            const stats = this.getStatistics('operationLatency');
            
            console.log('๐Ÿ“Š ์‹ค์‹œ๊ฐ„ ๋ฉ”ํŠธ๋ฆญ:');
            console.log(`  ์ž‘์—… ์ง€์—ฐ (ํ‰๊ท ): ${stats?.mean.toFixed(2)}ms`);
            console.log(`  ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ: ${(memory?.used / 1024 / 1024).toFixed(2)}MB`);
        }, interval);
    }
    
    // ์„ฑ๋Šฅ ๊ฒฝ๊ณ 
    checkPerformance() {
        const warnings = [];
        
        // ์ž‘์—… ์ง€์—ฐ ์ฒดํฌ
        const latencyStats = this.getStatistics('operationLatency');
        if (latencyStats && latencyStats.p95 > 100) {
            warnings.push(`๋†’์€ ์ž‘์—… ์ง€์—ฐ: P95 = ${latencyStats.p95.toFixed(2)}ms`);
        }
        
        // ๋ Œ๋”๋ง ์‹œ๊ฐ„ ์ฒดํฌ
        const renderStats = this.getStatistics('renderTime');
        if (renderStats && renderStats.mean > 16.67) {
            warnings.push(`๋А๋ฆฐ ๋ Œ๋”๋ง: ํ‰๊ท  = ${renderStats.mean.toFixed(2)}ms`);
        }
        
        // ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ ์ฒดํฌ
        const memory = this.measureMemory();
        if (memory && memory.used / memory.limit > 0.9) {
            warnings.push(`๋†’์€ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ: ${(memory.used / memory.limit * 100).toFixed(2)}%`);
        }
        
        return warnings;
    }
}

// ์‚ฌ์šฉ ์˜ˆ์ œ
const monitor = new PerformanceMonitor();

// ์ž‘์—… ์ธก์ •
const opStart = Date.now();
client.applyLocalOperation(operation);
monitor.measureOperationLatency(opStart);

// ๋ณ€ํ™˜ ์ธก์ •
const transformed = monitor.measureTransform(
    transform,
    op1,
    op2
);

// ๋ Œ๋”๋ง ์ธก์ •
monitor.measureRender(() => {
    editor.renderDocument();
});

// ์ฃผ๊ธฐ์  ์ฒดํฌ
setInterval(() => {
    const warnings = monitor.checkPerformance();
    if (warnings.length > 0) {
        console.warn('โš ๏ธ ์„ฑ๋Šฅ ๊ฒฝ๊ณ :', warnings);
    }
}, 5000);

// ์ตœ์ข… ๋ฆฌํฌํŠธ
window.addEventListener('beforeunload', () => {
    const report = monitor.generateReport();
    console.log('๐Ÿ“Š ์ตœ์ข… ์„ฑ๋Šฅ ๋ฆฌํฌํŠธ:', report);
});
๐Ÿ’ก ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ฒดํฌ๋ฆฌ์ŠคํŠธ: โœ… ์ž‘์—… ๋ฐฐ์นญ์œผ๋กœ ๋„คํŠธ์›Œํฌ ์š”์ฒญ ์ค„์ด๊ธฐ
โœ… ๋ธํƒ€ ์••์ถ•์œผ๋กœ ์ „์†ก ๋ฐ์ดํ„ฐ ํฌ๊ธฐ ์ค„์ด๊ธฐ
โœ… ๊ฐ€์ƒ ์Šคํฌ๋กค๋ง์œผ๋กœ ํฐ ๋ฌธ์„œ ๋ Œ๋”๋ง ์ตœ์ ํ™”
โœ… Web Worker๋กœ ๋ณ€ํ™˜ ๋กœ์ง ์˜คํ”„๋กœ๋“œ
โœ… IndexedDB๋กœ ๋กœ์ปฌ ์บ์‹ฑ
โœ… ๋””๋ฐ”์šด์‹ฑ์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ์—…๋ฐ์ดํŠธ ๋ฐฉ์ง€
โœ… ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๋ฐฉ์ง€ (์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์ •๋ฆฌ)

๐Ÿš€ ๋ฏธ๋ž˜ ๊ธฐ์ˆ ๊ณผ ๋ฐœ์ „ ๋ฐฉํ–ฅ

์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๊ธฐ์ˆ ์€ ๊ณ„์† ๋ฐœ์ „ํ•˜๊ณ  ์žˆ์–ด. ์•ž์œผ๋กœ ์–ด๋–ค ๋ฐฉํ–ฅ์œผ๋กœ ๋‚˜์•„๊ฐˆ์ง€ ์‚ดํŽด๋ณด์ž! ๐Ÿ”ฎ

1๏ธโƒฃ AI ๊ธฐ๋ฐ˜ ์ถฉ๋Œ ํ•ด๊ฒฐ ๋จธ์‹ ๋Ÿฌ๋‹์„ ํ™œ์šฉํ•ด์„œ ์‚ฌ์šฉ์ž์˜ ์˜๋„๋ฅผ ๋” ์ •ํ™•ํ•˜๊ฒŒ ํŒŒ์•…ํ•˜๊ณ , ์ถฉ๋Œ์„ ์ง€๋Šฅ์ ์œผ๋กœ ํ•ด๊ฒฐํ•˜๋Š” ์‹œ์Šคํ…œ์ด ๊ฐœ๋ฐœ๋˜๊ณ  ์žˆ์–ด. ์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž์˜ ํŽธ์ง‘ ํŒจํ„ด์„ ํ•™์Šตํ•ด์„œ ์–ด๋–ค ๋ณ€๊ฒฝ์ด ๋” ์ค‘์š”ํ•œ์ง€ ์ž๋™์œผ๋กœ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ์ง€.
2๏ธโƒฃ ๋ธ”๋ก์ฒด์ธ ๊ธฐ๋ฐ˜ ๋ถ„์‚ฐ ํ˜‘์—… ์ค‘์•™ ์„œ๋ฒ„ ์—†์ด ๋ธ”๋ก์ฒด์ธ์„ ํ™œ์šฉํ•œ ์™„์ „ ๋ถ„์‚ฐํ˜• ํ˜‘์—… ์‹œ์Šคํ…œ์ด ์—ฐ๊ตฌ๋˜๊ณ  ์žˆ์–ด. ๊ฐ ์ž‘์—…์ด ๋ธ”๋ก์œผ๋กœ ๊ธฐ๋ก๋˜๊ณ , ํ•ฉ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ์ถฉ๋Œ์„ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ์‹์ด์•ผ.
3๏ธโƒฃ ์‹ค์‹œ๊ฐ„ ์Œ์„ฑ/์˜์ƒ ํ†ตํ•ฉ ๋ฌธ์„œ ํŽธ์ง‘๊ณผ ๋™์‹œ์— ์Œ์„ฑ, ์˜์ƒ ํ†ตํ™”๊ฐ€ ํ†ตํ•ฉ๋˜๋Š” ์ถ”์„ธ์•ผ. WebRTC ๊ธฐ์ˆ ๊ณผ OT๋ฅผ ๊ฒฐํ•ฉํ•ด์„œ ๋” ํ’๋ถ€ํ•œ ํ˜‘์—… ๊ฒฝํ—˜์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์–ด.
4๏ธโƒฃ AR/VR ํ˜‘์—… ๊ณต๊ฐ„ ๊ฐ€์ƒํ˜„์‹ค์—์„œ ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ๋™์‹œ์— 3D ๊ฐ์ฒด๋ฅผ ํŽธ์ง‘ํ•˜๋Š” ์‹œ์Šคํ…œ์ด ๊ฐœ๋ฐœ๋˜๊ณ  ์žˆ์–ด. ์ด๋ฅผ ์œ„ํ•ด 3D ๊ณต๊ฐ„์— ํŠนํ™”๋œ ์ƒˆ๋กœ์šด OT ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ํ•„์š”ํ•ด.
5๏ธโƒฃ ์—ฃ์ง€ ์ปดํ“จํŒ… ํ™œ์šฉ 5G์™€ ์—ฃ์ง€ ์ปดํ“จํŒ…์„ ํ™œ์šฉํ•ด์„œ ์ง€์—ฐ์‹œ๊ฐ„์„ ๋”์šฑ ์ค„์ด๊ณ , ๋” ๋งŽ์€ ์‚ฌ์šฉ์ž๊ฐ€ ๋™์‹œ์— ํ˜‘์—…ํ•  ์ˆ˜ ์žˆ๋Š” ์‹œ์Šคํ…œ์ด ๊ฐ€๋Šฅํ•ด์งˆ ๊ฑฐ์•ผ.
์‹ค์‹œ๊ฐ„ ํ˜‘์—…์˜ ๋ฏธ๋ž˜ AI ์ง€๋Šฅํ˜• ์ถฉ๋Œ ํ•ด๊ฒฐ Blockchain ๋ถ„์‚ฐ ํ˜‘์—… AR/VR 3D ํ˜‘์—… ๊ณต๊ฐ„ ๋” ๋น ๋ฅด๊ณ , ๋” ์Šค๋งˆํŠธํ•˜๊ณ , ๋” ์ž์—ฐ์Šค๋Ÿฌ์šด ์‹ค์‹œ๊ฐ„ ํ˜‘์—…์˜ ์‹œ๋Œ€๊ฐ€ ์—ด๋ฆฝ๋‹ˆ๋‹ค

๐Ÿ’ผ ์‹ค๋ฌด ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ

์ด์ œ ์‹ค์ œ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•  ์ค€๋น„๊ฐ€ ๋์–ด! ๋‹จ๊ณ„๋ณ„๋กœ ์–ด๋–ป๊ฒŒ ์ง„ํ–‰ํ•˜๋ฉด ์ข‹์„์ง€ ์ •๋ฆฌํ•ด๋ณผ๊ฒŒ. ๐ŸŽฏ

๐Ÿ“‹ ํ”„๋กœ์ ํŠธ ์ฒดํฌ๋ฆฌ์ŠคํŠธ
1๋‹จ๊ณ„: ์š”๊ตฌ์‚ฌํ•ญ ๋ถ„์„ โœ… ๋™์‹œ ์‚ฌ์šฉ์ž ์ˆ˜ ์˜ˆ์ƒ
โœ… ๋ฌธ์„œ ํฌ๊ธฐ ๋ฒ”์œ„
โœ… ํ•„์š”ํ•œ ๊ธฐ๋Šฅ (ํ…์ŠคํŠธ, ์„œ์‹, ์ด๋ฏธ์ง€ ๋“ฑ)
โœ… ์˜คํ”„๋ผ์ธ ์ง€์› ํ•„์š” ์—ฌ๋ถ€
โœ… ์„ฑ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ (์ง€์—ฐ์‹œ๊ฐ„, ์ฒ˜๋ฆฌ๋Ÿ‰)
โœ… ๋ณด์•ˆ ์š”๊ตฌ์‚ฌํ•ญ
2๋‹จ๊ณ„: ๊ธฐ์ˆ  ์Šคํƒ ์„ ํƒ ํ”„๋ก ํŠธ์—”๋“œ: React/Vue/Svelte + WebSocket
๋ฐฑ์—”๋“œ: Node.js/Go/Rust + Redis/PostgreSQL
์ธํ”„๋ผ: AWS/GCP/Azure + CDN
๋ชจ๋‹ˆํ„ฐ๋ง: Prometheus + Grafana
3๋‹จ๊ณ„: MVP ๊ฐœ๋ฐœ โœ… ๊ธฐ๋ณธ ํ…์ŠคํŠธ ํŽธ์ง‘
โœ… ์‹ค์‹œ๊ฐ„ ๋™๊ธฐํ™”
โœ… ๊ฐ„๋‹จํ•œ ์ถฉ๋Œ ํ•ด๊ฒฐ
โœ… ์‚ฌ์šฉ์ž ์ธ์ฆ
โœ… ๊ธฐ๋ณธ UI/UX
4๋‹จ๊ณ„: ํ…Œ์ŠคํŠธ ๋ฐ ์ตœ์ ํ™” โœ… ๋‹จ์œ„ ํ…Œ์ŠคํŠธ
โœ… ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ
โœ… ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ
โœ… ์„ฑ๋Šฅ ํ”„๋กœํŒŒ์ผ๋ง
โœ… ๋ณด์•ˆ ๊ฐ์‚ฌ
5๋‹จ๊ณ„: ๋ฐฐํฌ ๋ฐ ๋ชจ๋‹ˆํ„ฐ๋ง โœ… CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ•
โœ… ์Šคํ…Œ์ด์ง• ํ™˜๊ฒฝ ํ…Œ์ŠคํŠธ
โœ… ํ”„๋กœ๋•์…˜ ๋ฐฐํฌ
โœ… ์‹ค์‹œ๊ฐ„ ๋ชจ๋‹ˆํ„ฐ๋ง ์„ค์ •
โœ… ์‚ฌ์šฉ์ž ํ”ผ๋“œ๋ฐฑ ์ˆ˜์ง‘
๐Ÿ’ก ์žฌ๋Šฅ๋„ท์—์„œ ํ˜‘์—…ํ•˜๊ธฐ: ํ˜ผ์ž์„œ ๋ชจ๋“  ๊ฑธ ๊ฐœ๋ฐœํ•˜๊ธฐ ์–ด๋ ต๋‹ค๋ฉด ์žฌ๋Šฅ๋„ท(https://www.jaenung.net)์—์„œ ํŒ€์›์„ ์ฐพ์•„๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์•ผ! ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž, ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž, UI/UX ๋””์ž์ด๋„ˆ ๋“ฑ ํ•„์š”ํ•œ ์—ญํ• ์˜ ์ „๋ฌธ๊ฐ€๋“ค๊ณผ ํ˜‘์—…ํ•  ์ˆ˜ ์žˆ์–ด. ๋˜ํ•œ ์™„์„ฑ๋œ ํ”„๋กœ์ ํŠธ๋ฅผ ์žฌ๋Šฅ๋„ท์—์„œ ์„œ๋น„์Šค๋กœ ์ œ๊ณตํ•  ์ˆ˜๋„ ์žˆ์ง€! ๐Ÿค

๐ŸŽ“ ํ•™์Šต ๋ฆฌ์†Œ์Šค์™€ ์ฐธ๊ณ  ์ž๋ฃŒ

๋” ๊นŠ์ด ๊ณต๋ถ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด ์ž๋ฃŒ๋“ค์„ ์ฐธ๊ณ ํ•ด๋ด! ๐Ÿ“š

๐Ÿ“– ํ•„์ˆ˜ ๋…ผ๋ฌธ: 1. "Operational Transformation in Real-Time Group Editors" - Ellis & Gibbs (1989)
2. "Consistency Maintenance in Real-Time Collaborative Graphics Editing Systems" - Sun et al. (1998)
3. "A Comprehensive Study of Convergent and Commutative Replicated Data Types" - Shapiro et al. (2011)
4. "Conflict-free Replicated Data Types" - Shapiro et al. (2011)
๐Ÿ”ง ์˜คํ”ˆ์†Œ์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ: ShareDB: ์‹ค์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค + OT ์—”์ง„
Yjs: CRDT ๊ธฐ๋ฐ˜ ํ˜‘์—… ํ”„๋ ˆ์ž„์›Œํฌ
Automerge: JSON CRDT ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
Quill: ๋ฆฌ์น˜ ํ…์ŠคํŠธ ์—๋””ํ„ฐ
ProseMirror: ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ํ…์ŠคํŠธ ์—๋””ํ„ฐ
๐ŸŽฅ ์ถ”์ฒœ ๊ฐ•์˜: - "Distributed Systems" - MIT OpenCourseWare
- "Real-Time Collaboration" - Frontend Masters
- "Building Collaborative Applications" - Pluralsight
๐ŸŒ ์ปค๋ฎค๋‹ˆํ‹ฐ: - CRDT.tech - CRDT ์ „๋ฌธ ์ปค๋ฎค๋‹ˆํ‹ฐ
- Collaborative Editing Research Group
- WebRTC Community
- Real-Time Web Technologies Forum

๐ŸŽฏ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์™€! ์ •๋ง ๊ธด ์—ฌ์ •์ด์—ˆ์ง€? ๐Ÿ˜… ์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๋„๊ตฌ ๊ฐœ๋ฐœ์€ ์‰ฝ์ง€ ์•Š์ง€๋งŒ, ์ •๋ง ํฅ๋ฏธ์ง„์ง„ํ•œ ๋ถ„์•ผ์•ผ. ์šฐ๋ฆฌ๊ฐ€ ์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ด๋ณด์ž:

๐ŸŽ“ ํ•ต์‹ฌ ๊ฐœ๋… ์š”์•ฝ: 1. OT ์•Œ๊ณ ๋ฆฌ์ฆ˜: ๋™์‹œ ์ž‘์—…์„ ๋ณ€ํ™˜ํ•ด์„œ ์ถฉ๋Œ ์—†์ด ๋ณ‘ํ•ฉ
2. ๋ณ€ํ™˜ ํ•จ์ˆ˜: Insert-Insert, Insert-Delete, Delete-Delete ๋“ฑ์˜ ์ผ€์ด์Šค ์ฒ˜๋ฆฌ
3. ์ˆ˜๋ ด์„ฑ ๋ณด์žฅ: ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋™์ผํ•œ ์ตœ์ข… ์ƒํƒœ ๋„๋‹ฌ
4. ์„ฑ๋Šฅ ์ตœ์ ํ™”: ๋ฐฐ์นญ, ์••์ถ•, ์บ์‹ฑ ๋“ฑ์˜ ๊ธฐ๋ฒ• ํ™œ์šฉ
5. ์ถฉ๋Œ ํ•ด๊ฒฐ: ์ž๋™ ํ•ด๊ฒฐ๊ณผ ์ˆ˜๋™ ํ•ด๊ฒฐ์˜ ๊ท ํ˜•
6. ํ…Œ์ŠคํŠธ: ์ฒ ์ €ํ•œ ํ…Œ์ŠคํŠธ๋กœ ์•ˆ์ •์„ฑ ํ™•๋ณด

์‹ค์‹œ๊ฐ„ ํ˜‘์—… ๊ธฐ์ˆ ์€ ์•ž์œผ๋กœ ๋”์šฑ ์ค‘์š”ํ•ด์งˆ ๊ฑฐ์•ผ. ์›๊ฒฉ ๊ทผ๋ฌด๊ฐ€ ์ผ์ƒํ™”๋˜๊ณ , ์ „ ์„ธ๊ณ„ ์‚ฌ๋žŒ๋“ค์ด ํ•จ๊ป˜ ์ผํ•˜๋Š” ์‹œ๋Œ€๋‹ˆ๊นŒ. ์ด ๊ธฐ์ˆ ์„ ๋งˆ์Šคํ„ฐํ•˜๋ฉด ์ •๋ง ๋งŽ์€ ๊ธฐํšŒ๊ฐ€ ์—ด๋ฆด ๊ฑฐ์•ผ! ๐Ÿ’ช

์ฒ˜์Œ์—๋Š” ๋ณต์žกํ•ด ๋ณด์ด์ง€๋งŒ, ํ•˜๋‚˜์”ฉ ์ฐจ๊ทผ์ฐจ๊ทผ ๊ตฌํ˜„ํ•˜๋‹ค ๋ณด๋ฉด ์–ด๋А์ƒˆ ์™„์„ฑ๋œ ํ˜‘์—… ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์„ ๊ฑฐ์•ผ. ํฌ๊ธฐํ•˜์ง€ ๋ง๊ณ  ๊ณ„์† ๋„์ „ํ•ด๋ด! ๐Ÿš€

โš ๏ธ ๋งˆ์ง€๋ง‰ ์กฐ์–ธ: ์‹ค์ œ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ๋Š” ๋ณด์•ˆ, ํ™•์žฅ์„ฑ, ์•ˆ์ •์„ฑ์ด ๋งค์šฐ ์ค‘์š”ํ•ด. ์‚ฌ์šฉ์ž ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฃจ๋Š” ๋งŒํผ ์ฑ…์ž„๊ฐ์„ ๊ฐ€์ง€๊ณ  ๊ฐœ๋ฐœํ•ด์•ผ ํ•ด. ํ•ญ์ƒ ์ตœ์‹  ๋ณด์•ˆ ํŒจ์น˜๋ฅผ ์ ์šฉํ•˜๊ณ , ์ •๊ธฐ์ ์œผ๋กœ ๋ฐฑ์—…ํ•˜๊ณ , ๋ชจ๋‹ˆํ„ฐ๋ง์„ ์ฒ ์ €ํžˆ ํ•˜์ž!

์ด ๊ธ€์ด ๋„์›€์ด ๋๋‹ค๋ฉด ์ •๋ง ๊ธฐ์  ๊ฒƒ ๊ฐ™์•„! ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๊ฑฐ๋‚˜ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์–ด๋ ค์›€์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“ ์ง€ ์ปค๋ฎค๋‹ˆํ‹ฐ์— ์งˆ๋ฌธํ•ด๋ด. ์šฐ๋ฆฌ ๋ชจ๋‘ ํ•จ๊ป˜ ์„ฑ์žฅํ•˜๋Š” ๊ฑฐ๋‹ˆ๊นŒ! ๐Ÿ˜Š

๊ทธ๋Ÿผ ํ–‰์šด์„ ๋นŒ์–ด! ๋ฉ‹์ง„ ํ˜‘์—… ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ํ™”์ดํŒ…! ๐ŸŽ‰โœจ

๐ŸŒŸ ๋‹น์‹ ์˜ ํ˜‘์—… ๋„๊ตฌ ๊ฐœ๋ฐœ ์—ฌ์ •์„ ์‘์›ํ•ฉ๋‹ˆ๋‹ค! ๐ŸŒŸ

Keep coding, keep collaborating! ๐Ÿ’ป๐Ÿค

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.