Note that there are some explanatory texts on larger screens.

plurals
  1. POSTL map for an struct defined in ANSI C
    primarykey
    data
    text
    <p>I am coding in a mixed C/C++ environment. I have an struct in C part and I would like to collect it in a map container in C++ part. I think I should define a custom <strong>key_compare</strong> function object, and let STL <em>map::insert()</em> orders nodes. However I don't know how can I modify map container to customize <em>map::find()</em> function. I am looking for a way to customize <em>map::find()</em> function to do something more that key_compare function for equivalence checking. </p> <p>Would you please let me know how I can put these functions into STL::map or STL::set ? </p> <p>here is my struct in C part (compile with gcc): </p> <pre><code>typedef struct iotrace_arh_node { double time; unsigned long long int blkno; int bcount; u_int flags; int devno; unsigned long stack_no; } iotrace_arh_node_t; </code></pre> <p>here is my proposed <strong>key_compare</strong> and equivalence checking function for <strong>find()</strong> in the C++ part (compile with g++):</p> <pre><code>int key_compare ( struct iotrace_arh_node tempa, struct iotrace_arh_node tempb ) { return (tempa.blkno-tempb.blkno); } int key_equal( struct iotrace_arh_node tempa, struct iotrace_arh_node tempb ) { if( (tempa.blkno == tempb.blkno) &amp;&amp; (tempa.bcount == tempb.bcount) ) return 0; // tempa and tempb is equal, node fund in the map else if ( (tempb.blkno &lt; tempa.blkno) ) return -1; //tempb is less than tempa else if ( (tempb.blkno &gt;= tempa.blkno) &amp;&amp; ( tempb.blkno + tempb.bcount &lt; tempa.blkno + tempa.bcount) ) return 0; // tempa and tempb is equal, node fund in the map else return 1; //tempb is grater than tempa } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload