• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>Data Structures</title>
6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="../heap.html" title="Chapter 17. Boost.Heap">
10<link rel="prev" href="concepts.html" title="Concepts &amp; Interface">
11<link rel="next" href="reference.html" title="Reference">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16<td align="center"><a href="../../../index.html">Home</a></td>
17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<a accesskey="p" href="concepts.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../heap.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
25</div>
26<div class="section">
27<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28<a name="heap.data_structures"></a><a class="link" href="data_structures.html" title="Data Structures">Data Structures</a>
29</h2></div></div></div>
30<div class="toc"><dl class="toc"><dt><span class="section"><a href="data_structures.html#heap.data_structures.data_structure_configuration">Data
31      Structure Configuration</a></span></dt></dl></div>
32<p>
33      <code class="literal">boost.heap</code> provides the following data structures:
34    </p>
35<div class="variablelist">
36<p class="title"><b></b></p>
37<dl class="variablelist">
38<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/priority_queue.html" title="Class template priority_queue">boost::heap::priority_queue</a></code></span></dt>
39<dd><p>
40            The <code class="computeroutput"><a class="link" href="../boost/heap/priority_queue.html" title="Class template priority_queue">priority_queue</a></code>
41            class is a wrapper to the stl heap functions. It implements a heap as
42            container adaptor ontop of a <code class="literal">std::vector</code> and is immutable.
43          </p></dd>
44<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/d_ary_heap.html" title="Class template d_ary_heap">boost::heap::d_ary_heap</a></code></span></dt>
45<dd>
46<p>
47            <a href="http://en.wikipedia.org/wiki/D-ary_heap" target="_top">D-ary heaps</a>
48            are a generalization of binary heap with each non-leaf node having N
49            children. For a low arity, the height of the heap is larger, but the
50            number of comparisons to find the largest child node is bigger. D-ary
51            heaps are implemented as container adaptors based on a <code class="literal">std::vector</code>.
52          </p>
53<p>
54            The data structure can be configured as mutable. This is achieved by
55            storing the values inside a std::list.
56          </p>
57</dd>
58<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/binomial_heap.html" title="Class template binomial_heap">boost::heap::binomial_heap</a></code></span></dt>
59<dd><p>
60            <a href="http://en.wikipedia.org/wiki/Binomial_heap" target="_top">Binomial heaps</a>
61            are node-base heaps, that are implemented as a set of binomial trees
62            of piecewise different order. The most important heap operations have
63            a worst-case complexity of O(log n). In contrast to d-ary heaps, binomial
64            heaps can also be merged in O(log n).
65          </p></dd>
66<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/fibonacci_heap.html" title="Class template fibonacci_heap">boost::heap::fibonacci_heap</a></code></span></dt>
67<dd><p>
68            <a href="http://en.wikipedia.org/wiki/Fibonacci_heap" target="_top">Fibonacci heaps</a>
69            are node-base heaps, that are implemented as a forest of heap-ordered
70            trees. They provide better amortized performance than binomial heaps.
71            Except <code class="literal">pop()</code> and <code class="literal">erase()</code>, the most
72            important heap operations have constant amortized complexity.
73          </p></dd>
74<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/pairing_heap.html" title="Class template pairing_heap">boost::heap::pairing_heap</a></code></span></dt>
75<dd>
76<p>
77            <a href="http://en.wikipedia.org/wiki/Pairing_heap" target="_top">Pairing heaps</a>
78            are self-adjusting node-based heaps. Although design and implementation
79            are rather simple, the complexity analysis is yet unsolved. For details,
80            consult:
81          </p>
82<p>
83            Pettie, Seth (2005), "Towards a final analysis of pairing heaps",
84            Proc. 46th Annual IEEE Symposium on Foundations of Computer Science,
85            pp. 174–183
86          </p>
87</dd>
88<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/skew_heap.html" title="Class template skew_heap">boost::heap::skew_heap</a></code></span></dt>
89<dd><p>
90            <a href="http://en.wikipedia.org/wiki/Skew_heap" target="_top">Skew heaps</a>
91            are self-adjusting node-based heaps. Although there are no constraints
92            for the tree structure, all heap operations can be performed in O(log
93            n).
94          </p></dd>
95</dl>
96</div>
97<div class="table">
98<a name="heap.data_structures.t0"></a><p class="title"><b>Table 17.1. Comparison of amortized complexity</b></p>
99<div class="table-contents"><table class="table" summary="Comparison of amortized complexity">
100<colgroup>
101<col>
102<col>
103<col>
104<col>
105<col>
106<col>
107<col>
108<col>
109<col>
110</colgroup>
111<thead><tr>
112<th>
113            </th>
114<th>
115              <p>
116                <code class="literal">top()</code>
117              </p>
118            </th>
119<th>
120              <p>
121                <code class="literal">push()</code>
122              </p>
123            </th>
124<th>
125              <p>
126                <code class="literal">pop()</code>
127              </p>
128            </th>
129<th>
130              <p>
131                <code class="literal">update()</code>
132              </p>
133            </th>
134<th>
135              <p>
136                <code class="literal">increase()</code>
137              </p>
138            </th>
139<th>
140              <p>
141                <code class="literal">decrease()</code>
142              </p>
143            </th>
144<th>
145              <p>
146                <code class="literal">erase()</code>
147              </p>
148            </th>
149<th>
150              <p>
151                <code class="literal">merge_and_clear()</code>
152              </p>
153            </th>
154</tr></thead>
155<tbody>
156<tr>
157<td>
158              <p>
159                <code class="computeroutput"><a class="link" href="../boost/heap/priority_queue.html" title="Class template priority_queue">boost::heap::priority_queue</a></code>
160              </p>
161            </td>
162<td>
163              <p>
164                <code class="literal">O(1)</code>
165              </p>
166            </td>
167<td>
168              <p>
169                O(log(N))
170              </p>
171            </td>
172<td>
173              <p>
174                O(log(N))
175              </p>
176            </td>
177<td>
178              <p>
179                n/a
180              </p>
181            </td>
182<td>
183              <p>
184                n/a
185              </p>
186            </td>
187<td>
188              <p>
189                n/a
190              </p>
191            </td>
192<td>
193              <p>
194                n/a
195              </p>
196            </td>
197<td>
198              <p>
199                O((N+M)*log(N+M))
200              </p>
201            </td>
202</tr>
203<tr>
204<td>
205              <p>
206                <code class="computeroutput"><a class="link" href="../boost/heap/d_ary_heap.html" title="Class template d_ary_heap">boost::heap::d_ary_heap</a></code>
207              </p>
208            </td>
209<td>
210              <p>
211                <code class="literal">O(1)</code>
212              </p>
213            </td>
214<td>
215              <p>
216                O(log(N))
217              </p>
218            </td>
219<td>
220              <p>
221                O(log(N))
222              </p>
223            </td>
224<td>
225              <p>
226                O(log(N))
227              </p>
228            </td>
229<td>
230              <p>
231                O(log(N))
232              </p>
233            </td>
234<td>
235              <p>
236                O(log(N))
237              </p>
238            </td>
239<td>
240              <p>
241                O(log(N))
242              </p>
243            </td>
244<td>
245              <p>
246                O((N+M)*log(N+M))
247              </p>
248            </td>
249</tr>
250<tr>
251<td>
252              <p>
253                <code class="computeroutput"><a class="link" href="../boost/heap/binomial_heap.html" title="Class template binomial_heap">boost::heap::binomial_heap</a></code>
254              </p>
255            </td>
256<td>
257              <p>
258                <code class="literal">O(1)</code>
259              </p>
260            </td>
261<td>
262              <p>
263                O(log(N))
264              </p>
265            </td>
266<td>
267              <p>
268                O(log(N))
269              </p>
270            </td>
271<td>
272              <p>
273                O(log(N))
274              </p>
275            </td>
276<td>
277              <p>
278                O(log(N))
279              </p>
280            </td>
281<td>
282              <p>
283                O(log(N))
284              </p>
285            </td>
286<td>
287              <p>
288                O(log(N))
289              </p>
290            </td>
291<td>
292              <p>
293                O(log(N+M))
294              </p>
295            </td>
296</tr>
297<tr>
298<td>
299              <p>
300                <code class="computeroutput"><a class="link" href="../boost/heap/fibonacci_heap.html" title="Class template fibonacci_heap">boost::heap::fibonacci_heap</a></code>
301              </p>
302            </td>
303<td>
304              <p>
305                <code class="literal">O(1)</code>
306              </p>
307            </td>
308<td>
309              <p>
310                O(1)
311              </p>
312            </td>
313<td>
314              <p>
315                O(log(N))
316              </p>
317            </td>
318<td>
319              <p>
320                O(log(N)) <a href="#ftn.heap.data_structures.f0" class="footnote" name="heap.data_structures.f0"><sup class="footnote">[a]</sup></a>
321              </p>
322            </td>
323<td>
324              <p>
325                O(1)
326              </p>
327            </td>
328<td>
329              <p>
330                O(log(N))
331              </p>
332            </td>
333<td>
334              <p>
335                O(log(N))
336              </p>
337            </td>
338<td>
339              <p>
340                O(1)
341              </p>
342            </td>
343</tr>
344<tr>
345<td>
346              <p>
347                <code class="computeroutput"><a class="link" href="../boost/heap/pairing_heap.html" title="Class template pairing_heap">boost::heap::pairing_heap</a></code>
348              </p>
349            </td>
350<td>
351              <p>
352                <code class="literal">O(1)</code>
353              </p>
354            </td>
355<td>
356              <p>
357                O(2**2*log(log(N)))
358              </p>
359            </td>
360<td>
361              <p>
362                O(log(N))
363              </p>
364            </td>
365<td>
366              <p>
367                O(2**2*log(log(N)))
368              </p>
369            </td>
370<td>
371              <p>
372                O(2**2*log(log(N)))
373              </p>
374            </td>
375<td>
376              <p>
377                O(2**2*log(log(N)))
378              </p>
379            </td>
380<td>
381              <p>
382                O(2**2*log(log(N)))
383              </p>
384            </td>
385<td>
386              <p>
387                O(2**2*log(log(N)))
388              </p>
389            </td>
390</tr>
391<tr>
392<td>
393              <p>
394                <code class="computeroutput"><a class="link" href="../boost/heap/skew_heap.html" title="Class template skew_heap">boost::heap::skew_heap</a></code>
395              </p>
396            </td>
397<td>
398              <p>
399                <code class="literal">O(1)</code>
400              </p>
401            </td>
402<td>
403              <p>
404                O(log(N))
405              </p>
406            </td>
407<td>
408              <p>
409                O(log(N))
410              </p>
411            </td>
412<td>
413              <p>
414                O(log(N))
415              </p>
416            </td>
417<td>
418              <p>
419                O(log(N))
420              </p>
421            </td>
422<td>
423              <p>
424                O(log(N))
425              </p>
426            </td>
427<td>
428              <p>
429                O(log(N))
430              </p>
431            </td>
432<td>
433              <p>
434                O(log(N+M))
435              </p>
436            </td>
437</tr>
438</tbody>
439<tbody class="footnotes"><tr><td colspan="9"><div id="ftn.heap.data_structures.f0" class="footnote"><p><a href="#heap.data_structures.f0" class="para"><sup class="para">[a] </sup></a>
440                  The fibonacci a <code class="literal">update_lazy()</code> method, which
441                  has O(log(N)) amortized complexity as well, but does not try to
442                  consolidate the internal forest
443                </p></div></td></tr></tbody>
444</table></div>
445</div>
446<br class="table-break"><div class="section">
447<div class="titlepage"><div><div><h3 class="title">
448<a name="heap.data_structures.data_structure_configuration"></a><a class="link" href="data_structures.html#heap.data_structures.data_structure_configuration" title="Data Structure Configuration">Data
449      Structure Configuration</a>
450</h3></div></div></div>
451<p>
452        The data structures can be configured with <a href="../../../libs/parameter/doc/html/index.html" target="_top">Boost.Parameter</a>-style
453        templates.
454      </p>
455<div class="variablelist">
456<p class="title"><b></b></p>
457<dl class="variablelist">
458<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/compare.html" title="Struct template compare">boost::heap::compare</a></code></span></dt>
459<dd><p>
460              Predicate for defining the heap order, optional (defaults to <code class="literal">boost::heap::compare&lt;std::less&lt;T&gt;
461              &gt;</code>)
462            </p></dd>
463<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/allocator.html" title="Struct template allocator">boost::heap::allocator</a></code></span></dt>
464<dd><p>
465              Allocator for internal memory management, optional (defaults to <code class="literal">boost::heap::allocator&lt;std::allocator&lt;T&gt;
466              &gt;</code>)
467            </p></dd>
468<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/stable.html" title="Struct template stable">boost::heap::stable</a></code></span></dt>
469<dd><p>
470              Configures the heap to use a <a class="link" href="concepts.html#heap.concepts.stability" title="Stability">stable
471              heap order</a>, optional (defaults to <code class="literal">boost::heap::stable&lt;false&gt;</code>).
472            </p></dd>
473<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/mutable_.html" title="Struct template mutable_">boost::heap::mutable_</a></code></span></dt>
474<dd><p>
475              Configures the heap to be mutable. <code class="computeroutput"><a class="link" href="../boost/heap/d_ary_heap.html" title="Class template d_ary_heap">boost::heap::d_ary_heap</a></code>
476              and <code class="computeroutput"><a class="link" href="../boost/heap/skew_heap.html" title="Class template skew_heap">boost::heap::skew_heap</a></code>
477              have to be configured with this policy to enable the <a class="link" href="concepts.html#heap.concepts.mutability" title="Mutability">mutability
478              interface</a>.
479            </p></dd>
480<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/stability_counter_type.html" title="Struct template stability_counter_type">boost::heap::stability_counter_type</a></code></span></dt>
481<dd><p>
482              Configures the integer type used for the stability counter, optional
483              (defaults to <code class="literal">boost::heap::stability_counter_type&lt;boost::uintmax_t&gt;</code>).
484              For more details, consult the <a class="link" href="concepts.html#heap.concepts.stability" title="Stability">Stability</a>
485              section.
486            </p></dd>
487<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/constant_time_size.html" title="Struct template constant_time_size">boost::heap::constant_time_size</a></code></span></dt>
488<dd><p>
489              Specifies, whether <code class="literal">size()</code> should have linear or
490              constant complexity. This argument is only available for node-based
491              heap data structures and if available, it is optional (defaults to
492              <code class="literal">boost::heap::constant_time_size&lt;true&gt;</code>)
493            </p></dd>
494<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/arity.html" title="Struct template arity">boost::heap::arity</a></code></span></dt>
495<dd><p>
496              Specifies the arity of a d-ary heap. For details, please consult the
497              class reference of <code class="computeroutput"><a class="link" href="../boost/heap/d_ary_heap.html" title="Class template d_ary_heap">boost::heap::d_ary_heap</a></code>
498            </p></dd>
499<dt><span class="term"><code class="computeroutput"><a class="link" href="../boost/heap/store_parent_pointer.html" title="Struct template store_parent_pointer">boost::heap::store_parent_pointer</a></code></span></dt>
500<dd><p>
501              Store the parent pointer in the heap nodes. This policy is only available
502              in the <code class="computeroutput"><a class="link" href="../boost/heap/skew_heap.html" title="Class template skew_heap">boost::heap::skew_heap</a></code>.
503            </p></dd>
504</dl>
505</div>
506</div>
507</div>
508<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
509<td align="left"></td>
510<td align="right"><div class="copyright-footer">Copyright © 2010, 2011 Tim Blechmann<p>
511        Distributed under the Boost Software License, Version 1.0. (See accompanying
512        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
513      </p>
514</div></td>
515</tr></table>
516<hr>
517<div class="spirit-nav">
518<a accesskey="p" href="concepts.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../heap.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
519</div>
520</body>
521</html>
522