moonpool/dev/ocaml/Diffing_with_keys/index.html
2023-08-28 17:11:38 +00:00

2 lines
No EOL
9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Diffing_with_keys (ocaml.Diffing_with_keys)</title><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../index.html">ocaml</a> &#x00BB; Diffing_with_keys</nav><header class="odoc-preamble"><h1>Module <code><span>Diffing_with_keys</span></code></h1><p>When diffing lists where each element has a distinct key, we can refine the diffing patch by introducing two composite edit moves: swaps and moves.</p><p><code>Swap</code>s exchange the position of two elements. <code>Swap</code> cost is set to <code>2 * change - epsilon</code>. <code>Move</code>s change the position of one element. <code>Move</code> cost is set to <code>delete + addition - epsilon</code>.</p><p>When the cost <code>delete + addition</code> is greater than <code>change</code> and with those specific weights, the optimal patch with <code>Swap</code>s and <code>Move</code>s can be computed directly and cheaply from the original optimal patch.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-with_pos"><a href="#type-with_pos" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a with_pos</span></span><span> = </span><span>{</span></code><ol><li id="type-with_pos.pos" class="def record field anchored"><a href="#type-with_pos.pos" class="anchor"></a><code><span>pos : int;</span></code></li><li id="type-with_pos.data" class="def record field anchored"><a href="#type-with_pos.data" class="anchor"></a><code><span>data : <span class="type-var">'a</span>;</span></code></li></ol><code><span>}</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-with_pos"><a href="#val-with_pos" class="anchor"></a><code><span><span class="keyword">val</span> with_pos : <span><span><span class="type-var">'a</span> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span><span class="type-var">'a</span> <a href="#type-with_pos">with_pos</a></span> list</span></span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-mismatch"><a href="#type-mismatch" class="anchor"></a><code><span><span class="keyword">type</span> <span>('l, 'r, 'diff) mismatch</span></span><span> = </span></code><ol><li id="type-mismatch.Name" class="def variant constructor anchored"><a href="#type-mismatch.Name" class="anchor"></a><code><span>| </span><span><span class="constructor">Name</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-mismatch.pos" class="def record field anchored"><a href="#type-mismatch.pos" class="anchor"></a><code><span>pos : int;</span></code></li><li id="type-mismatch.got" class="def record field anchored"><a href="#type-mismatch.got" class="anchor"></a><code><span>got : string;</span></code></li><li id="type-mismatch.expected" class="def record field anchored"><a href="#type-mismatch.expected" class="anchor"></a><code><span>expected : string;</span></code></li><li id="type-mismatch.types_match" class="def record field anchored"><a href="#type-mismatch.types_match" class="anchor"></a><code><span>types_match : bool;</span></code></li></ol><code><span>}</span></code></li><li id="type-mismatch.Type" class="def variant constructor anchored"><a href="#type-mismatch.Type" class="anchor"></a><code><span>| </span><span><span class="constructor">Type</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-mismatch.pos" class="def record field anchored"><a href="#type-mismatch.pos" class="anchor"></a><code><span>pos : int;</span></code></li><li id="type-mismatch.got" class="def record field anchored"><a href="#type-mismatch.got" class="anchor"></a><code><span>got : <span class="type-var">'l</span>;</span></code></li><li id="type-mismatch.expected" class="def record field anchored"><a href="#type-mismatch.expected" class="anchor"></a><code><span>expected : <span class="type-var">'r</span>;</span></code></li><li id="type-mismatch.reason" class="def record field anchored"><a href="#type-mismatch.reason" class="anchor"></a><code><span>reason : <span class="type-var">'diff</span>;</span></code></li></ol><code><span>}</span></code></li></ol></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-change"><a href="#type-change" class="anchor"></a><code><span><span class="keyword">type</span> <span>('l, 'r, 'diff) change</span></span><span> = </span></code><ol><li id="type-change.Change" class="def variant constructor anchored"><a href="#type-change.Change" class="anchor"></a><code><span>| </span><span><span class="constructor">Change</span> <span class="keyword">of</span> <span><span>(<span class="type-var">'l</span>, <span class="type-var">'r</span>, <span class="type-var">'diff</span>)</span> <a href="#type-mismatch">mismatch</a></span></span></code></li><li id="type-change.Swap" class="def variant constructor anchored"><a href="#type-change.Swap" class="anchor"></a><code><span>| </span><span><span class="constructor">Swap</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-change.pos" class="def record field anchored"><a href="#type-change.pos" class="anchor"></a><code><span>pos : int * int;</span></code></li><li id="type-change.first" class="def record field anchored"><a href="#type-change.first" class="anchor"></a><code><span>first : string;</span></code></li><li id="type-change.last" class="def record field anchored"><a href="#type-change.last" class="anchor"></a><code><span>last : string;</span></code></li></ol><code><span>}</span></code></li><li id="type-change.Move" class="def variant constructor anchored"><a href="#type-change.Move" class="anchor"></a><code><span>| </span><span><span class="constructor">Move</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-change.name" class="def record field anchored"><a href="#type-change.name" class="anchor"></a><code><span>name : string;</span></code></li><li id="type-change.got" class="def record field anchored"><a href="#type-change.got" class="anchor"></a><code><span>got : int;</span></code></li><li id="type-change.expected" class="def record field anchored"><a href="#type-change.expected" class="anchor"></a><code><span>expected : int;</span></code></li></ol><code><span>}</span></code></li><li id="type-change.Insert" class="def variant constructor anchored"><a href="#type-change.Insert" class="anchor"></a><code><span>| </span><span><span class="constructor">Insert</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-change.pos" class="def record field anchored"><a href="#type-change.pos" class="anchor"></a><code><span>pos : int;</span></code></li><li id="type-change.insert" class="def record field anchored"><a href="#type-change.insert" class="anchor"></a><code><span>insert : <span class="type-var">'r</span>;</span></code></li></ol><code><span>}</span></code></li><li id="type-change.Delete" class="def variant constructor anchored"><a href="#type-change.Delete" class="anchor"></a><code><span>| </span><span><span class="constructor">Delete</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-change.pos" class="def record field anchored"><a href="#type-change.pos" class="anchor"></a><code><span>pos : int;</span></code></li><li id="type-change.delete" class="def record field anchored"><a href="#type-change.delete" class="anchor"></a><code><span>delete : <span class="type-var">'l</span>;</span></code></li></ol><code><span>}</span></code></li></ol></div><div class="spec-doc"><p>This specialized version of changes introduces two composite changes: <code>Move</code> and <code>Swap</code></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-prefix"><a href="#val-prefix" class="anchor"></a><code><span><span class="keyword">val</span> prefix : <span><a href="../Stdlib/Format/index.html#type-formatter">Stdlib.Format.formatter</a> <span class="arrow">&#45;&gt;</span></span> <span><span><span>(<span class="type-var">'l</span>, <span class="type-var">'r</span>, <span class="type-var">'diff</span>)</span> <a href="#type-change">change</a></span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Define"><a href="#module-Define" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Define/index.html">Define</a></span><span> (<a href="Define/argument-1-D/index.html">D</a> : <a href="../Diffing/module-type-Defs/index.html">Diffing.Defs</a> <span class="keyword">with</span> <span><span class="keyword">type</span> <a href="../Diffing/module-type-Defs/index.html#type-eq">eq</a> := unit</span>) : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div></div></body></html>