summaryrefslogtreecommitdiff
path: root/doc/html/unordered/comparison.html
blob: 6e74d03a2548cc767e7ff48e09220fa8fe73932e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Comparison with Associative Containers</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../unordered.html" title="Chapter&#160;44.&#160;Boost.Unordered">
<link rel="prev" href="hash_equality.html" title="Equality Predicates and Hash Functions">
<link rel="next" href="compliance.html" title="Standard Compliance">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="hash_equality.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../unordered.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="compliance.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="unordered.comparison"></a><a class="link" href="comparison.html" title="Comparison with Associative Containers">Comparison with Associative Containers</a>
</h2></div></div></div>
<div class="table">
<a name="unordered.comparison.interface_differences"></a><p class="title"><b>Table&#160;44.4.&#160;Interface differences.</b></p>
<div class="table-contents"><table class="table" summary="Interface differences.">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
              <p>
                Associative Containers
              </p>
            </th>
<th>
              <p>
                Unordered Associative Containers
              </p>
            </th>
</tr></thead>
<tbody>
<tr>
<td>
              <p>
                Parameterized by an ordering relation <code class="computeroutput"><span class="identifier">Compare</span></code>
              </p>
            </td>
<td>
              <p>
                Parameterized by a function object <code class="computeroutput"><span class="identifier">Hash</span></code>
                and an equivalence relation <code class="computeroutput"><span class="identifier">Pred</span></code>
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Keys can be compared using <code class="computeroutput"><span class="identifier">key_compare</span></code>
                which is accessed by member function <code class="computeroutput"><span class="identifier">key_comp</span><span class="special">()</span></code>, values can be compared using
                <code class="computeroutput"><span class="identifier">value_compare</span></code> which
                is accessed by member function <code class="computeroutput"><span class="identifier">value_comp</span><span class="special">()</span></code>.
              </p>
            </td>
<td>
              <p>
                Keys can be hashed using <code class="computeroutput"><span class="identifier">hasher</span></code>
                which is accessed by member function <code class="computeroutput"><span class="identifier">hash_function</span><span class="special">()</span></code>, and checked for equality using
                <code class="computeroutput"><span class="identifier">key_equal</span></code> which is
                accessed by member function <code class="computeroutput"><span class="identifier">key_eq</span><span class="special">()</span></code>. There is no function object for
                compared or hashing values.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Constructors have optional extra parameters for the comparison object.
              </p>
            </td>
<td>
              <p>
                Constructors have optional extra parameters for the initial minimum
                number of buckets, a hash function and an equality object.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Keys <code class="computeroutput"><span class="identifier">k1</span></code>, <code class="computeroutput"><span class="identifier">k2</span></code> are considered equivalent if
                <code class="computeroutput"><span class="special">!</span><span class="identifier">Compare</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span> <span class="identifier">k2</span><span class="special">)</span> <span class="special">&amp;&amp;</span>
                <span class="special">!</span><span class="identifier">Compare</span><span class="special">(</span><span class="identifier">k2</span><span class="special">,</span> <span class="identifier">k1</span><span class="special">)</span></code>
              </p>
            </td>
<td>
              <p>
                Keys <code class="computeroutput"><span class="identifier">k1</span></code>, <code class="computeroutput"><span class="identifier">k2</span></code> are considered equivalent if
                <code class="computeroutput"><span class="identifier">Pred</span><span class="special">(</span><span class="identifier">k1</span><span class="special">,</span> <span class="identifier">k2</span><span class="special">)</span></code>
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Member function <code class="computeroutput"><span class="identifier">lower_bound</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code> and <code class="computeroutput"><span class="identifier">upper_bound</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>
              </p>
            </td>
<td>
              <p>
                No equivalent. Since the elements aren't ordered <code class="computeroutput"><span class="identifier">lower_bound</span></code>
                and <code class="computeroutput"><span class="identifier">upper_bound</span></code> would
                be meaningless.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">equal_range</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>
                returns an empty range at the position that k would be inserted if
                k isn't present in the container.
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">equal_range</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>
                returns a range at the end of the container if k isn't present in
                the container. It can't return a positioned range as k could be inserted
                into multiple place. To find out the bucket that k would be inserted
                into use <code class="computeroutput"><span class="identifier">bucket</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>.
                But remember that an insert can cause the container to rehash - meaning
                that the element can be inserted into a different bucket.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">iterator</span></code>, <code class="computeroutput"><span class="identifier">const_iterator</span></code> are of the bidirectional
                category.
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">iterator</span></code>, <code class="computeroutput"><span class="identifier">const_iterator</span></code> are of at least
                the forward category.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Iterators, pointers and references to the container's elements are
                never invalidated.
              </p>
            </td>
<td>
              <p>
                <a class="link" href="buckets.html#unordered.buckets.iterator_invalidation">Iterators
                can be invalidated by calls to insert or rehash</a>. Pointers
                and references to the container's elements are never invalidated.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Iterators iterate through the container in the order defined by the
                comparison object.
              </p>
            </td>
<td>
              <p>
                Iterators iterate through the container in an arbitrary order, that
                can change as elements are inserted. Although, equivalent elements
                are always adjacent.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                No equivalent
              </p>
            </td>
