Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
needful thing for marriage
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
wonderful-panda
May 21, 2014
Programming
440
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
needful thing for marriage
wonderful-panda
May 21, 2014
Other Decks in Programming
See All in Programming
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
270
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
golang-bob.pdf
iwatsukayura
0
130
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
150
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
気持ちぃ〜角丸 Squircle
ryu1013
0
310
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Navigating Weather and Climate Data
rabernat
0
560
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Documentation Writing (for coders)
carmenintech
77
5.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Building an army of robots
kneath
307
47k
Thoughts on Productivity
jonyablonski
76
5.4k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Transcript
結婚生活に 必要なこと IS
お互いの違いを認め 尊重しあうこと
というわけで diff のはなしをします
今さら聞けない Patience Diff
Patience Diff • Bazaar の Diff アルゴリズム • Bram Cohen
によって書かれた • “Patience” is ソリティア •なんか賢いらしい
↓ こうではなくて ↓ ちゃんとこうなる
Python implementation in Bazaar _patiencediff_py.py http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/view /head:/bzrlib/_patiencediff_py.py •実質 200 行弱
•Python 知らなくても割と読める •bzrlib 内には、 C による実装もあり ( たいてい 実際に使われるのはこっち )
How it work ?
// 会場を計算する int Fact(int n) { if (n == 1)
return 1; else return Fact(n-1)*n; } // フィボナッチを計算する int Fib(int n) { if (n == 0 || n == 1) return 1; else return Fib(n-1)+Fib(n-2); } // 階乗を計算する int Fact(int n) { Assert(n >= 0); if (n>0) return Fact(n-1)*n; return 1; } この2つのテキストを比較してみる
// 会場を計算する int Fact(int n) { if (n == 1)
return 1; else return Fact(n-1)*n; } // フィボナッチを計算する int Fib(int n) { if (n == 0 || n == 1) return 1; else return Fib(n-1)+Fib(n-2); } // 階乗を計算する int Fact(int n) { Assert(n >= 0); if (n>0) return Fact(n-1)*n; return 1; } まず、同じ行同士をマッチング ただし 2回以上出現する行は 無視する 繰り返し出現するパターンを無視することで、 { や } などのノイズが意図せずマッチして おかしな Diff になることを防ぐことができる
// 会場を計算する int Fact(int n) { if (n == 1)
return 1; else return Fact(n-1)*n; } // フィボナッチを計算する int Fib(int n) { if (n == 0 || n == 1) return 1; else return Fib(n-1)+Fib(n-2); } // 階乗を計算する int Fact(int n) { Assert(n >= 0); if (n>0) return Fact(n-1)*n; return 1; } マッチング結果から、互いに交差しないもの同士でなる 最大の部分集合を選ぶ → 今回の場合はこの3本 これを導くための手順がソリティア っぽいということで、 Patience Diff と呼ぶ
1 2 3 4 5 6 7 8 0 1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 ソリティアっぽいってどういうこと? 重ならない線の組み合わせを選ぶとは、 右側の行番号を左側の順に並べたリスト [9, 4, 5, 13] から、最長の単調増加部分列 [4, 5, 13] を 抽出するということ ( 部分列は連続している必要 はない ) ソリティアっぽいってどういうこと?
その処理を適当な数列に対して実施してみる。 3 5 2 7 1 6 9 4 8
0 これをカードの束に見立てて、以下の通りに左から順に場に出していき、いくつ かのカードの山を作る。 3 5 1.まず [3] を出して、場に山を一つ作る。 2.次に [5] を出す。場に山がある場合は、各山のてっぺんのカードとこ れから出すカードを比べて、これから出すカードが一番大きければ右 端に新しい山を作り、より大きい数字の山があればその山に乗せる ( 該当する山が複数ある場合は、その中で数字が最小のものを選ぶ ) 今回は場に [3] の山しかないので、 [5] は新しい山になる。 3.場に新しいカードを出した場合は、その時点で左隣の山が何番だった か憶えておく ( 今回は [5]→[3]) 4.次に [2] を出す。山は [3][5] なので、 [3] の山に乗せる。 5.次は [7] を出す。 [7] は新しい山になり、 [7]→[5] の関係が記憶 される。 6.この要領で最後までカードを出すと、右図のような4つの山ができ る。一番右の山のてっぺん [8] からリンクをたどると、 [8, 6, 5, 3] という数列が得られる。 7.得られた数列をひっくり返して、 [3, 5, 6, 8] が求める答え。 2 7 4 1 9 6 8 0
ソリティアっぽいってどういうこと? alfedenzo: Patience Diff, a brief summary http://alfedenzo.livejournal.com/170301.html
// 会場を計算する int Fact(int n) { if (n == 1)
return 1; else return Fact(n-1)*n; } // フィボナッチを計算する int Fib(int n) { if (n == 0 || n == 1) return 1; else return Fib(n-1)+Fib(n-2); } // 階乗を計算する int Fact(int n) { Assert(n >= 0); if (n>0) return Fact(n-1)*n; return 1; } これでこの3行が同一行としてマークされたので
// 会場を計算する int Fact(int n) { if (n == 1)
return 1; else return Fact(n-1)*n; } // フィボナッチを計算する int Fib(int n) { if (n == 0 || n == 1) return 1; else return Fib(n-1)+Fib(n-2); } // 階乗を計算する int Fact(int n) { Assert(n >= 0); if (n>0) return Fact(n-1)*n; return 1; } 残った各ブロックに対して、再帰的に同様の処理を していく
VCS での利用
git git diff --patience Mercurial PatienceExtension( 死んでる? ) Bazaar By
default
参考 bramcohen: Patience Diff Advantages http://bramcohen.livejournal.com/73318.html Journal of a Programmer:
Patience Diff http://bryanpendleton.blogspot.jp/2010/05/patience-diff.html alfedenzo: Patience Diff, a brief summary http://alfedenzo.livejournal.com/170301.html