UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

67 lines (59 loc) 11.1 kB
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>Diff algorithm &mdash; The CiaoPP Program Processor v1.5</title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">&#9776;</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-logo_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="incanal.html">&#x2191;</a><a class="lpdoc-navbutton" href="tarjan_inc.html">&#x2190;</a><a class="lpdoc-navbutton" href="fixpo_dd.html">&#x2192;</a><a class="lpdoc-navbutton" href="ciaopp_ref_mansearch.html">&#x1F50D;</a></span><span><a href="ciaopp_ref_manfulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="ciaopp_ref_man.html">The CiaoPP Program Processor</a> &raquo;<br/> </li><li><a href="part_internals.html">PART IV - CiaoPP Internals</a> &raquo;<br/> </li><li><a href="incanal.html">Incremental analysis (high level)</a> &raquo;<br/> </li><li><a href=""><strong>Diff algorithm</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Complexity">Complexity</a></li><li><a href="#Pseudocode">Pseudocode</a></li><li><a href="#Example">Example</a></li><li><a href="#Patch">Patch</a></li><li><a href="#Usage and interface">Usage and interface</a></li><li><a href="#Documentation on exports">Documentation on exports</a></li><li><a href="#Documentation on imports">Documentation on imports</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>Diff algorithm</h1><a class="lpdoc-idx-anchor" href="ciaopp_ref_mansearch.html#diff"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="Isabel Garcia-Contreras" href="ciaopp_ref_mansearch.html#Isabel Garcia-Contreras">Isabel Garcia-Contreras</a>, <a class="lpdoc-idx-anchor" id="Jose F. Morales" href="ciaopp_ref_mansearch.html#Jose F. Morales">Jose F. Morales</a>.<p> This module implements Eugene Myers&apos; Greedy Difference Algorithm described in &apos;An O(ND) Difference Algorithm and Its Variations&apos; [<a class="lpdoc-idx-anchor" id="0" href="ciaopp_ref_manrefs.html#myers1986">Mye86</a>].<p>The implementation is parametric in the comparison predicate. This predicate has to succeed if two elements are considered equal.<p><div id="Complexity"><h2>Complexity</h2> <p>This &apos;greedy&apos; algorithm that computes the number differences has complexity O((N+M)D) in both time and space. With M and N the lenghts of the input lists and D the number of changes.<p></div><div id="Pseudocode"><h2>Pseudocode</h2> <p>This pseudocode is copied from the original article, where: <ul> <li><tt>a</tt> and <tt>b</tt> are the input lists of lengths <tt>N</tt> and <tt>M</tt>, <li><tt>k = x - y</tt> and is used to label diagonals, <li><tt>V[k]</tt> contains the row index of the endpoint of a furthest reaching path in diagonal k. </ul> <p><pre class="lpdoc-codeblock">Constant MAX [0,M+N] Var V: Array [-MAX.. MAX] of Integer V[1] = 0 For D = 0 to MAX Do For k = -D to D in steps of 2 Do If k = -D or (k = D and V[k-1] &lt; V[k+1] Then x = V[k+1] Else x = V[k-1] + 1 y = x - k While (x &lt; N, y &lt; M and a(x+1) = b(y+1) Do (x,y) = (x+1,y+1) V[k] = x If (x &gt;= N and y &gt;= M) Then Length of an SES is D Stop Length of an SES is greater than MAX </pre> <p></div><div id="Example"><h2>Example</h2> <p><pre class="lpdoc-codeblock">?- diff([a,a,b,c], [b,c,d], &apos;=&apos;, Diff). Diff = [del(0,a),del(0,a),ins(2,d)] ? yes ?- </pre> <p></div><div id="Patch"><h2>Patch</h2> <p>The patch operation applies a list of changes expressed as <a class="lpdoc-idx-anchor" id="1" href="#diff_item/1"><tt>diff_item/1</tt></a> to obtain a new list. Note that given two lists L1, L2, if their Diff is applied to L1, it will be obtained L2:<p><pre class="lpdoc-codeblock">?- L1 = [a,a,b,c], L2 = [b,c,d], diff(L1, L2, &apos;=&apos;, Diff), patch(L1, Diff, L2). Diff = [del(0,a),del(0,a),ins(2,d)], L1 = [a,a,b,c], L2 = [b,c,d] ? yes ?- </pre> </div><br/><div id="Usage and interface"><h2>Usage and interface</h2><div class="lpdoc-cartouche"><ul><li><strong>Library usage:</strong><br/><tt>:- use_module(library(diff)).</tt><li><strong>Exports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Predicates:</em><br/><a class="lpdoc-idx-anchor" id="2" href="#diff/4"><tt>diff/4</tt></a>, <a class="lpdoc-idx-anchor" id="3" href="#patch/3"><tt>patch/3</tt></a>. <li><em>Regular Types:</em><br/><a class="lpdoc-idx-anchor" id="4" href="#diff_item/1"><tt>diff_item/1</tt></a>. </ul></ul></div></div><div id="Documentation on exports"><h2>Documentation on exports</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="diff/4" href="ciaopp_ref_mansearch.html#diff/4">diff/4</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>diff(Ls1,Ls2,Compare,Diff)</tt> </span><p><span class="lpdoc-var">Diff</span> are the changes needed to transform <span class="lpdoc-var">Ls1</span> into <span class="lpdoc-var">Ls2</span>.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="5" href="basic_props.html#list/1"><tt>list/1</tt></a>)</span><span><span class="lpdoc-var">Ls1</span> is a list. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="6" href="basic_props.html#list/1"><tt>list/1</tt></a>)</span><span><span class="lpdoc-var">Ls2</span> is a list. </span> <li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="7" href="basic_props.html#list/2"><tt>list/2</tt></a>)</span><span><span class="lpdoc-var">Diff</span> is a list of <span class="lpdoc-var">diff_item</span>s. </span> </ul> <em>Meta-predicate</em> with arguments: <tt>diff(?,?,pred(2),?)</tt>.<br/></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="patch/3" href="ciaopp_ref_mansearch.html#patch/3">patch/3</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>patch(Ls,Diff,LNew)</tt> </span><p>Apply a list of changes (<span class="lpdoc-var">Diff</span>) onto a <span class="lpdoc-var">Ls</span>.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="8" href="basic_props.html#list/1"><tt>list/1</tt></a>)</span><span><span class="lpdoc-var">Ls</span> is a list. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="9" href="basic_props.html#list/2"><tt>list/2</tt></a>)</span><span><span class="lpdoc-var">diff_item</span> is a list of <span class="lpdoc-var">Diff</span>s. </span> <li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="10" href="basic_props.html#list/1"><tt>list/1</tt></a>)</span><span><span class="lpdoc-var">LNew</span> is a list. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">REGTYPE</span><a class="lpdoc-idx-anchor" id="diff_item/1" href="ciaopp_ref_mansearch.html#diff_item/1">diff_item/1</a></div><div class="lpdoc-deftext"><span class="lpdoc-usage-decl"><tt>diff_item(X)</tt> </span><p><span class="lpdoc-var">X</span> is an insertion denoted with <a class="lpdoc-idx-anchor" id="11" href="ciaopp_ref_mansearch.html#ins(Pos, Elem)"><tt>ins(Pos, Elem)</tt></a> meaning that <span class="lpdoc-var">Elem</span> has to be inserted in position <span class="lpdoc-var">Pos</span>, or <a class="lpdoc-idx-anchor" id="12" href="ciaopp_ref_mansearch.html#del(Pos, Elem)"><tt>del(Pos, Elem)</tt></a> meaning that <span class="lpdoc-var">Elem</span> has to be removed from position <span class="lpdoc-var">Pos</span>. It is defined as: <pre class="lpdoc-codeblock">diff_item(ins(P,_1)) :- nnegint(P). diff_item(del(P,_1)) :- nnegint(P). </pre><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>diff_item(X)</tt> </span><p><span class="lpdoc-var">X</span> is a single edition in a sequence (insertion or deletion)</p><ul class="lpdoc-itemize-minus"></ul></div></div><p> </div><div id="Documentation on imports"><h2>Documentation on imports</h2>This module has the following direct dependencies:<ul class="lpdoc-itemize-minus"><li><em>System library modules:</em><br/><a class="lpdoc-idx-anchor" id="13" href="ciaopp_ref_mansearch.html#lists"><tt>lists</tt></a>. <li><em>Internal (engine) modules:</em><br/><a class="lpdoc-idx-anchor" id="14" href="ciaopp_ref_mansearch.html#term_basic"><tt>term_basic</tt></a>, <a class="lpdoc-idx-anchor" id="15" href="ciaopp_ref_mansearch.html#arithmetic"><tt>arithmetic</tt></a>, <a class="lpdoc-idx-anchor" id="16" href="ciaopp_ref_mansearch.html#atomic_basic"><tt>atomic_basic</tt></a>, <a class="lpdoc-idx-anchor" id="17" href="ciaopp_ref_mansearch.html#basiccontrol"><tt>basiccontrol</tt></a>, <a class="lpdoc-idx-anchor" id="18" href="ciaopp_ref_mansearch.html#exceptions"><tt>exceptions</tt></a>, <a class="lpdoc-idx-anchor" id="19" href="ciaopp_ref_mansearch.html#term_compare"><tt>term_compare</tt></a>, <a class="lpdoc-idx-anchor" id="20" href="ciaopp_ref_mansearch.html#term_typing"><tt>term_typing</tt></a>, <a class="lpdoc-idx-anchor" id="21" href="ciaopp_ref_mansearch.html#debugger_support"><tt>debugger_support</tt></a>, <a class="lpdoc-idx-anchor" id="22" href="basic_props.html"><tt>basic_props</tt></a>, <a class="lpdoc-idx-anchor" id="23" href="ciaopp_ref_mansearch.html#hiord_rt"><tt>hiord_rt</tt></a>. <li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="24" href="ciaopp_ref_mansearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="25" href="ciaopp_ref_mansearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="26" href="ciaopp_ref_mansearch.html#condcomp"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="27" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="28" href="ciaopp_ref_mansearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>, <a class="lpdoc-idx-anchor" id="29" href="ciaopp_ref_mansearch.html#hiord"><tt>hiord</tt></a>, <a class="lpdoc-idx-anchor" id="30" href="regtypes_doc.html"><tt>regtypes</tt></a>. </ul></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>