indices.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>Boost.MultiIndex Documentation - Index reference</title>
  6. <link rel="stylesheet" href="../style.css" type="text/css">
  7. <link rel="start" href="../index.html">
  8. <link rel="prev" href="multi_index_container.html">
  9. <link rel="up" href="index.html">
  10. <link rel="next" href="ord_indices.html">
  11. </head>
  12. <body>
  13. <h1><img src="../../../../boost.png" alt="boost.png (6897 bytes)" align=
  14. "middle" width="277" height="86">Boost.MultiIndex Index reference</h1>
  15. <div class="prev_link"><a href="multi_index_container.html"><img src="../prev.gif" alt="multi_index_container reference" border="0"><br>
  16. <code>multi_index_container</code> reference
  17. </a></div>
  18. <div class="up_link"><a href="index.html"><img src="../up.gif" alt="Boost.MultiIndex reference" border="0"><br>
  19. Boost.MultiIndex reference
  20. </a></div>
  21. <div class="next_link"><a href="ord_indices.html"><img src="../next.gif" alt="ordered indices" border="0"><br>
  22. Ordered indices
  23. </a></div><br clear="all" style="clear: all;">
  24. <hr>
  25. <h2>Contents</h2>
  26. <ul>
  27. <li><a href="#index_concepts">Index concepts</a></li>
  28. <li><a href="#complexity_signature">Complexity signature</a></li>
  29. <li><a href="#index_specification">Index specification</a></li>
  30. <li><a href="#indexed_by_synopsis">Header
  31. <code>"boost/multi_index/indexed_by.hpp"</code> synopsis</a>
  32. <ul>
  33. <li><a href="#indexed_by">Class template <code>indexed_by</code></a></li>
  34. </ul>
  35. </li>
  36. <li><a href="#tags">Tags</a></li>
  37. <li><a href="#tag_synopsis">Header
  38. <code>"boost/multi_index/tag.hpp"</code> synopsis</a>
  39. <ul>
  40. <li><a href="#tag">Class template <code>tag</code></a></li>
  41. </ul>
  42. </li>
  43. <li><a href="#index_catalog">Indices provided by Boost.MultiIndex</a>
  44. <ul>
  45. <li><a href="#key_based_indices">Key-based indices</a></li>
  46. <li><a href="#other_indices">Other types</a></li>
  47. </ul>
  48. </li>
  49. <li><a href="#views">Index views</a></li>
  50. </ul>
  51. <h2><a name="index_concepts">Index concepts</a></h2>
  52. <p>
  53. <code>multi_index_container</code> instantiations comprise one or more indices
  54. specified at compile time. Each index allows read/write access to the elements
  55. contained in a definite manner. For instance,
  56. <a href="ord_indices.html">ordered indices</a>
  57. provide a set-like interface to the elements, whereas
  58. <a href="seq_indices.html">sequenced indices</a> mimic the functionality
  59. of <code>std::list</code>.
  60. </p>
  61. <p>
  62. Indices are not isolated objects, and so cannot be constructed on their
  63. own. Rather they are embedded into a <code>multi_index_container</code> as specified by
  64. means of an <a href="#index_specification">index specifier</a>. The name of
  65. the index class implementation proper is never directly exposed to the user, who
  66. has only access to the associated index specifier.
  67. </p>
  68. <p>
  69. Insertion and erasing of elements are always performed through the
  70. appropriate interface of some index of the <code>multi_index_container</code>;
  71. these operations, however, do have an impact on all other indices as
  72. well: for instance, insertion through a given index may fail because
  73. there exists another index which bans the operation in order to preserve
  74. its invariant (like uniqueness of elements.) This circumstance, rather
  75. than being an obstacle, yields much of the power of Boost.MultiIndex:
  76. equivalent constructions based on manual composition of standard
  77. containers would have to add a fair amount of code in order to
  78. globally preserve the invariants of each container while guaranteeing
  79. that all of them are synchronized. The global operations performed
  80. in a joint manner among the various indices can be reduced to
  81. six primitives:
  82. <ul>
  83. <li>Copying,</li>
  84. <li>insertion of an element,</li>
  85. <li>hinted insertion, where a preexisting element is suggested in
  86. order to improve the efficiency of the operation,</li>
  87. <li>deletion of an element,</li>
  88. <li>replacement of the value of an element,
  89. which may trigger the rearrangement of this element in one or
  90. more indices, or the banning of the replacement,</li>
  91. <li>modification of an element, and its subsequent
  92. rearrangement/banning by the various indices.
  93. </ul>
  94. The last two primitives deserve some further explanation: in order to
  95. guarantee the invariants associated to each index (e.g. some definite
  96. ordering,) elements of a <code>multi_index_container</code> are not mutable.
  97. To overcome this restriction, indices expose member functions
  98. for replacement and modification which allow for the mutation of elements
  99. in a controlled fashion. Immutability of elements does not significantly
  100. impact the interfaces of ordered and hashed indices, as they are based upon
  101. those of associative and unordered associative containers, respectively,
  102. and these containers
  103. also have non-mutable elements; but it may come as a surprise when dealing
  104. with sequenced and random access indices, which are designed upon the functionality provided
  105. by <code>std::list</code>.
  106. </p>
  107. <p>
  108. These global operations are not directly exposed to the user, but rather
  109. they are wrapped as appropriate by each index (for instance, ordered indices
  110. provide a set-like suite of insertion member functions, whereas sequenced
  111. and random access indices have <code>push_back</code> and <code>push_front</code>
  112. operations.) Boost.MultiIndex poses no particular conditions on
  113. the interface of indices, although each index provided satisfy the C++ requirements for
  114. standard containers to the maximum extent possible within the conceptual framework
  115. of the library.
  116. </p>
  117. <h2><a name="complexity_signature">Complexity signature</a></h2>
  118. <p>
  119. Some member functions of an index interface are implemented by
  120. global primitives from the list above. Complexity of these operations
  121. thus depends on all indices of a given <code>multi_index_container</code>, not just
  122. the currently used index.
  123. </p>
  124. <p>
  125. In order to establish complexity estimates, an index is characterized
  126. by its <i>complexity signature</i>, consisting of the following
  127. associated functions on the number of elements:
  128. <ul>
  129. <li><code>c(n)</code>: copying,
  130. <li><code>i(n)</code>: insertion,
  131. <li><code>h(n)</code>: hinted insertion,
  132. <li><code>d(n)</code>: deletion,
  133. <li><code>r(n)</code>: replacement,
  134. <li><code>m(n)</code>: modifying.
  135. </ul>
  136. </p>
  137. Each function yields the complexity estimate of the contribution of the index
  138. to the corresponding global primitive. Let us consider
  139. an instantiation of <code>multi_index_container</code>
  140. with <code>N</code> indices labelled <code>0</code>,...,<code>N-1</code>
  141. whose complexity signatures are
  142. (<code>c<sub>i</sub></code>,<code>i<sub>i</sub></code>,<code>h<sub>i</sub></code>,<code>d<sub>i</sub></code>,<code>r<sub>i</sub></code>,<code>m<sub>i</sub></code>);
  143. the insertion of an element in such a container is then of complexity
  144. <code>O(i<sub>0</sub>(n)+···+i<sub>N-1</sub>(n))</code> where <code>n</code>
  145. is the number of elements. To abbreviate notation, we adopt the
  146. following definitions:
  147. <ul>
  148. <li><code>C(n)=c<sub>0</sub>(n)+···+c<sub>N-1</sub>(n)</code>,</li>
  149. <li><code>I(n)=i<sub>0</sub>(n)+···+i<sub>N-1</sub>(n)</code>,</li>
  150. <li><code>H(n)=h<sub>0</sub>(n)+···+h<sub>N-1</sub>(n)</code>,</li>
  151. <li><code>D(n)=d<sub>0</sub>(n)+···+d<sub>N-1</sub>(n)</code>,</li>
  152. <li><code>R(n)=r<sub>0</sub>(n)+···+r<sub>N-1</sub>(n)</code>,</li>
  153. <li><code>M(n)=m<sub>0</sub>(n)+···+m<sub>N-1</sub>(n)</code>.</li>
  154. </ul>
  155. For instance, consider a <code>multi_index_container</code> with two ordered indices,
  156. for which <code>i(n)=log(n)</code>, and a sequenced index with <code>i(n)=1</code>
  157. (constant time insertion). Insertion of an element into this <code>multi_index_container</code>
  158. is then of complexity
  159. <blockquote>
  160. <code>O(I(n))=O(2*log(n)+1)=O(log(n))</code>.
  161. </blockquote>
  162. </p>
  163. <h2><a name="index_specification">Index specification</a></h2>
  164. <p>
  165. Index specifiers are passed as instantiation arguments to
  166. <code>multi_index_container</code> and provide the information needed to incorporate
  167. the corresponding indices. Future releases of Boost.MultiIndex may allow for
  168. specification of user-defined indices. Meanwhile, the requirements for an index
  169. specifier remain implementation defined. Currently, Boost.MultiIndex provides the
  170. index specifiers
  171. <ul>
  172. <li><a href="ord_indices.html#unique_non_unique"><code>ordered_unique</code> and
  173. <code>ordered_non_unique</code></a> for
  174. <a href="ord_indices.html">ordered indices</a>,</li>
  175. <li><a href="rnk_indices.html#unique_non_unique"><code>ranked_unique</code> and
  176. <code>ranked_non_unique</code></a> for
  177. <a href="rnk_indices.html">ranked indices</a>,</li>
  178. <li><a href="hash_indices.html#unique_non_unique"><code>hashed_unique</code> and
  179. <code>hashed_non_unique</code></a> for
  180. <a href="hash_indices.html">hashed indices</a>,</li>
  181. <li><a href="seq_indices.html#sequenced"><code>sequenced</code></a> for
  182. <a href="seq_indices.html">sequenced indices</a>,</li>
  183. <li>and <a href="rnd_indices.html#random_access"><code>random_access</code></a> for
  184. <a href="rnd_indices.html">random access indices</a>.</li>
  185. </ul>
  186. </p>
  187. <h2>
  188. <a name="indexed_by_synopsis">Header
  189. <a href="../../../../boost/multi_index/indexed_by.hpp">
  190. <code>"boost/multi_index/indexed_by.hpp"</code></a> synopsis</a></h2>
  191. <blockquote><pre>
  192. <span class=keyword>namespace</span> <span class=identifier>boost</span><span class=special>{</span>
  193. <span class=keyword>namespace</span> <span class=identifier>multi_index</span><span class=special>{</span>
  194. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T0</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Tn</span><span class=special>&gt;</span>
  195. <span class=keyword>struct</span> <span class=identifier>indexed_by</span><span class=special>;</span>
  196. <span class=special>}</span> <span class=comment>// namespace boost::multi_index</span>
  197. <span class=special>}</span> <span class=comment>// namespace boost</span>
  198. </pre></blockquote>
  199. <h3><a name="indexed_by">Class template <code>indexed_by</code></a></h3>
  200. <p>
  201. <code>indexed_by</code> is a model of
  202. <a href="../../../../libs/mpl/doc/refmanual/random-access-sequence.html">
  203. <code>MPL Random Access Sequence</code></a> and
  204. <a href="../../../../libs/mpl/doc/refmanual/extensible-sequence.html">
  205. <code>MPL Extensible Sequence</code></a> meant to be used to specify a
  206. compile-time list of indices as the <code>IndexSpecifierList</code> of
  207. <code>multi_index_container</code>.
  208. </p>
  209. <blockquote><pre>
  210. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T0</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Tn</span><span class=special>&gt;</span>
  211. <span class=keyword>struct</span> <span class=identifier>indexed_by</span><span class=special>;</span>
  212. </pre></blockquote>
  213. <p>
  214. Each user-provided element of <code>indexed_list</code> must be an index
  215. specifier. At least an element must be provided. The maximum number of elements
  216. of an <code>indexed_by</code> sequence is implementation defined.
  217. </p>
  218. <h2><a name="tags">Tags</a></h2>
  219. <p>
  220. Tags are just conventional types used as mnemonics for indices of an
  221. <code>multi_index_container</code>, as for instance in member function <code>get</code>.
  222. Each index can have none, one or more tags associated. The way tags are assigned
  223. to a given index is dependent on the particular index specifier. However,
  224. for convenience all indices of Boost.MultiIndex support tagging through the
  225. class template <a href="#tag"><code>tag</code></a>.
  226. </p>
  227. <h2>
  228. <a name="tag_synopsis">Header
  229. <a href="../../../../boost/multi_index/tag.hpp">
  230. <code>"boost/multi_index/tag.hpp"</code></a> synopsis</a></h2>
  231. <blockquote><pre>
  232. <span class=keyword>namespace</span> <span class=identifier>boost</span><span class=special>{</span>
  233. <span class=keyword>namespace</span> <span class=identifier>multi_index</span><span class=special>{</span>
  234. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T0</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Tn</span><span class=special>&gt;</span>
  235. <span class=keyword>struct</span> <span class=identifier>tag</span><span class=special>;</span>
  236. <span class=special>}</span> <span class=comment>// namespace boost::multi_index</span>
  237. <span class=special>}</span> <span class=comment>// namespace boost</span>
  238. </pre></blockquote>
  239. <h3><a name="tag">Class template <code>tag</code></a></h3>
  240. <p>
  241. <code>tag</code> is a typelist construct used to specify a compile-time
  242. sequence of tags to be assigned to an index in instantiation time.
  243. </p>
  244. <blockquote><pre>
  245. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T0</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Tn</span><span class=special>&gt;</span>
  246. <span class=keyword>struct</span> <span class=identifier>tag</span>
  247. <span class=special>{</span>
  248. <span class=keyword>typedef</span> <b>implementation defined</b> <span class=identifier>type</span><span class=special>;</span>
  249. <span class=special>};</span>
  250. </pre></blockquote>
  251. <p>
  252. Elements of <code>tag</code> can be any type, though the user is expected
  253. to provide classes with mnemonic names. Duplicate elements are not allowed.
  254. The maximum number of elements of a <code>tag</code> instantiation is
  255. implementation defined.
  256. The nested
  257. <code>type</code> is a model of
  258. <a href="../../../../libs/mpl/doc/refmanual/random-access-sequence.html">
  259. <code>MPL Random Access Sequence</code></a> and
  260. <a href="../../../../libs/mpl/doc/refmanual/extensible-sequence.html">
  261. <code>MPL Extensible Sequence</code></a> containing the types <code>T0</code>, ... ,
  262. <code>Tn</code> in the same order as specified.
  263. </p>
  264. <h2><a name="index_catalog">Indices provided by Boost.MultiIndex</a></h2>
  265. <h3><a name="key_based_indices">Key-based indices</a></h3>
  266. <p>
  267. Indices of this type are organized around <i>keys</i> obtained from the
  268. elements, as described in the <a href="key_extraction.html">key extraction
  269. reference</a>.
  270. <ul>
  271. <li><a href="ord_indices.html">Ordered indices</a> sort the elements
  272. on the key and provide fast lookup capabilites.</li>
  273. <li><a href="rnk_indices.html">Ranked indices</a> are a variation of
  274. ordered indices providing extra operations based on
  275. <i>rank</i>, the numerical position of an element
  276. in the sequence.</li>
  277. <li><a href="hash_indices.html">Hashed indices</a> offer high
  278. efficiency access through hashing techniques.</li>
  279. </ul>
  280. </p>
  281. <h3><a name="other_indices">Other types</a></h3>
  282. <p>
  283. <ul>
  284. <li><a href="seq_indices.html">Sequenced indices</a> allow to arrange
  285. elements as in a bidirectional list.</li>
  286. <li><a href="rnd_indices.html">Random access indices</a> provide
  287. constant time positional access and free ordering of elements.</li>
  288. </ul>
  289. </p>
  290. <h2><a name="views">Index views</a></h2>
  291. <p>
  292. The following concept is used by the rearrange facilities of non key-based
  293. indices. Given an index <code>i</code> of type <code>Index</code>, a <i>view
  294. of <code>i</code></i> is any range [<code>first</code>,<code>last</code>)
  295. where <code>first</code> and <code>last</code> are input iterators such that
  296. <ol>
  297. <li>the associated value type of <code>Iterator</code> is convertible
  298. to <code>const Index::value_type&amp;</code>
  299. </li>
  300. <li>and each of the elements of <code>i</code> appears exactly once in
  301. [<code>first</code>,<code>last</code>).
  302. </li>
  303. </ol>
  304. Note that the view refers to the actual elements of <code>i</code>, not to
  305. copies of them. Additionally, a view is said to be <i>free</i> if its traversal
  306. order is not affected by changes in the traversal order of <code>i</code>.
  307. Examples of free views are:
  308. <ul>
  309. <li>[<code>c.begin()</code>,<code>c.end()</code>), where <code>c</code> is
  310. any container of reference wrappers (from
  311. <a href="../../../../doc/html/ref.html">Boost.Ref</a>) to the elements
  312. of <code>i</code> containing exactly one reference to every element.
  313. </li>
  314. <li>[<code>i'.begin()</code>,<code>i'.end()</code>), where <code>i'</code> is
  315. any index belonging to the same <code>multi_index_container</code>
  316. as <code>i</code>, except <code>i</code> itself.
  317. </li>
  318. <li>
  319. Any range which is a permutation of the ones described above, as for
  320. instance [<code>c.rbegin()</code>,<code>c.rend()</code>), or
  321. ranges obtained from the former with the aid of
  322. <a href="../../../../libs/iterator/doc/permutation_iterator.html">
  323. <code>permutation_iterator</code></a> from Boost.Iterator.
  324. </li>
  325. </ul>
  326. </p>
  327. <hr>
  328. <div class="prev_link"><a href="multi_index_container.html"><img src="../prev.gif" alt="multi_index_container reference" border="0"><br>
  329. <code>multi_index_container</code> reference
  330. </a></div>
  331. <div class="up_link"><a href="index.html"><img src="../up.gif" alt="Boost.MultiIndex reference" border="0"><br>
  332. Boost.MultiIndex reference
  333. </a></div>
  334. <div class="next_link"><a href="ord_indices.html"><img src="../next.gif" alt="ordered indices" border="0"><br>
  335. Ordered indices
  336. </a></div><br clear="all" style="clear: all;">
  337. <br>
  338. <p>Revised April 19th 2015</p>
  339. <p>&copy; Copyright 2003-2015 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
  340. Distributed under the Boost Software
  341. License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
  342. LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  343. http://www.boost.org/LICENSE_1_0.txt</a>)
  344. </p>
  345. </body>
  346. </html>