Comparison.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <html lang="en">
  2. <head>
  3. <title>Comparison - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Lists.html#Lists" title="Lists">
  9. <link rel="prev" href="Type-Conversions.html#Type-Conversions" title="Type Conversions">
  10. <link rel="next" href="Deconstruction-Functions.html#Deconstruction-Functions" title="Deconstruction Functions">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Comparison"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Deconstruction-Functions.html#Deconstruction-Functions">Deconstruction Functions</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Lists.html#Lists">Lists</a>
  32. <hr>
  33. </div>
  34. <h4 class="subsection">3.1.5 Comparison</h4>
  35. <p>The file <samp><span class="file">compare.h</span></samp> contains a few function declarations
  36. pertaining to the computation of the comparison predicate described in
  37. <a href="Compare.html#Compare">Compare</a>. Some of the work is done by static functions in
  38. <samp><span class="file">compare.c</span></samp> that are not recommended entry points to the library.
  39. <div class="defun">
  40. &mdash; Function: void <b>avm_initialize_compare</b> ()<var><a name="index-avm_005finitialize_005fcompare-476"></a></var><br>
  41. <blockquote><p><a name="index-g_t_0040code_007bcompare_007d-477"></a>This function should be called once before the first call to
  42. <code>avm_comparison</code>, as it initializes some necessary internal data
  43. structures.
  44. </p></blockquote></div>
  45. <div class="defun">
  46. &mdash; Function: void <b>avm_count_compare</b> ()<var><a name="index-avm_005fcount_005fcompare-478"></a></var><br>
  47. <blockquote><p>This function can be used to check for memory leaks, by detecting
  48. unreclaimed storage at the end of a run. The data structures relevant to
  49. comparison that could be reported as unreclaimed are known as &ldquo;decision&rdquo;
  50. nodes, but these should always be handled properly by the library
  51. without intervention. If <code>avm_count_lists</code> is also being used, the
  52. call to this function must precede it.
  53. </p></blockquote></div>
  54. <div class="defun">
  55. &mdash; Function: list <b>avm_comparison</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005fcomparison-479"></a></var><br>
  56. <blockquote><p>This function takes a list operand representing a pair of trees and
  57. returns a list representing the logical value of their equality. If the
  58. operand is <code>NULL</code>, a message of invalid comparison is returned and
  59. the <code>*</code><var>fault</var> is set to a non-zero value. If the <code>head</code> of the
  60. operand is unequal to the <code>tail</code>, a <code>NULL</code> value is
  61. returned. If they are equal, a list is returned whose <code>head</code> and
  62. <code>tail</code> are both <code>NULL</code>. The equality in question is structural
  63. <a name="index-pointer-equality-480"></a>rather than pointer equality.
  64. <p>The list operand to this function may be modified by this function, but
  65. not in a way that should make any difference to a client program. If two
  66. lists are found to be equal, or if even two sublists are found to be
  67. equal in the course of the comparison, one of them is deallocated and
  68. made to point to the other. This action saves memory and may make
  69. subsequent comparisons faster. However, it could disrupt client programs
  70. <a name="index-pointers-481"></a>that happen to be holding stale list pointers.
  71. <p><a name="index-discontiguous-field-482"></a>As of <code>avram</code> version 0.6.0, a logical field called
  72. <code>discontiguous</code> has been added to the <code>node</code> record type
  73. declared in <code>lists.h</code>, which is checked by the comparison
  74. function. If a list node has its <code>discontiguous</code> field set to a
  75. non-zero value, and if it also has a non-null <code>value</code> field, then
  76. it won't be deallocated in the course of comparison even if it is
  77. found to be equal to something else. This feature can be used by
  78. client modules to create lists in which value fields refer to data
  79. structures that are meant to exist independently of them. See
  80. <samp><span class="file">mpfr.c</span></samp> for an example.
  81. <p>This function is likely to have better performance and memory usage than
  82. a naive implementation of comparison, for the above reasons and also
  83. because of optimizations pertaining to comparison of lists representing
  84. characters. Moreover, it is not subject to stack overflow exceptions
  85. <a name="index-recursion-483"></a>because it is not written in a recursive style.
  86. </p></blockquote></div>
  87. <div class="defun">
  88. &mdash; Function: list <b>avm_binary_comparison</b> (<var>list left_operand, list right_operand, int *fault</var>)<var>;<a name="index-avm_005fbinary_005fcomparison-484"></a></var><br>
  89. <blockquote><p>This function is the same as <code>avm_comparison</code> except that it
  90. allows the left and right operands to be passed as separate lists
  91. rather than taking them from the <code>head</code> and the <code>tail</code> of a
  92. single list.
  93. </p></blockquote></div>
  94. </body></html>