123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <html lang="en">
- <head>
- <title>Comparison - avram - a virtual machine code interpreter</title>
- <meta http-equiv="Content-Type" content="text/html">
- <meta name="description" content="avram - a virtual machine code interpreter">
- <meta name="generator" content="makeinfo 4.13">
- <link title="Top" rel="start" href="index.html#Top">
- <link rel="up" href="Lists.html#Lists" title="Lists">
- <link rel="prev" href="Type-Conversions.html#Type-Conversions" title="Type Conversions">
- <link rel="next" href="Deconstruction-Functions.html#Deconstruction-Functions" title="Deconstruction Functions">
- <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
- <meta http-equiv="Content-Style-Type" content="text/css">
- <style type="text/css"><!--
- pre.display { font-family:inherit }
- pre.format { font-family:inherit }
- pre.smalldisplay { font-family:inherit; font-size:smaller }
- pre.smallformat { font-family:inherit; font-size:smaller }
- pre.smallexample { font-size:smaller }
- pre.smalllisp { font-size:smaller }
- span.sc { font-variant:small-caps }
- span.roman { font-family:serif; font-weight:normal; }
- span.sansserif { font-family:sans-serif; font-weight:normal; }
- --></style>
- </head>
- <body>
- <div class="node">
- <a name="Comparison"></a>
- <p>
- Next: <a rel="next" accesskey="n" href="Deconstruction-Functions.html#Deconstruction-Functions">Deconstruction Functions</a>,
- Previous: <a rel="previous" accesskey="p" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>,
- Up: <a rel="up" accesskey="u" href="Lists.html#Lists">Lists</a>
- <hr>
- </div>
- <h4 class="subsection">3.1.5 Comparison</h4>
- <p>The file <samp><span class="file">compare.h</span></samp> 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
- <samp><span class="file">compare.c</span></samp> that are not recommended entry points to the library.
- <div class="defun">
- — Function: void <b>avm_initialize_compare</b> ()<var><a name="index-avm_005finitialize_005fcompare-476"></a></var><br>
- <blockquote><p><a name="index-g_t_0040code_007bcompare_007d-477"></a>This function should be called once before the first call to
- <code>avm_comparison</code>, as it initializes some necessary internal data
- structures.
- </p></blockquote></div>
- <div class="defun">
- — Function: void <b>avm_count_compare</b> ()<var><a name="index-avm_005fcount_005fcompare-478"></a></var><br>
- <blockquote><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></blockquote></div>
- <div class="defun">
- — Function: list <b>avm_comparison</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005fcomparison-479"></a></var><br>
- <blockquote><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>*</code><var>fault</var> 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-480"></a>rather than pointer equality.
- <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-481"></a>that happen to be holding stale list pointers.
- <p><a name="index-discontiguous-field-482"></a>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
- <samp><span class="file">mpfr.c</span></samp> for an example.
- <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-483"></a>because it is not written in a recursive style.
- </p></blockquote></div>
- <div class="defun">
- — 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>
- <blockquote><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></blockquote></div>
- </body></html>
|