<td>
              <p>
                Local iterators can be used to iterate through individual buckets.
                (The order of local iterators and iterators aren't required to have
                any correspondence.)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Can be compared using the <code class="computeroutput"><span class="special">==</span></code>,
                <code class="computeroutput"><span class="special">!=</span></code>, <code class="computeroutput"><span class="special">&lt;</span></code>,
                <code class="computeroutput"><span class="special">&lt;=</span></code>, <code class="computeroutput"><span class="special">&gt;</span></code>, <code class="computeroutput"><span class="special">&gt;=</span></code>
                operators.
              </p>
            </td>
<td>
              <p>
                Can be compared using the <code class="computeroutput"><span class="special">==</span></code>
                and <code class="computeroutput"><span class="special">!=</span></code> operators.
              </p>
            </td>
</tr>
<tr>
<td>
            </td>
<td>
              <p>
                When inserting with a hint, implementations are permitted to ignore
                the hint.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">erase</span></code> never throws
                an exception
              </p>
            </td>
<td>
              <p>
                The containers' hash or predicate function can throw exceptions from
                <code class="computeroutput"><span class="identifier">erase</span></code>
              </p>
            </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><div class="table">
<a name="unordered.comparison.complexity_guarantees"></a><p class="title"><b>Table&#160;44.5.&#160;Complexity Guarantees</b></p>
<div class="table-contents"><table class="table" summary="Complexity Guarantees">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
              <p>
                Operation
              </p>
            </th>
<th>
              <p>
                Associative Containers
              </p>
            </th>
<th>
              <p>
                Unordered Associative Containers
              </p>
            </th>
</tr></thead>
<tbody>
<tr>
<td>
              <p>
                Construction of empty container
              </p>
            </td>
<td>
              <p>
                constant
              </p>
            </td>
<td>
              <p>
                O(<span class="emphasis"><em>n</em></span>) where <span class="emphasis"><em>n</em></span> is the minimum
                number of buckets.
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Construction of container from a range of <span class="emphasis"><em>N</em></span>
                elements
              </p>
            </td>
<td>
              <p>
                O(<span class="emphasis"><em>N</em></span> log <span class="emphasis"><em>N</em></span>), O(<span class="emphasis"><em>N</em></span>)
                if the range is sorted with <code class="computeroutput"><span class="identifier">value_comp</span><span class="special">()</span></code>
              </p>
            </td>
<td>
              <p>
                Average case O(<span class="emphasis"><em>N</em></span>), worst case O(<span class="emphasis"><em>N</em></span><sup>2</sup>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Insert a single element
              </p>
            </td>
<td>
              <p>
                logarithmic
              </p>
            </td>
<td>
              <p>
                Average case constant, worst case linear
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Insert a single element with a hint
              </p>
            </td>
<td>
              <p>
                Amortized constant if t elements inserted right after hint, logarithmic
                otherwise
              </p>
            </td>
<td>
              <p>
                Average case constant, worst case linear (ie. the same as a normal
                insert).
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Inserting a range of <span class="emphasis"><em>N</em></span> elements
              </p>
            </td>
<td>
              <p>
                <span class="emphasis"><em>N</em></span> log(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>+<span class="emphasis"><em>N</em></span>)
              </p>
            </td>
<td>
              <p>
                Average case O(<span class="emphasis"><em>N</em></span>), worst case O(<span class="emphasis"><em>N</em></span>
                * <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Erase by key, <code class="computeroutput"><span class="identifier">k</span></code>
              </p>
            </td>
<td>
              <p>
                O(log(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
                + <code class="computeroutput"><span class="identifier">count</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>)
              </p>
            </td>
<td>
              <p>
                Average case: O(<code class="computeroutput"><span class="identifier">count</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>), Worst case: O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Erase a single element by iterator
              </p>
            </td>
<td>
              <p>
                Amortized constant
              </p>
            </td>
<td>
              <p>
                Average case: O(1), Worst case: O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Erase a range of <span class="emphasis"><em>N</em></span> elements
              </p>
            </td>
<td>
              <p>
                O(log(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
                + <span class="emphasis"><em>N</em></span>)
              </p>
            </td>
<td>
              <p>
                Average case: O(<span class="emphasis"><em>N</em></span>), Worst case: O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Clearing the container
              </p>
            </td>
<td>
              <p>
                O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
<td>
              <p>
                O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Find
              </p>
            </td>
<td>
              <p>
                logarithmic
              </p>
            </td>
<td>
              <p>
                Average case: O(1), Worst case: O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                Count
              </p>
            </td>
<td>
              <p>
                O(log(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
                + <code class="computeroutput"><span class="identifier">count</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>)
              </p>
            </td>
<td>
              <p>
                Average case: O(1), Worst case: O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">equal_range</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>
              </p>
            </td>
<td>
              <p>
                logarithmic
              </p>
            </td>
<td>
              <p>
                Average case: O(<code class="computeroutput"><span class="identifier">count</span><span class="special">(</span><span class="identifier">k</span><span class="special">)</span></code>), Worst case: O(<code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>)
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">lower_bound</span></code>,<code class="computeroutput"><span class="identifier">upper_bound</span></code>
              </p>
            </td>
<td>
              <p>
                logarithmic
              </p>
            </td>
<td>
              <p>
                n/a
              </p>
            </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2003, 2004 Jeremy B. Maitin-Shepard<br>Copyright &#169; 2005-2008 Daniel
      James<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        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>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="hash_equality.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../unordered.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="compliance.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>