123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
- <html>
- <!-- Created on December 10, 2012 by texi2html 1.82
- texi2html was written by:
- Lionel Cons <[email protected]> (original author)
- Karl Berry <[email protected]>
- Olaf Bachmann <[email protected]>
- and many others.
- Maintained by: Many creative people.
- Send bugs and suggestions to <[email protected]>
- -->
- <head>
- <title>avram - a virtual machine code interpreter: 3.1.5 Comparison</title>
- <meta name="description" content="avram - a virtual machine code interpreter: 3.1.5 Comparison">
- <meta name="keywords" content="avram - a virtual machine code interpreter: 3.1.5 Comparison">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="texi2html 1.82">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.smallquotation {font-size: smaller}
- pre.display {font-family: serif}
- pre.format {font-family: serif}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: serif; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: serif; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.roman {font-family:serif; font-weight:normal;}
- span.sansserif {font-family:sans-serif; font-weight:normal;}
- ul.toc {list-style: none}
- -->
- </style>
- </head>
- <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
- <a name="Comparison"></a>
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Related-utility-functions.html#Related-utility-functions" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Deconstruction-Functions.html#Deconstruction-Functions" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="Lists.html#Lists" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <hr size="1">
- <a name="Comparison-1"></a>
- <h3 class="subsection">3.1.5 Comparison</h3>
- <p>The file ‘<tt>compare.h</tt>’ contains a few function declarations
- pertaining to the computation of the comparison predicate described in
- <a href="Compare.html#Compare">Compare</a>. Some of the work is done by static functions in
- ‘<tt>compare.c</tt>’ that are not recommended entry points to the library.
- </p>
- <dl>
- <dt><a name="index-avm_005finitialize_005fcompare"></a><u>Function:</u> void <b>avm_initialize_compare</b><i> ()</i></dt>
- <dd><a name="index-compare-1"></a>
- <p>This function should be called once before the first call to
- <code>avm_comparison</code>, as it initializes some necessary internal data
- structures.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fcount_005fcompare"></a><u>Function:</u> void <b>avm_count_compare</b><i> ()</i></dt>
- <dd><p>This function can be used to check for memory leaks, by detecting
- unreclaimed storage at the end of a run. The data structures relevant to
- comparison that could be reported as unreclaimed are known as “decision”
- nodes, but these should always be handled properly by the library
- without intervention. If <code>avm_count_lists</code> is also being used, the
- call to this function must precede it.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fcomparison"></a><u>Function:</u> list <b>avm_comparison</b><i> (list <var>operand</var>, int *<var>fault</var>)</i></dt>
- <dd><p>This function takes a list operand representing a pair of trees and
- returns a list representing the logical value of their equality. If the
- operand is <code>NULL</code>, a message of invalid comparison is returned and
- the <code>*<var>fault</var></code> is set to a non-zero value. If the <code>head</code> of the
- operand is unequal to the <code>tail</code>, a <code>NULL</code> value is
- returned. If they are equal, a list is returned whose <code>head</code> and
- <code>tail</code> are both <code>NULL</code>. The equality in question is structural
- <a name="index-pointer-equality-1"></a>
- rather than pointer equality.
- </p>
- <p>The list operand to this function may be modified by this function, but
- not in a way that should make any difference to a client program. If two
- lists are found to be equal, or if even two sublists are found to be
- equal in the course of the comparison, one of them is deallocated and
- made to point to the other. This action saves memory and may make
- subsequent comparisons faster. However, it could disrupt client programs
- <a name="index-pointers-3"></a>
- that happen to be holding stale list pointers.
- </p>
- <a name="index-discontiguous-field"></a>
- <p>As of <code>avram</code> version 0.6.0, a logical field called
- <code>discontiguous</code> has been added to the <code>node</code> record type
- declared in <code>lists.h</code>, which is checked by the comparison
- function. If a list node has its <code>discontiguous</code> field set to a
- non-zero value, and if it also has a non-null <code>value</code> field, then
- it won’t be deallocated in the course of comparison even if it is
- found to be equal to something else. This feature can be used by
- client modules to create lists in which value fields refer to data
- structures that are meant to exist independently of them. See
- ‘<tt>mpfr.c</tt>’ for an example.
- </p>
- <p>This function is likely to have better performance and memory usage than
- a naive implementation of comparison, for the above reasons and also
- because of optimizations pertaining to comparison of lists representing
- characters. Moreover, it is not subject to stack overflow exceptions
- <a name="index-recursion-4"></a>
- because it is not written in a recursive style.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fbinary_005fcomparison"></a><u>Function:</u> list <b>avm_binary_comparison</b><i> (list <var>left_operand</var>, list <var>right_operand</var>, int *<var>fault</var>);</i></dt>
- <dd><p>This function is the same as <code>avm_comparison</code> except that it
- allows the left and right operands to be passed as separate lists
- rather than taking them from the <code>head</code> and the <code>tail</code> of a
- single list.
- </p></dd></dl>
- <hr size="1">
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Related-utility-functions.html#Related-utility-functions" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Deconstruction-Functions.html#Deconstruction-Functions" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="Lists.html#Lists" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <p>
- <font size="-1">
- This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
- </font>
- <br>
- </p>
- </body>
- </html>
|