Comparison.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
  2. <html>
  3. <!-- Created on November 8, 2012 by texi2html 1.82
  4. texi2html was written by:
  5. Lionel Cons <[email protected]> (original author)
  6. Karl Berry <[email protected]>
  7. Olaf Bachmann <[email protected]>
  8. and many others.
  9. Maintained by: Many creative people.
  10. Send bugs and suggestions to <[email protected]>
  11. -->
  12. <head>
  13. <title>avram - a virtual machine code interpreter: 3.1.5 Comparison</title>
  14. <meta name="description" content="avram - a virtual machine code interpreter: 3.1.5 Comparison">
  15. <meta name="keywords" content="avram - a virtual machine code interpreter: 3.1.5 Comparison">
  16. <meta name="resource-type" content="document">
  17. <meta name="distribution" content="global">
  18. <meta name="Generator" content="texi2html 1.82">
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <style type="text/css">
  21. <!--
  22. a.summary-letter {text-decoration: none}
  23. blockquote.smallquotation {font-size: smaller}
  24. pre.display {font-family: serif}
  25. pre.format {font-family: serif}
  26. pre.menu-comment {font-family: serif}
  27. pre.menu-preformatted {font-family: serif}
  28. pre.smalldisplay {font-family: serif; font-size: smaller}
  29. pre.smallexample {font-size: smaller}
  30. pre.smallformat {font-family: serif; font-size: smaller}
  31. pre.smalllisp {font-size: smaller}
  32. span.roman {font-family:serif; font-weight:normal;}
  33. span.sansserif {font-family:sans-serif; font-weight:normal;}
  34. ul.toc {list-style: none}
  35. -->
  36. </style>
  37. </head>
  38. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  39. <a name="Comparison"></a>
  40. <table cellpadding="1" cellspacing="1" border="0">
  41. <tr><td valign="middle" align="left">[<a href="Related-utility-functions.html#Related-utility-functions" title="Previous section in reading order"> &lt; </a>]</td>
  42. <td valign="middle" align="left">[<a href="Deconstruction-Functions.html#Deconstruction-Functions" title="Next section in reading order"> &gt; </a>]</td>
  43. <td valign="middle" align="left"> &nbsp; </td>
  44. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  45. <td valign="middle" align="left">[<a href="Lists.html#Lists" title="Up section"> Up </a>]</td>
  46. <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> &gt;&gt; </a>]</td>
  47. <td valign="middle" align="left"> &nbsp; </td>
  48. <td valign="middle" align="left"> &nbsp; </td>
  49. <td valign="middle" align="left"> &nbsp; </td>
  50. <td valign="middle" align="left"> &nbsp; </td>
  51. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  52. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  53. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  54. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  55. </tr></table>
  56. <hr size="1">
  57. <a name="Comparison-1"></a>
  58. <h3 class="subsection">3.1.5 Comparison</h3>
  59. <p>The file &lsquo;<tt>compare.h</tt>&rsquo; contains a few function declarations
  60. pertaining to the computation of the comparison predicate described in
  61. <a href="Compare.html#Compare">Compare</a>. Some of the work is done by static functions in
  62. &lsquo;<tt>compare.c</tt>&rsquo; that are not recommended entry points to the library.
  63. </p>
  64. <dl>
  65. <dt><a name="index-avm_005finitialize_005fcompare"></a><u>Function:</u> void <b>avm_initialize_compare</b><i> ()</i></dt>
  66. <dd><a name="index-compare-1"></a>
  67. <p>This function should be called once before the first call to
  68. <code>avm_comparison</code>, as it initializes some necessary internal data
  69. structures.
  70. </p></dd></dl>
  71. <dl>
  72. <dt><a name="index-avm_005fcount_005fcompare"></a><u>Function:</u> void <b>avm_count_compare</b><i> ()</i></dt>
  73. <dd><p>This function can be used to check for memory leaks, by detecting
  74. unreclaimed storage at the end of a run. The data structures relevant to
  75. comparison that could be reported as unreclaimed are known as &ldquo;decision&rdquo;
  76. nodes, but these should always be handled properly by the library
  77. without intervention. If <code>avm_count_lists</code> is also being used, the
  78. call to this function must precede it.
  79. </p></dd></dl>
  80. <dl>
  81. <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>
  82. <dd><p>This function takes a list operand representing a pair of trees and
  83. returns a list representing the logical value of their equality. If the
  84. operand is <code>NULL</code>, a message of invalid comparison is returned and
  85. the <code>*<var>fault</var></code> is set to a non-zero value. If the <code>head</code> of the
  86. operand is unequal to the <code>tail</code>, a <code>NULL</code> value is
  87. returned. If they are equal, a list is returned whose <code>head</code> and
  88. <code>tail</code> are both <code>NULL</code>. The equality in question is structural
  89. <a name="index-pointer-equality-1"></a>
  90. rather than pointer equality.
  91. </p>
  92. <p>The list operand to this function may be modified by this function, but
  93. not in a way that should make any difference to a client program. If two
  94. lists are found to be equal, or if even two sublists are found to be
  95. equal in the course of the comparison, one of them is deallocated and
  96. made to point to the other. This action saves memory and may make
  97. subsequent comparisons faster. However, it could disrupt client programs
  98. <a name="index-pointers-3"></a>
  99. that happen to be holding stale list pointers.
  100. </p>
  101. <a name="index-discontiguous-field"></a>
  102. <p>As of <code>avram</code> version 0.6.0, a logical field called
  103. <code>discontiguous</code> has been added to the <code>node</code> record type
  104. declared in <code>lists.h</code>, which is checked by the comparison
  105. function. If a list node has its <code>discontiguous</code> field set to a
  106. non-zero value, and if it also has a non-null <code>value</code> field, then
  107. it won&rsquo;t be deallocated in the course of comparison even if it is
  108. found to be equal to something else. This feature can be used by
  109. client modules to create lists in which value fields refer to data
  110. structures that are meant to exist independently of them. See
  111. &lsquo;<tt>mpfr.c</tt>&rsquo; for an example.
  112. </p>
  113. <p>This function is likely to have better performance and memory usage than
  114. a naive implementation of comparison, for the above reasons and also
  115. because of optimizations pertaining to comparison of lists representing
  116. characters. Moreover, it is not subject to stack overflow exceptions
  117. <a name="index-recursion-4"></a>
  118. because it is not written in a recursive style.
  119. </p></dd></dl>
  120. <dl>
  121. <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>
  122. <dd><p>This function is the same as <code>avm_comparison</code> except that it
  123. allows the left and right operands to be passed as separate lists
  124. rather than taking them from the <code>head</code> and the <code>tail</code> of a
  125. single list.
  126. </p></dd></dl>
  127. <hr size="1">
  128. <table cellpadding="1" cellspacing="1" border="0">
  129. <tr><td valign="middle" align="left">[<a href="Related-utility-functions.html#Related-utility-functions" title="Previous section in reading order"> &lt; </a>]</td>
  130. <td valign="middle" align="left">[<a href="Deconstruction-Functions.html#Deconstruction-Functions" title="Next section in reading order"> &gt; </a>]</td>
  131. <td valign="middle" align="left"> &nbsp; </td>
  132. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  133. <td valign="middle" align="left">[<a href="Lists.html#Lists" title="Up section"> Up </a>]</td>
  134. <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> &gt;&gt; </a>]</td>
  135. <td valign="middle" align="left"> &nbsp; </td>
  136. <td valign="middle" align="left"> &nbsp; </td>
  137. <td valign="middle" align="left"> &nbsp; </td>
  138. <td valign="middle" align="left"> &nbsp; </td>
  139. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  140. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  141. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  142. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  143. </tr></table>
  144. <p>
  145. <font size="-1">
  146. This document was generated on <i>November 8, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
  147. </font>
  148. <br>
  149. </p>
  150. </body>
  151. </html>