comparison.qbk 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. [/ Copyright 2006-2011 Daniel James.
  2. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ]
  4. [section:comparison Comparison with Associative Containers]
  5. [table:interface_differences Interface differences.
  6. [[Associative Containers] [Unordered Associative Containers]]
  7. [
  8. [Parameterized by an ordering relation `Compare`]
  9. [Parameterized by a function object `Hash` and an equivalence relation
  10. `Pred`]
  11. ]
  12. [
  13. [Keys can be compared using `key_compare` which is accessed by member function `key_comp()`,
  14. values can be compared using `value_compare` which is accessed by member function `value_comp()`.]
  15. [Keys can be hashed using `hasher` which is accessed by member function `hash_function()`,
  16. and checked for equality using `key_equal` which is accessed by member function `key_eq()`.
  17. There is no function object for compared or hashing values.]
  18. ]
  19. [
  20. [Constructors have optional extra parameters for the comparison object.]
  21. [Constructors have optional extra parameters for the initial minimum
  22. number of buckets, a hash function and an equality object.]
  23. ]
  24. [
  25. [Keys `k1`, `k2` are considered equivalent if
  26. `!Compare(k1, k2) && !Compare(k2, k1)`]
  27. [Keys `k1`, `k2` are considered equivalent if `Pred(k1, k2)`]
  28. ]
  29. [
  30. [Member function `lower_bound(k)` and `upper_bound(k)`]
  31. [No equivalent. Since the elements aren't ordered `lower_bound` and
  32. `upper_bound` would be meaningless.]
  33. ]
  34. [
  35. [`equal_range(k)` returns an empty range at the position that k
  36. would be inserted if k isn't present in the container.]
  37. [`equal_range(k)` returns a range at the end of the container if
  38. k isn't present in the container. It can't return a positioned
  39. range as k could be inserted into multiple place. To find out the
  40. bucket that k would be inserted into use `bucket(k)`. But remember
  41. that an insert can cause the container to rehash - meaning that the
  42. element can be inserted into a different bucket.]
  43. ]
  44. [
  45. [`iterator`, `const_iterator` are of the bidirectional category.]
  46. [`iterator`, `const_iterator` are of at least the forward category.]
  47. ]
  48. [
  49. [Iterators, pointers and references to the container's elements are
  50. never invalidated.]
  51. [[link unordered.buckets.iterator_invalidation Iterators can
  52. be invalidated by calls to insert or rehash]. Pointers and
  53. references to the container's elements are never invalidated.]
  54. ]
  55. [
  56. [Iterators iterate through the container in the order defined by
  57. the comparison object.]
  58. [Iterators iterate through the container in an arbitrary order, that
  59. can change as elements are inserted, although equivalent elements
  60. are always adjacent.]
  61. ]
  62. [
  63. [No equivalent]
  64. [Local iterators can be used to iterate through individual buckets.
  65. (The order of local iterators and iterators aren't
  66. required to have any correspondence.)]
  67. ]
  68. [
  69. [Can be compared using the `==`, `!=`, `<`, `<=`, `>`, `>=` operators.]
  70. [Can be compared using the `==` and `!=` operators.]
  71. ]
  72. [
  73. []
  74. [When inserting with a hint, implementations are permitted to ignore
  75. the hint.]
  76. ]
  77. [
  78. [`erase` never throws an exception]
  79. [The containers' hash or predicate function can throw exceptions
  80. from `erase`]
  81. ]
  82. ]
  83. [table:complexity_guarantees Complexity Guarantees
  84. [[Operation] [Associative Containers] [Unordered Associative Containers]]
  85. [
  86. [Construction of empty container]
  87. [constant]
  88. [O(/n/) where /n/ is the minimum number of buckets.]
  89. ]
  90. [
  91. [Construction of container from a range of /N/ elements]
  92. [O(/N/ log /N/), O(/N/) if the range is sorted with `value_comp()`]
  93. [Average case O(/N/), worst case
  94. O(/N/'''<superscript>2</superscript>''')]
  95. ]
  96. [
  97. [Insert a single element]
  98. [logarithmic]
  99. [Average case constant, worst case linear]
  100. ]
  101. [
  102. [Insert a single element with a hint]
  103. [Amortized constant if t elements inserted right after hint,
  104. logarithmic otherwise]
  105. [Average case constant, worst case linear (ie. the same as
  106. a normal insert).]
  107. ]
  108. [
  109. [Inserting a range of /N/ elements]
  110. [ /N/ log(`size()`+/N/) ]
  111. [Average case O(/N/), worst case O(/N/ * `size()`)]
  112. ]
  113. [
  114. [Erase by key, `k`]
  115. [O(log(`size()`) + `count(k)`)]
  116. [Average case: O(`count(k)`), Worst case: O(`size()`)]
  117. ]
  118. [
  119. [Erase a single element by iterator]
  120. [Amortized constant]
  121. [Average case: O(1), Worst case: O(`size()`)]
  122. ]
  123. [
  124. [Erase a range of /N/ elements]
  125. [O(log(`size()`) + /N/)]
  126. [Average case: O(/N/), Worst case: O(`size()`)]
  127. ]
  128. [
  129. [Clearing the container]
  130. [O(`size()`)]
  131. [O(`size()`)]
  132. ]
  133. [
  134. [Find]
  135. [logarithmic]
  136. [Average case: O(1), Worst case: O(`size()`)]
  137. ]
  138. [/ TODO: Average case is probably wrong. ]
  139. [
  140. [Count]
  141. [O(log(`size()`) + `count(k)`)]
  142. [Average case: O(1), Worst case: O(`size()`)]
  143. ]
  144. [
  145. [`equal_range(k)`]
  146. [logarithmic]
  147. [Average case: O(`count(k)`), Worst case: O(`size()`)]
  148. ]
  149. [
  150. [`lower_bound`,`upper_bound`]
  151. [logarithmic]
  152. [n/a]
  153. ]
  154. ]
  155. [endsect]