Diff algorithms എങ്ങനെ പ്രവർത്തിക്കുന്നു
ഈ page-ലെ ഓരോ diff view-ഉം Myers algorithm produce ചെയ്യുന്നു — Eugene W. Myers-ന്റെ 1986 technique, O((N+M)D) time-ൽ രണ്ട് token sequences ഇടയ്ക്ക് shortest edit script കണ്ടെത്തുന്നു. Algorithm Longest Common Subsequence problem-ഉ ചുറ്റി, open-source jsdiff library ഉപയോഗിച്ച് browser-ൽ run ചെയ്യുന്നു.
- Inputs tokenise ചെയ്യൂ — Compare ചെയ്യുന്നതിന് മുൻപ്, algorithm ഓരോ input-ഉം tokens sequence ആക്കി split ചെയ്യുന്നു. Line granularity newlines-ൽ split; word granularity whitespace, punctuation boundaries-ൽ split; character granularity ഓരോ Unicode code point-ഉം സ്വന്തം token.
- Edit graph build ചെയ്യൂ — Myers algorithm comparison-ഒ ഒരു 2D grid-ൽ path ആയി model ചെയ്യുന്നു — right move: original-ൽ നിന്ന് delete, down move: changed-ൽ insert, diagonal move: token രണ്ടിലും match. Algorithm shortest diagonal-heavy path കണ്ടെത്തുന്നു.
- LCS extract ചെയ്യൂ — Shortest path-ൽ diagonal moves Longest Common Subsequence trace ചെയ്യുന്നു — ഒരേ relative order-ൽ രണ്ട് inputs-ഉം appear ആകുന്ന tokens. LCS-ൽ ഓരോ token-ഉം "unchanged"; ബാക്കിയൊക്കെ addition അല്ലെങ്കിൽ deletion.
- Preprocessing options apply ചെയ്യൂ — "Ignore case" enable ചെയ്താൽ LCS pass-ന് മുൻപ് inputs lowercased ആകുന്നു — "HELLO", "hello" identical ആകുന്നു. "Ignore whitespace" multiple spaces ഒന്നാക്കുന്നു. "Trim each line" comparison-ന് മുൻപ് per-line leading/trailing whitespace strip ചെയ്യുന്നു.
- Selected view render ചെയ്യൂ — Output ഒരേ LCS result മൂന്ന് ways-ൽ: Side-by-side left-ൽ original, right-ൽ changed — red/green row highlights ഉള്ള two-column grid. Unified − , + prefix lines ഉള്ള single column —
git diffoutput-ഇ ഒരേ. Inline deletions red strikethrough, additions green underline ആയി ഒരേ text flow-ൽ. - Summary strip compute ചെയ്യൂ — Render ചെയ്ത ശേഷം, ടൂൾ add, remove, unchanged tokens count ചെയ്ത്, similarity ratio unchanged tokens / larger input length ആയി calculate ചെയ്യുന്നു. 100% similarity: preprocessing ശേഷം inputs identical.
Diff checker ഉപയോഗിക്കേണ്ടത് എന്തുകൊണ്ട്
- Git client ഇല്ലാതെ code review — Config file, SQL migration, shell script-ന്റെ രണ്ട് versions paste ചെയ്ത്, repo clone ചെയ്യാതെ, branches switch ചെയ്യാതെ, CI pipeline wait ചെയ്യാതെ — എന്ത് മാറി എന്ന് കാണൂ. Pair programming, contractor handoffs, version control-ഇല്ലാത്ത legacy codebases-ന് useful. Unified view chat thread, ticket-ലേക്ക് directly copy ചെയ്യാൻ കഴിയുന്ന output produce ചെയ്യുന്നു.
- Contract, document redlines — Word-level diff contract drafts ഇടയ്ക്ക് terms shift ആയ് Word-ന്റെ Track Changes panel-നേക്കാൾ വേഗം കാണിക്കുന്നു. First draft-ൽ nിന്നുള്ള clause A, executed copy-ൽ ഉള്ള clause B paste ചെയ്ത് — moved phrase-ൽ exact red-on-green ദൃശ്യമാകുന്നു.
- Essay, draft revisions — First draft, edited version compare ചെയ്യുന്ന writers word granularity-ൽ flip ചെയ്ത് ഓരോ substitution, insertion, cut കാണൂ — copies reread ചെയ്യാതെ. Translators, editors, journalism teams-ഉ ഒരേ workflow.
- Log, config comparison — രണ്ട് server config snapshots, two cron schedules, രണ്ട്
ps auxoutputs compare ചെയ്യുന്ന sysadmins line granularity ഉപയോഗിച്ച് 200-line file-ൽ changed parameter seconds-ൽ locate ചെയ്യൂ. Ignore-whitespace option pair ആക്കൂ, noisy alignment-only diff actual parameter changes ആക്കി collapse ആകുന്നു.
പൊതു ആപ്ലിക്കേഷനുകൾ
Writing, development, operations work-ലെ ഓരോ edit cycle-ഉ അൻ്ററ്റിൽ text diff ഉണ്ടാകും.
- Pull request review: branch checkout overhead ഇല്ലാതെ approve ചെയ്യുന്നതിന് മുൻപ് logic change മനസ്സിലാക്കാൻ രണ്ട് function implementations side by side paste ചെയ്യൂ.
- Internationalisation QA: translator introduce ചെയ്തേക്കാവുന്ന insertions, omissions, terminology swaps detect ചെയ്യാൻ English source string, translated equivalent word level-ൽ compare ചെയ്യൂ.
- Incident analysis: outage-ഉ precede ചെയ്ത configuration change isolate ചെയ്യാൻ രണ്ട് Kubernetes manifest snapshots, "docker inspect" outputs line level-ൽ diff ചെയ്യൂ.
ഒരു ഉദാഹരണം
ഒരു അഞ്ച്-line server config. Original: host=localhost, port=5432, dbname=app_db, user=app, password=secret. Changed: host=db.prod.example.com, port=5432, dbname=app_db, user=app_prod, password=secret. Line granularity, Side-by-side view: line 1 left-ൽ red (host=localhost), right-ൽ green (host=db.prod.example.com); line 4 red (user=app), green (user=app_prod); lines 2, 3, 5 unchanged. Summary strip: 2 additions, 2 deletions, 3 unchanged, 60% similarity. Word granularity-ലേക്ക് switch ചെയ്താൽ diff tighten ആകുന്നു: lines 1, 4-ൽ =-ഉ right-ലുള്ള values മാത്രം light up, keys unchanged, similarity ~85%-ലേക്ക് climb ആകുന്നു.
ഇത് ബ്രൗസറിൽ run ചെയ്യുന്നുണ്ടോ?
അതേ. Diff computation മുഴുവനും open-source jsdiff library ഉപയോഗിച്ച് client-side run ചെയ്യുന്നു. Type, paste, compare ചെയ്യുന്നത് ഒരു server-ഉ send ചെയ്യുന്നില്ല. Verify ചെയ്യൂ: DevTools തുറന്ന് Network tab-ൽ log clear ചെയ്ത്, Compare ക്ലിക്ക് ചെയ്ത്, comparison step-ന് zero network requests confirm ചെയ്യൂ.
Similarity percentage-ന്റെ അർത്ഥം?
Similarity unchanged tokens / max(original total tokens, changed total tokens) ആയി calculate ചെയ്യുന്നു. 100%: preprocessing options ശേഷം inputs identical. 0%: inputs ഇടയ്ക്ക് ഒരു token-ഉം shared ഇല്ല. Metric edit distance-ന്റെ rough approximation — plagiarism, originality score ഇല്ല.
JSON / YAML / XML semantically diff ചെയ്യാൻ കഴിയുമോ?
ഈ ടൂളിൽ ഇല്ല. ഇത് text-level diff — JSON, XML-ന്റെ whitespace-only reformatting data logically identical ആണെങ്കിലും many changes കാണിക്കുന്നു. JSON-ൽ object keys reorder ചെയ്താലും changes ദൃശ്യമാകുന്നു. True semantic diff — parsed object trees compare ചെയ്ത് key order, formatting ignore ചെയ്യുന്ന — ഒരു dedicated JSON Diff ടൂൾ plan ചെയ്യുന്നു. ഇപ്പോൾ, ഇവിടെ paste ചെയ്യുന്നതിന് മുൻപ് inputs ഒരേ indentation, key order-ൽ normalise ചെയ്യൂ.
Unified vs side-by-side views-ന്റെ വ്യത്യാസം?
Side-by-side: two columns — left original, right changed; removed lines left-ൽ red, added lines right-ൽ green. Unchanged lines aligned same row-ൽ. Unified: single column — removed lines-ന് − prefix, red background; added lines-ന് + prefix, green background — terminal-ൽ git diff print ആകുന്നതിനൊക്കെ. Patch file copy ചെയ്യണം, code review thread-ൽ paste ചെയ്യണം: unified. What replaced what-ന്റെ visual alignment raw patch text-നേക്കാൾ important: side-by-side.
Original left-ൽ, changed version right-ൽ paste ചെയ്ത്, view, granularity pick ചെയ്ത്, milliseconds-ൽ comparison. Live mode on ആക്കൂ — ഏത് side-ഉ edit ചെയ്താലും diff ഓരോ keystroke-ഉ rerun ചെയ്യുന്നു. Standard unified .patch file download ചെയ്ത് git apply consume ചെയ്യൂ. Upload ഇല്ല, account ഇല്ല, vendor API key ഇല്ല, quota ഇല്ല.