| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 | <title>Dbstl container specific notes</title> |
| 7 | <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> |
| 8 | <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> |
| 9 | <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> |
| 10 | <link rel="up" href="stl.html" title="Chapter 7. Standard Template Library API" /> |
| 11 | <link rel="prev" href="stl_persistence.html" title="Dbstl persistence" /> |
| 12 | <link rel="next" href="stl_efficienct_use.html" title="Using dbstl efficiently" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Dbstl container specific notes</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="stl_persistence.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 7. Standard Template Library API</th> |
| 26 | <td width="20%" align="right"> <a accesskey="n" href="stl_efficienct_use.html">Next</a></td> |
| 27 | </tr> |
| 28 | </table> |
| 29 | <hr /> |
| 30 | </div> |
| 31 | <div class="sect1" lang="en" xml:lang="en"> |
| 32 | <div class="titlepage"> |
| 33 | <div> |
| 34 | <div> |
| 35 | <h2 class="title" style="clear: both"><a id="stl_container_specific"></a>Dbstl container specific notes</h2> |
| 36 | </div> |
| 37 | </div> |
| 38 | </div> |
| 39 | <div class="toc"> |
| 40 | <dl> |
| 41 | <dt> |
| 42 | <span class="sect2"> |
| 43 | <a href="stl_container_specific.html#idp51492808">db_vector specific notes</a> |
| 44 | </span> |
| 45 | </dt> |
| 46 | <dt> |
| 47 | <span class="sect2"> |
| 48 | <a href="stl_container_specific.html#idp51561456">Associative container specific notes</a> |
| 49 | </span> |
| 50 | </dt> |
| 51 | </dl> |
| 52 | </div> |
| 53 | <div class="sect2" lang="en" xml:lang="en"> |
| 54 | <div class="titlepage"> |
| 55 | <div> |
| 56 | <div> |
| 57 | <h3 class="title"><a id="idp51492808"></a>db_vector specific notes</h3> |
| 58 | </div> |
| 59 | </div> |
| 60 | </div> |
| 61 | <div class="itemizedlist"> |
| 62 | <ul type="disc"> |
| 63 | <li> |
| 64 | <p> |
| 65 | Set the <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> flag in the database handle if you want |
| 66 | <code class="classname">db_vector<></code> to work like |
| 67 | <code class="classname">std::vector</code> or <code class="classname">std::deque</code>. Do not set |
| 68 | <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> if you want <code class="classname">db_vector<></code> to work like |
| 69 | <code class="classname">std::list</code>. Note that without <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> set, |
| 70 | <code class="classname">db_vector<></code> can work faster. |
| 71 | </p> |
| 72 | <p> |
| 73 | For example, to construct a fast std::queue/std::stack object, you only need a |
| 74 | <code class="classname">db_vector<></code> object whose database handle does not have |
| 75 | <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> set. Of course, if the database handle has <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> set, it |
| 76 | still works for this kind of scenario, just not as fast. |
| 77 | </p> |
| 78 | <p> |
| 79 | <code class="classname">db_vector</code> does not check whether <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> is set. If |
| 80 | you do not set it, <code class="classname">db_vector<></code> will not work like |
| 81 | std::vector<>/std::deque<> with regard to operator[], because the |
| 82 | indices are not maintained in that case. |
| 83 | </p> |
| 84 | <p> |
| 85 | You can find example code showing how to use this feature in the |
| 86 | <code class="methodname">StlAdvancedFeaturesExample::queue_stack()</code> method. |
| 87 | </p> |
| 88 | </li> |
| 89 | <li> |
| 90 | <p> |
| 91 | Just as is the case with <code class="classname">std::vector</code>, inserting/deleting in |
| 92 | the middle of a <code class="classname">db_vector</code> is slower than doing the same |
| 93 | action at the end of the sequence. This is because the underlying DB_RECNO DB (with |
| 94 | the <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> flag set) is relatively slow when inserting/deleting in the middle |
| 95 | or the head — it has to update the index numbers of all the records following |
| 96 | the one that was inserted/deleted. If you do not need to keep the index ordered on |
| 97 | insert/delete, you can use <code class="classname">db_map</code> instead. |
| 98 | </p> |
| 99 | <p> |
| 100 | <code class="classname">db_vector</code> also contains methods inherited from |
| 101 | <code class="classname">std::list</code> and <code class="classname">std::deque</code>, |
| 102 | including <code class="classname">std::list<>'s</code> unique methods |
| 103 | <code class="methodname">remove()</code>, <code class="methodname">remove_if()</code>, |
| 104 | <code class="methodname">unique()</code>, <code class="methodname">merge()</code>, |
| 105 | <code class="methodname">sort()</code>, <code class="methodname">reverse()</code>, and |
| 106 | <code class="methodname">splice()</code>. These use the identical semantics/behaviors |
| 107 | of the <code class="classname">std::list<></code> methods, although |
| 108 | pushing/deleting at the head is slower than the |
| 109 | <code class="methodname">std::deque</code> and <code class="methodname">std::list</code> |
| 110 | equivalent when there are quite a lot of elements in the database. |
| 111 | </p> |
| 112 | </li> |
| 113 | <li> |
| 114 | <p> |
| 115 | You can use <code class="classname">std::queue</code>, |
| 116 | <code class="classname">std::priority_queue</code> and <code class="classname">std::stack</code> |
| 117 | container adapters with <code class="classname">db_vector</code>; they work with db_vector |
| 118 | even without <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> set. |
| 119 | </p> |
| 120 | </li> |
| 121 | </ul> |
| 122 | </div> |
| 123 | </div> |
| 124 | <div class="sect2" lang="en" xml:lang="en"> |
| 125 | <div class="titlepage"> |
| 126 | <div> |
| 127 | <div> |
| 128 | <h3 class="title"><a id="idp51561456"></a>Associative container specific notes</h3> |
| 129 | </div> |
| 130 | </div> |
| 131 | </div> |
| 132 | <p> |
| 133 | <code class="classname">db_map</code> contains the union of method set from |
| 134 | <code class="classname">std::map</code> and <code class="classname">hash_map</code>, but there are some |
| 135 | methods that can only be called on containers backed by <code class="literal">DB_BTREE</code> or |
| 136 | <code class="literal">DB_HASH</code> databases. You can call |
| 137 | <code class="function">db_map<>::is_hash()</code> to figure out the type of the backing |
| 138 | database. If you call unsupported methods then an InvalidFunctionCall exception is thrown. |
| 139 | </p> |
| 140 | <p> |
| 141 | These are the <code class="literal">DB_BTREE</code> specific methods: <code class="methodname">upper_bound()</code>, |
| 142 | <code class="methodname">lower_bound()</code>, <code class="methodname">key_comp()</code>, |
| 143 | and <code class="methodname">value_comp()</code>. The <code class="literal">DB_HASH</code> specific methods are |
| 144 | <code class="methodname">key_eq()</code>, <code class="methodname">hash_funct()</code>. |
| 145 | </p> |
| 146 | </div> |
| 147 | </div> |
| 148 | <div class="navfooter"> |
| 149 | <hr /> |
| 150 | <table width="100%" summary="Navigation footer"> |
| 151 | <tr> |
| 152 | <td width="40%" align="left"><a accesskey="p" href="stl_persistence.html">Prev</a> </td> |
| 153 | <td width="20%" align="center"> |
| 154 | <a accesskey="u" href="stl.html">Up</a> |
| 155 | </td> |
| 156 | <td width="40%" align="right"> <a accesskey="n" href="stl_efficienct_use.html">Next</a></td> |
| 157 | </tr> |
| 158 | <tr> |
| 159 | <td width="40%" align="left" valign="top">Dbstl persistence </td> |
| 160 | <td width="20%" align="center"> |
| 161 | <a accesskey="h" href="index.html">Home</a> |
| 162 | </td> |
| 163 | <td width="40%" align="right" valign="top"> Using dbstl efficiently</td> |
| 164 | </tr> |
| 165 | </table> |
| 166 | </div> |
| 167 | </body> |
| 168 | </html> |