- tmp/tmp0i551os4/{from.md → to.md} +945 -35
tmp/tmp0i551os4/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
### Unordered associative containers <a id="unord.req">[[unord.req]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
Unordered associative containers provide an ability for fast retrieval
|
| 4 |
of data based on keys. The worst-case complexity for most operations is
|
| 5 |
linear, but the average case is much faster. The library provides four
|
| 6 |
unordered associative containers: `unordered_set`, `unordered_map`,
|
| 7 |
`unordered_multiset`, and `unordered_multimap`.
|
|
@@ -73,54 +75,956 @@ per bucket is kept below a bound. Rehashing invalidates iterators,
|
|
| 73 |
changes ordering between elements, and changes which buckets elements
|
| 74 |
appear in, but does not invalidate pointers or references to elements.
|
| 75 |
For `unordered_multiset` and `unordered_multimap`, rehashing preserves
|
| 76 |
the relative ordering of equivalent elements.
|
| 77 |
|
| 78 |
-
|
| 79 |
-
Allocator-aware containers [[container.requirements.general]], except
|
| 80 |
-
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 81 |
-
placed on `value_type` in [[container.alloc.req]] apply instead to
|
| 82 |
-
`key_type` and `mapped_type`.
|
| 83 |
-
|
| 84 |
-
[*Note 3*: For example, `key_type` and `mapped_type` are sometimes
|
| 85 |
-
required to be *Cpp17CopyAssignable* even though the associated
|
| 86 |
-
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 87 |
-
*Cpp17CopyAssignable*. — *end note*]
|
| 88 |
-
|
| 89 |
-
In [[container.hash.req]]:
|
| 90 |
|
| 91 |
- `X` denotes an unordered associative container class,
|
| 92 |
- `a` denotes a value of type `X`,
|
| 93 |
- `a2` denotes a value of a type with nodes compatible with type `X` (
|
| 94 |
[[container.node.compat]]),
|
| 95 |
-
- `b` denotes a
|
| 96 |
- `a_uniq` denotes a value of type `X` when `X` supports unique keys,
|
| 97 |
- `a_eq` denotes a value of type `X` when `X` supports equivalent keys,
|
| 98 |
-
- `a_tran` denotes a
|
| 99 |
*qualified-id*s `X::key_equal::is_transparent` and
|
| 100 |
`X::hasher::is_transparent` are both valid and denote types
|
| 101 |
[[temp.deduct]],
|
| 102 |
- `i` and `j` denote input iterators that refer to `value_type`,
|
| 103 |
- `[i, j)` denotes a valid range,
|
|
|
|
|
|
|
| 104 |
- `p` and `q2` denote valid constant iterators to `a`,
|
| 105 |
- `q` and `q1` denote valid dereferenceable constant iterators to `a`,
|
| 106 |
- `r` denotes a valid dereferenceable iterator to `a`,
|
| 107 |
- `[q1, q2)` denotes a valid range in `a`,
|
| 108 |
- `il` denotes a value of type `initializer_list<value_type>`,
|
| 109 |
- `t` denotes a value of type `X::value_type`,
|
| 110 |
- `k` denotes a value of type `key_type`,
|
| 111 |
-
- `hf` denotes a
|
| 112 |
-
- `eq` denotes a
|
| 113 |
- `ke` is a value such that
|
| 114 |
-
- `eq(r1, ke) == eq(ke, r1)`
|
| 115 |
- `hf(r1) == hf(ke)` if `eq(r1, ke)` is `true`, and
|
| 116 |
-
- `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
where `r1` and `r2` are keys of elements in `a_tran`,
|
| 119 |
- `n` denotes a value of type `size_type`,
|
| 120 |
- `z` denotes a value of type `float`, and
|
| 121 |
-
- `nh` denotes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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key group \[`Ea1`,
|
| 125 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 126 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
|
@@ -140,42 +1044,48 @@ same container), then the average-case complexity for
|
|
| 140 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 141 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 142 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 143 |
`operator!=` on unordered containers is undefined unless the `Pred`
|
| 144 |
function object has the same behavior for both containers and the
|
| 145 |
-
equality comparison function for `Key` is a refinement[^1]
|
| 146 |
-
|
|
|
|
| 147 |
|
| 148 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 149 |
associative container are of at least the forward iterator category. For
|
| 150 |
unordered associative containers where the key type and value type are
|
| 151 |
the same, both `iterator` and `const_iterator` are constant iterators.
|
| 152 |
|
| 153 |
-
The `insert` and `emplace` members shall not affect the
|
| 154 |
-
references to container elements, but may invalidate all
|
| 155 |
-
the container. The `erase` members shall invalidate only
|
| 156 |
-
references to the erased elements, and preserve the
|
| 157 |
-
the elements that are not erased.
|
| 158 |
|
| 159 |
-
The `insert` and `emplace` members shall not affect the
|
| 160 |
-
iterators if `(N+n) <= z * B`, where `N` is the number of
|
| 161 |
-
the container prior to the insert operation, `n` is the
|
| 162 |
-
elements inserted, `B` is the container’s bucket count, and
|
| 163 |
-
container’s maximum load factor.
|
| 164 |
|
| 165 |
The `extract` members invalidate only iterators to the removed element,
|
| 166 |
and preserve the relative order of the elements that are not erased;
|
| 167 |
pointers and references to the removed element remain valid. However,
|
| 168 |
accessing the element through such pointers and references while the
|
| 169 |
element is owned by a `node_type` is undefined behavior. References and
|
| 170 |
pointers to an element obtained while it is owned by a `node_type` are
|
| 171 |
invalidated if the element is successfully inserted.
|
| 172 |
|
| 173 |
-
The member function templates `find`, `count`, `equal_range`,
|
| 174 |
-
`contains` shall not participate in overload
|
| 175 |
-
*qualified-id*s `Pred::is_transparent` and
|
| 176 |
-
both valid and denote types [[temp.deduct]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
A deduction guide for an unordered associative container shall not
|
| 179 |
participate in overload resolution if any of the following are true:
|
| 180 |
|
| 181 |
- It has an `InputIterator` template parameter and a type that does not
|
|
|
|
| 1 |
### Unordered associative containers <a id="unord.req">[[unord.req]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="unord.req.general">[[unord.req.general]]</a>
|
| 4 |
+
|
| 5 |
Unordered associative containers provide an ability for fast retrieval
|
| 6 |
of data based on keys. The worst-case complexity for most operations is
|
| 7 |
linear, but the average case is much faster. The library provides four
|
| 8 |
unordered associative containers: `unordered_set`, `unordered_map`,
|
| 9 |
`unordered_multiset`, and `unordered_multimap`.
|
|
|
|
| 75 |
changes ordering between elements, and changes which buckets elements
|
| 76 |
appear in, but does not invalidate pointers or references to elements.
|
| 77 |
For `unordered_multiset` and `unordered_multimap`, rehashing preserves
|
| 78 |
the relative ordering of equivalent elements.
|
| 79 |
|
| 80 |
+
In this subclause,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
- `X` denotes an unordered associative container class,
|
| 83 |
- `a` denotes a value of type `X`,
|
| 84 |
- `a2` denotes a value of a type with nodes compatible with type `X` (
|
| 85 |
[[container.node.compat]]),
|
| 86 |
+
- `b` denotes a value of type `X` or `const X`,
|
| 87 |
- `a_uniq` denotes a value of type `X` when `X` supports unique keys,
|
| 88 |
- `a_eq` denotes a value of type `X` when `X` supports equivalent keys,
|
| 89 |
+
- `a_tran` denotes a value of type `X` or `const X` when the
|
| 90 |
*qualified-id*s `X::key_equal::is_transparent` and
|
| 91 |
`X::hasher::is_transparent` are both valid and denote types
|
| 92 |
[[temp.deduct]],
|
| 93 |
- `i` and `j` denote input iterators that refer to `value_type`,
|
| 94 |
- `[i, j)` denotes a valid range,
|
| 95 |
+
- `rg` denotes a value of a type `R` that models
|
| 96 |
+
`container-compatible-range<value_type>`,
|
| 97 |
- `p` and `q2` denote valid constant iterators to `a`,
|
| 98 |
- `q` and `q1` denote valid dereferenceable constant iterators to `a`,
|
| 99 |
- `r` denotes a valid dereferenceable iterator to `a`,
|
| 100 |
- `[q1, q2)` denotes a valid range in `a`,
|
| 101 |
- `il` denotes a value of type `initializer_list<value_type>`,
|
| 102 |
- `t` denotes a value of type `X::value_type`,
|
| 103 |
- `k` denotes a value of type `key_type`,
|
| 104 |
+
- `hf` denotes a value of type `hasher` or `const hasher`,
|
| 105 |
+
- `eq` denotes a value of type `key_equal` or `const key_equal`,
|
| 106 |
- `ke` is a value such that
|
| 107 |
+
- `eq(r1, ke) == eq(ke, r1)`,
|
| 108 |
- `hf(r1) == hf(ke)` if `eq(r1, ke)` is `true`, and
|
| 109 |
+
- if any two of `eq(r1, ke)`, `eq(r2, ke)`, and `eq(r1, r2)` are
|
| 110 |
+
`true`, then all three are `true`,
|
| 111 |
+
|
| 112 |
+
where `r1` and `r2` are keys of elements in `a_tran`,
|
| 113 |
+
- `kx` is a value such that
|
| 114 |
+
- `eq(r1, kx) == eq(kx, r1)`,
|
| 115 |
+
- `hf(r1) == hf(kx)` if `eq(r1, kx)` is `true`,
|
| 116 |
+
- if any two of `eq(r1, kx)`, `eq(r2, kx)`, and `eq(r1, r2)` are
|
| 117 |
+
`true`, then all three are `true`, and
|
| 118 |
+
- `kx` is not convertible to either `iterator` or `const_iterator`,
|
| 119 |
|
| 120 |
where `r1` and `r2` are keys of elements in `a_tran`,
|
| 121 |
- `n` denotes a value of type `size_type`,
|
| 122 |
- `z` denotes a value of type `float`, and
|
| 123 |
+
- `nh` denotes an rvalue of type `X::node_type`.
|
| 124 |
+
|
| 125 |
+
A type `X` meets the *unordered associative container* requirements if
|
| 126 |
+
`X` meets all the requirements of an allocator-aware container
|
| 127 |
+
[[container.requirements.general]] and the following types, statements,
|
| 128 |
+
and expressions are well-formed and have the specified semantics, except
|
| 129 |
+
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 130 |
+
placed on `value_type` in [[container.alloc.reqmts]] apply instead to
|
| 131 |
+
`key_type` and `mapped_type`.
|
| 132 |
+
|
| 133 |
+
[*Note 3*: For example, `key_type` and `mapped_type` are sometimes
|
| 134 |
+
required to be *Cpp17CopyAssignable* even though the associated
|
| 135 |
+
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 136 |
+
*Cpp17CopyAssignable*. — *end note*]
|
| 137 |
+
|
| 138 |
+
``` cpp
|
| 139 |
+
typename X::key_type
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
*Result:* `Key`.
|
| 143 |
+
|
| 144 |
+
``` cpp
|
| 145 |
+
typename X::mapped_type
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
*Result:* `T`.
|
| 149 |
+
|
| 150 |
+
*Remarks:* For `unordered_map` and `unordered_multimap` only.
|
| 151 |
+
|
| 152 |
+
``` cpp
|
| 153 |
+
typename X::value_type
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
*Result:* `Key` for `unordered_set` and `unordered_multiset` only;
|
| 157 |
+
`pair<const Key, T>` for `unordered_map` and `unordered_multimap` only.
|
| 158 |
+
|
| 159 |
+
*Preconditions:* `value_type` is *Cpp17Erasable* from `X`.
|
| 160 |
+
|
| 161 |
+
``` cpp
|
| 162 |
+
typename X::hasher
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
*Result:* `Hash`.
|
| 166 |
+
|
| 167 |
+
*Preconditions:* `Hash` is a unary function object type such that the
|
| 168 |
+
expression `hf(k)` has type `size_t`.
|
| 169 |
+
|
| 170 |
+
``` cpp
|
| 171 |
+
typename X::key_equal
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
*Result:* `Pred`.
|
| 175 |
+
|
| 176 |
+
*Preconditions:* `Pred` meets the *Cpp17CopyConstructible* requirements.
|
| 177 |
+
`Pred` is a binary predicate that takes two arguments of type `Key`.
|
| 178 |
+
`Pred` is an equivalence relation.
|
| 179 |
+
|
| 180 |
+
``` cpp
|
| 181 |
+
typename X::local_iterator
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
*Result:* An iterator type whose category, value type, difference type,
|
| 185 |
+
and pointer and reference types are the same as `X::iterator`’s.
|
| 186 |
+
|
| 187 |
+
[*Note 1*: A `local_iterator` object can be used to iterate through a
|
| 188 |
+
single bucket, but cannot be used to iterate across
|
| 189 |
+
buckets. — *end note*]
|
| 190 |
+
|
| 191 |
+
``` cpp
|
| 192 |
+
typename X::const_local_iterator
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
*Result:* An iterator type whose category, value type, difference type,
|
| 196 |
+
and pointer and reference types are the same as `X::const_iterator`’s.
|
| 197 |
+
|
| 198 |
+
[*Note 2*: A `const_local_iterator` object can be used to iterate
|
| 199 |
+
through a single bucket, but cannot be used to iterate across
|
| 200 |
+
buckets. — *end note*]
|
| 201 |
+
|
| 202 |
+
``` cpp
|
| 203 |
+
typename X::node_type
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
*Result:* A specialization of a *node-handle* class
|
| 207 |
+
template [[container.node]], such that the public nested types are the
|
| 208 |
+
same types as the corresponding types in `X`.
|
| 209 |
+
|
| 210 |
+
``` cpp
|
| 211 |
+
X(n, hf, eq)
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 215 |
+
using `hf` as the hash function and `eq` as the key equality predicate.
|
| 216 |
+
|
| 217 |
+
*Complexity:* 𝑂(`n`)
|
| 218 |
+
|
| 219 |
+
``` cpp
|
| 220 |
+
X(n, hf)
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
*Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
|
| 224 |
+
requirements.
|
| 225 |
+
|
| 226 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 227 |
+
using `hf` as the hash function and `key_equal()` as the key equality
|
| 228 |
+
predicate.
|
| 229 |
+
|
| 230 |
+
*Complexity:* 𝑂(`n`)
|
| 231 |
+
|
| 232 |
+
``` cpp
|
| 233 |
+
X(n)
|
| 234 |
+
```
|
| 235 |
+
|
| 236 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 237 |
+
*Cpp17DefaultConstructible* requirements.
|
| 238 |
+
|
| 239 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 240 |
+
using `hasher()` as the hash function and `key_equal()` as the key
|
| 241 |
+
equality predicate.
|
| 242 |
+
|
| 243 |
+
*Complexity:* 𝑂(`n`)
|
| 244 |
+
|
| 245 |
+
``` cpp
|
| 246 |
+
X a = X();
|
| 247 |
+
X a;
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 251 |
+
*Cpp17DefaultConstructible* requirements.
|
| 252 |
+
|
| 253 |
+
*Effects:* Constructs an empty container with an unspecified number of
|
| 254 |
+
buckets, using `hasher()` as the hash function and `key_equal()` as the
|
| 255 |
+
key equality predicate.
|
| 256 |
+
|
| 257 |
+
*Complexity:* Constant.
|
| 258 |
+
|
| 259 |
+
``` cpp
|
| 260 |
+
X(i, j, n, hf, eq)
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 264 |
+
from `*i`.
|
| 265 |
+
|
| 266 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 267 |
+
using `hf` as the hash function and `eq` as the key equality predicate,
|
| 268 |
+
and inserts elements from \[`i`, `j`) into it.
|
| 269 |
+
|
| 270 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 271 |
+
𝑂(N^2).
|
| 272 |
+
|
| 273 |
+
``` cpp
|
| 274 |
+
X(i, j, n, hf)
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
+
*Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
|
| 278 |
+
requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
|
| 279 |
+
`*i`.
|
| 280 |
+
|
| 281 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 282 |
+
using `hf` as the hash function and `key_equal()` as the key equality
|
| 283 |
+
predicate, and inserts elements from \[`i`, `j`) into it.
|
| 284 |
+
|
| 285 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 286 |
+
𝑂(N^2).
|
| 287 |
+
|
| 288 |
+
``` cpp
|
| 289 |
+
X(i, j, n)
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 293 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 294 |
+
*Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 295 |
+
|
| 296 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 297 |
+
using `hasher()` as the hash function and `key_equal()` as the key
|
| 298 |
+
equality predicate, and inserts elements from \[`i`, `j`) into it.
|
| 299 |
+
|
| 300 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 301 |
+
𝑂(N^2).
|
| 302 |
+
|
| 303 |
+
``` cpp
|
| 304 |
+
X(i, j)
|
| 305 |
+
```
|
| 306 |
+
|
| 307 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 308 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 309 |
+
*Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 310 |
+
|
| 311 |
+
*Effects:* Constructs an empty container with an unspecified number of
|
| 312 |
+
buckets, using `hasher()` as the hash function and `key_equal()` as the
|
| 313 |
+
key equality predicate, and inserts elements from \[`i`, `j`) into it.
|
| 314 |
+
|
| 315 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 316 |
+
𝑂(N^2).
|
| 317 |
+
|
| 318 |
+
``` cpp
|
| 319 |
+
X(from_range, rg, n, hf, eq)
|
| 320 |
+
```
|
| 321 |
+
|
| 322 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 323 |
+
from `*ranges::begin(rg)`.
|
| 324 |
+
|
| 325 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 326 |
+
using `hf` as the hash function and `eq` as the key equality predicate,
|
| 327 |
+
and inserts elements from `rg` into it.
|
| 328 |
+
|
| 329 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 330 |
+
case 𝑂(N^2).
|
| 331 |
+
|
| 332 |
+
``` cpp
|
| 333 |
+
X(from_range, rg, n, hf)
|
| 334 |
+
```
|
| 335 |
+
|
| 336 |
+
*Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
|
| 337 |
+
requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
|
| 338 |
+
`*ranges::begin(rg)`.
|
| 339 |
+
|
| 340 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 341 |
+
using `hf` as the hash function and `key_equal()` as the key equality
|
| 342 |
+
predicate, and inserts elements from `rg` into it.
|
| 343 |
+
|
| 344 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 345 |
+
case 𝑂(N^2).
|
| 346 |
+
|
| 347 |
+
``` cpp
|
| 348 |
+
X(from_range, rg, n)
|
| 349 |
+
```
|
| 350 |
+
|
| 351 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 352 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 353 |
+
*Cpp17EmplaceConstructible* into `X` from `*ranges::begin(rg)`.
|
| 354 |
+
|
| 355 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 356 |
+
using `hasher()` as the hash function and `key_equal()` as the key
|
| 357 |
+
equality predicate, and inserts elements from `rg` into it.
|
| 358 |
+
|
| 359 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 360 |
+
case 𝑂(N^2).
|
| 361 |
+
|
| 362 |
+
``` cpp
|
| 363 |
+
X(from_range, rg)
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 367 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 368 |
+
*Cpp17EmplaceConstructible* into `X` from `*ranges::begin(rg)`.
|
| 369 |
+
|
| 370 |
+
*Effects:* Constructs an empty container with an unspecified number of
|
| 371 |
+
buckets, using `hasher()` as the hash function and `key_equal()` as the
|
| 372 |
+
key equality predicate, and inserts elements from `rg` into it.
|
| 373 |
+
|
| 374 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 375 |
+
case 𝑂(N^2).
|
| 376 |
+
|
| 377 |
+
``` cpp
|
| 378 |
+
X(il)
|
| 379 |
+
```
|
| 380 |
+
|
| 381 |
+
*Effects:* Equivalent to `X(il.begin(), il.end())`.
|
| 382 |
+
|
| 383 |
+
``` cpp
|
| 384 |
+
X(il, n)
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), n)`.
|
| 388 |
+
|
| 389 |
+
``` cpp
|
| 390 |
+
X(il, n, hf)
|
| 391 |
+
```
|
| 392 |
+
|
| 393 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), n, hf)`.
|
| 394 |
+
|
| 395 |
+
``` cpp
|
| 396 |
+
X(il, n, hf, eq)
|
| 397 |
+
```
|
| 398 |
+
|
| 399 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), n, hf, eq)`.
|
| 400 |
+
|
| 401 |
+
``` cpp
|
| 402 |
+
X(b)
|
| 403 |
+
```
|
| 404 |
+
|
| 405 |
+
*Effects:* In addition to the container
|
| 406 |
+
requirements [[container.requirements.general]], copies the hash
|
| 407 |
+
function, predicate, and maximum load factor.
|
| 408 |
+
|
| 409 |
+
*Complexity:* Average case linear in `b.size()`, worst case quadratic.
|
| 410 |
+
|
| 411 |
+
``` cpp
|
| 412 |
+
a = b
|
| 413 |
+
```
|
| 414 |
+
|
| 415 |
+
*Result:* `X&`
|
| 416 |
+
|
| 417 |
+
*Effects:* In addition to the container requirements, copies the hash
|
| 418 |
+
function, predicate, and maximum load factor.
|
| 419 |
+
|
| 420 |
+
*Complexity:* Average case linear in `b.size()`, worst case quadratic.
|
| 421 |
+
|
| 422 |
+
``` cpp
|
| 423 |
+
a = il
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
*Result:* `X&`
|
| 427 |
+
|
| 428 |
+
*Preconditions:* `value_type` is *Cpp17CopyInsertable* into `X` and
|
| 429 |
+
*Cpp17CopyAssignable*.
|
| 430 |
+
|
| 431 |
+
*Effects:* Assigns the range \[`il.begin()`, `il.end()`) into `a`. All
|
| 432 |
+
existing elements of `a` are either assigned to or destroyed.
|
| 433 |
+
|
| 434 |
+
*Complexity:* Average case linear in `il.size()`, worst case quadratic.
|
| 435 |
+
|
| 436 |
+
``` cpp
|
| 437 |
+
b.hash_function()
|
| 438 |
+
```
|
| 439 |
+
|
| 440 |
+
*Result:* `hasher`
|
| 441 |
+
|
| 442 |
+
*Returns:* `b`’s hash function.
|
| 443 |
+
|
| 444 |
+
*Complexity:* Constant.
|
| 445 |
+
|
| 446 |
+
``` cpp
|
| 447 |
+
b.key_eq()
|
| 448 |
+
```
|
| 449 |
+
|
| 450 |
+
*Result:* `key_equal`
|
| 451 |
+
|
| 452 |
+
*Returns:* `b`’s key equality predicate.
|
| 453 |
+
|
| 454 |
+
*Complexity:* Constant.
|
| 455 |
+
|
| 456 |
+
``` cpp
|
| 457 |
+
a_uniq.emplace(args)
|
| 458 |
+
```
|
| 459 |
+
|
| 460 |
+
*Result:* `pair<iterator,` `bool>`
|
| 461 |
+
|
| 462 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 463 |
+
from `args`.
|
| 464 |
+
|
| 465 |
+
*Effects:* Inserts a `value_type` object `t` constructed with
|
| 466 |
+
`std::forward<Args>(args)...` if and only if there is no element in the
|
| 467 |
+
container with key equivalent to the key of `t`.
|
| 468 |
+
|
| 469 |
+
*Returns:* The `bool` component of the returned pair is `true` if and
|
| 470 |
+
only if the insertion takes place, and the iterator component of the
|
| 471 |
+
pair points to the element with key equivalent to the key of `t`.
|
| 472 |
+
|
| 473 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
|
| 474 |
+
|
| 475 |
+
``` cpp
|
| 476 |
+
a_eq.emplace(args)
|
| 477 |
+
```
|
| 478 |
+
|
| 479 |
+
*Result:* `iterator`
|
| 480 |
+
|
| 481 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 482 |
+
from `args`.
|
| 483 |
+
|
| 484 |
+
*Effects:* Inserts a `value_type` object `t` constructed with
|
| 485 |
+
`std::forward<Args>(args)...`.
|
| 486 |
+
|
| 487 |
+
*Returns:* An iterator pointing to the newly inserted element.
|
| 488 |
+
|
| 489 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
|
| 490 |
+
|
| 491 |
+
``` cpp
|
| 492 |
+
a.emplace_hint(p, args)
|
| 493 |
+
```
|
| 494 |
+
|
| 495 |
+
*Result:* `iterator`
|
| 496 |
+
|
| 497 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 498 |
+
from `args`.
|
| 499 |
+
|
| 500 |
+
*Effects:* Equivalent to `a.emplace(std::forward<Args>(args)...)`.
|
| 501 |
+
|
| 502 |
+
*Returns:* An iterator pointing to the element with the key equivalent
|
| 503 |
+
to the newly inserted element. The `const_iterator` `p` is a hint
|
| 504 |
+
pointing to where the search should start. Implementations are permitted
|
| 505 |
+
to ignore the hint.
|
| 506 |
+
|
| 507 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 508 |
+
|
| 509 |
+
``` cpp
|
| 510 |
+
a_uniq.insert(t)
|
| 511 |
+
```
|
| 512 |
+
|
| 513 |
+
*Result:* `pair<iterator, bool>`
|
| 514 |
+
|
| 515 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 516 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 517 |
+
*Cpp17CopyInsertable* into `X`.
|
| 518 |
+
|
| 519 |
+
*Effects:* Inserts `t` if and only if there is no element in the
|
| 520 |
+
container with key equivalent to the key of `t`.
|
| 521 |
+
|
| 522 |
+
*Returns:* The `bool` component of the returned pair indicates whether
|
| 523 |
+
the insertion takes place, and the `iterator` component points to the
|
| 524 |
+
element with key equivalent to the key of `t`.
|
| 525 |
+
|
| 526 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
|
| 527 |
+
|
| 528 |
+
``` cpp
|
| 529 |
+
a_eq.insert(t)
|
| 530 |
+
```
|
| 531 |
+
|
| 532 |
+
*Result:* `iterator`
|
| 533 |
+
|
| 534 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 535 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 536 |
+
*Cpp17CopyInsertable* into `X`.
|
| 537 |
+
|
| 538 |
+
*Effects:* Inserts `t`.
|
| 539 |
+
|
| 540 |
+
*Returns:* An iterator pointing to the newly inserted element.
|
| 541 |
+
|
| 542 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
|
| 543 |
+
|
| 544 |
+
``` cpp
|
| 545 |
+
a.insert(p, t)
|
| 546 |
+
```
|
| 547 |
+
|
| 548 |
+
*Result:* `iterator`
|
| 549 |
+
|
| 550 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 551 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 552 |
+
*Cpp17CopyInsertable* into `X`.
|
| 553 |
+
|
| 554 |
+
*Effects:* Equivalent to `a.insert(t)`. The iterator `p` is a hint
|
| 555 |
+
pointing to where the search should start. Implementations are permitted
|
| 556 |
+
to ignore the hint.
|
| 557 |
+
|
| 558 |
+
*Returns:* An iterator pointing to the element with the key equivalent
|
| 559 |
+
to that of `t`.
|
| 560 |
+
|
| 561 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 562 |
+
|
| 563 |
+
``` cpp
|
| 564 |
+
a.insert(i, j)
|
| 565 |
+
```
|
| 566 |
+
|
| 567 |
+
*Result:* `void`
|
| 568 |
+
|
| 569 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 570 |
+
from `*i`. Neither `i` nor `j` are iterators into `a`.
|
| 571 |
+
|
| 572 |
+
*Effects:* Equivalent to `a.insert(t)` for each element in `[i,j)`.
|
| 573 |
+
|
| 574 |
+
*Complexity:* Average case 𝑂(N), where N is `distance(i, j)`, worst case
|
| 575 |
+
𝑂(N(`a.size()` + 1)).
|
| 576 |
+
|
| 577 |
+
``` cpp
|
| 578 |
+
a.insert_range(rg)
|
| 579 |
+
```
|
| 580 |
+
|
| 581 |
+
*Result:* `void`
|
| 582 |
+
|
| 583 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 584 |
+
from `*ranges::begin(rg)`. `rg` and `a` do not overlap.
|
| 585 |
+
|
| 586 |
+
*Effects:* Equivalent to `a.insert(t)` for each element `t` in `rg`.
|
| 587 |
+
|
| 588 |
+
*Complexity:* Average case 𝑂(N), where N is `ranges::distance(rg)`,
|
| 589 |
+
worst case 𝑂(N(`a.size()` + 1)).
|
| 590 |
+
|
| 591 |
+
``` cpp
|
| 592 |
+
a.insert(il)
|
| 593 |
+
```
|
| 594 |
+
|
| 595 |
+
*Effects:* Equivalent to `a.insert(il.begin(), il.end())`.
|
| 596 |
+
|
| 597 |
+
``` cpp
|
| 598 |
+
a_uniq.insert(nh)
|
| 599 |
+
```
|
| 600 |
+
|
| 601 |
+
*Result:* `insert_return_type`
|
| 602 |
+
|
| 603 |
+
*Preconditions:* `nh` is empty or
|
| 604 |
+
`a_uniq.get_allocator() == nh.get_allocator()` is `true`.
|
| 605 |
+
|
| 606 |
+
*Effects:* If `nh` is empty, has no effect. Otherwise, inserts the
|
| 607 |
+
element owned by `nh` if and only if there is no element in the
|
| 608 |
+
container with a key equivalent to `nh.key()`.
|
| 609 |
+
|
| 610 |
+
*Ensures:* If `nh` is empty, `inserted` is `false`, `position` is
|
| 611 |
+
`end()`, and `node` is empty. Otherwise if the insertion took place,
|
| 612 |
+
`inserted` is `true`, `position` points to the inserted element, and
|
| 613 |
+
`node` is empty; if the insertion failed, `inserted` is `false`, `node`
|
| 614 |
+
has the previous value of `nh`, and `position` points to an element with
|
| 615 |
+
a key equivalent to `nh.key()`.
|
| 616 |
+
|
| 617 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
|
| 618 |
+
|
| 619 |
+
``` cpp
|
| 620 |
+
a_eq.insert(nh)
|
| 621 |
+
```
|
| 622 |
+
|
| 623 |
+
*Result:* `iterator`
|
| 624 |
+
|
| 625 |
+
*Preconditions:* `nh` is empty or
|
| 626 |
+
`a_eq.get_allocator() == nh.get_allocator()` is `true`.
|
| 627 |
+
|
| 628 |
+
*Effects:* If `nh` is empty, has no effect and returns `a_eq.end()`.
|
| 629 |
+
Otherwise, inserts the element owned by `nh` and returns an iterator
|
| 630 |
+
pointing to the newly inserted element.
|
| 631 |
+
|
| 632 |
+
*Ensures:* `nh` is empty.
|
| 633 |
+
|
| 634 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
|
| 635 |
+
|
| 636 |
+
``` cpp
|
| 637 |
+
a.insert(q, nh)
|
| 638 |
+
```
|
| 639 |
+
|
| 640 |
+
*Result:* `iterator`
|
| 641 |
+
|
| 642 |
+
*Preconditions:* `nh` is empty or
|
| 643 |
+
`a.get_allocator() == nh.get_allocator()` is `true`.
|
| 644 |
+
|
| 645 |
+
*Effects:* If `nh` is empty, has no effect and returns `a.end()`.
|
| 646 |
+
Otherwise, inserts the element owned by `nh` if and only if there is no
|
| 647 |
+
element with key equivalent to `nh.key()` in containers with unique
|
| 648 |
+
keys; always inserts the element owned by `nh` in containers with
|
| 649 |
+
equivalent keys. The iterator `q` is a hint pointing to where the search
|
| 650 |
+
should start. Implementations are permitted to ignore the hint.
|
| 651 |
+
|
| 652 |
+
*Ensures:* `nh` is empty if insertion succeeds, unchanged if insertion
|
| 653 |
+
fails.
|
| 654 |
+
|
| 655 |
+
*Returns:* An iterator pointing to the element with key equivalent to
|
| 656 |
+
`nh.key()`.
|
| 657 |
+
|
| 658 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 659 |
+
|
| 660 |
+
``` cpp
|
| 661 |
+
a.extract(k)
|
| 662 |
+
```
|
| 663 |
+
|
| 664 |
+
*Result:* `node_type`
|
| 665 |
+
|
| 666 |
+
*Effects:* Removes an element in the container with key equivalent to
|
| 667 |
+
`k`.
|
| 668 |
+
|
| 669 |
+
*Returns:* A `node_type` owning the element if found, otherwise an empty
|
| 670 |
+
`node_type`.
|
| 671 |
+
|
| 672 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 673 |
+
|
| 674 |
+
``` cpp
|
| 675 |
+
a_tran.extract(kx)
|
| 676 |
+
```
|
| 677 |
+
|
| 678 |
+
*Result:* `node_type`
|
| 679 |
+
|
| 680 |
+
*Effects:* Removes an element in the container with key equivalent to
|
| 681 |
+
`kx`.
|
| 682 |
+
|
| 683 |
+
*Returns:* A `node_type` owning the element if found, otherwise an empty
|
| 684 |
+
`node_type`.
|
| 685 |
+
|
| 686 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_tran.size()`).
|
| 687 |
+
|
| 688 |
+
``` cpp
|
| 689 |
+
a.extract(q)
|
| 690 |
+
```
|
| 691 |
+
|
| 692 |
+
*Result:* `node_type`
|
| 693 |
+
|
| 694 |
+
*Effects:* Removes the element pointed to by `q`.
|
| 695 |
+
|
| 696 |
+
*Returns:* A `node_type` owning that element.
|
| 697 |
+
|
| 698 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 699 |
+
|
| 700 |
+
``` cpp
|
| 701 |
+
a.merge(a2)
|
| 702 |
+
```
|
| 703 |
+
|
| 704 |
+
*Result:* `void`
|
| 705 |
+
|
| 706 |
+
*Preconditions:* `a.get_allocator() == a2.get_allocator()`.
|
| 707 |
+
|
| 708 |
+
*Effects:* Attempts to extract each element in `a2` and insert it into
|
| 709 |
+
`a` using the hash function and key equality predicate of `a`. In
|
| 710 |
+
containers with unique keys, if there is an element in `a` with key
|
| 711 |
+
equivalent to the key of an element from `a2`, then that element is not
|
| 712 |
+
extracted from `a2`.
|
| 713 |
+
|
| 714 |
+
*Ensures:* Pointers and references to the transferred elements of `a2`
|
| 715 |
+
refer to those same elements but as members of `a`. Iterators referring
|
| 716 |
+
to the transferred elements and all iterators referring to `a` will be
|
| 717 |
+
invalidated, but iterators to elements remaining in `a2` will remain
|
| 718 |
+
valid.
|
| 719 |
+
|
| 720 |
+
*Complexity:* Average case 𝑂(N), where N is `a2.size()`, worst case
|
| 721 |
+
𝑂(N`*a.size() + N`).
|
| 722 |
+
|
| 723 |
+
``` cpp
|
| 724 |
+
a.erase(k)
|
| 725 |
+
```
|
| 726 |
+
|
| 727 |
+
*Result:* `size_type`
|
| 728 |
+
|
| 729 |
+
*Effects:* Erases all elements with key equivalent to `k`.
|
| 730 |
+
|
| 731 |
+
*Returns:* The number of elements erased.
|
| 732 |
+
|
| 733 |
+
*Complexity:* Average case 𝑂(`a.count(k)`), worst case 𝑂(`a.size()`).
|
| 734 |
+
|
| 735 |
+
``` cpp
|
| 736 |
+
a_tran.erase(kx)
|
| 737 |
+
```
|
| 738 |
+
|
| 739 |
+
*Result:* `size_type`
|
| 740 |
+
|
| 741 |
+
*Effects:* Erases all elements with key equivalent to `kx`.
|
| 742 |
+
|
| 743 |
+
*Returns:* The number of elements erased.
|
| 744 |
+
|
| 745 |
+
*Complexity:* Average case 𝑂(`a_tran.count(kx)`), worst case
|
| 746 |
+
𝑂(`a_tran.size()`).
|
| 747 |
+
|
| 748 |
+
``` cpp
|
| 749 |
+
a.erase(q)
|
| 750 |
+
```
|
| 751 |
+
|
| 752 |
+
*Result:* `iterator`
|
| 753 |
+
|
| 754 |
+
*Effects:* Erases the element pointed to by `q`.
|
| 755 |
+
|
| 756 |
+
*Returns:* The iterator immediately following `q` prior to the erasure.
|
| 757 |
+
|
| 758 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 759 |
+
|
| 760 |
+
``` cpp
|
| 761 |
+
a.erase(r)
|
| 762 |
+
```
|
| 763 |
+
|
| 764 |
+
*Result:* `iterator`
|
| 765 |
+
|
| 766 |
+
*Effects:* Erases the element pointed to by `r`.
|
| 767 |
+
|
| 768 |
+
*Returns:* The iterator immediately following `r` prior to the erasure.
|
| 769 |
+
|
| 770 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 771 |
+
|
| 772 |
+
``` cpp
|
| 773 |
+
a.erase(q1, q2)
|
| 774 |
+
```
|
| 775 |
+
|
| 776 |
+
*Result:* `iterator`
|
| 777 |
+
|
| 778 |
+
*Effects:* Erases all elements in the range `[q1, q2)`.
|
| 779 |
+
|
| 780 |
+
*Returns:* The iterator immediately following the erased elements prior
|
| 781 |
+
to the erasure.
|
| 782 |
+
|
| 783 |
+
*Complexity:* Average case linear in `distance(q1, q2)`, worst case
|
| 784 |
+
𝑂(`a.size()`).
|
| 785 |
+
|
| 786 |
+
``` cpp
|
| 787 |
+
a.clear()
|
| 788 |
+
```
|
| 789 |
+
|
| 790 |
+
*Result:* `void`
|
| 791 |
+
|
| 792 |
+
*Effects:* Erases all elements in the container.
|
| 793 |
+
|
| 794 |
+
*Ensures:* `a.empty()` is `true`.
|
| 795 |
+
|
| 796 |
+
*Complexity:* Linear in `a.size()`.
|
| 797 |
+
|
| 798 |
+
``` cpp
|
| 799 |
+
b.find(k)
|
| 800 |
+
```
|
| 801 |
+
|
| 802 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 803 |
+
|
| 804 |
+
*Returns:* An iterator pointing to an element with key equivalent to
|
| 805 |
+
`k`, or `b.end()` if no such element exists.
|
| 806 |
+
|
| 807 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`b.size()`).
|
| 808 |
+
|
| 809 |
+
``` cpp
|
| 810 |
+
a_tran.find(ke)
|
| 811 |
+
```
|
| 812 |
+
|
| 813 |
+
*Result:* `iterator`; `const_iterator` for constant `a_tran`.
|
| 814 |
+
|
| 815 |
+
*Returns:* An iterator pointing to an element with key equivalent to
|
| 816 |
+
`ke`, or `a_tran.end()` if no such element exists.
|
| 817 |
+
|
| 818 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_tran.size()`).
|
| 819 |
+
|
| 820 |
+
``` cpp
|
| 821 |
+
b.count(k)
|
| 822 |
+
```
|
| 823 |
+
|
| 824 |
+
*Result:* `size_type`
|
| 825 |
+
|
| 826 |
+
*Returns:* The number of elements with key equivalent to `k`.
|
| 827 |
+
|
| 828 |
+
*Complexity:* Average case 𝑂(`b.count(k)`), worst case 𝑂(`b.size()`).
|
| 829 |
+
|
| 830 |
+
``` cpp
|
| 831 |
+
a_tran.count(ke)
|
| 832 |
+
```
|
| 833 |
+
|
| 834 |
+
*Result:* `size_type`
|
| 835 |
+
|
| 836 |
+
*Returns:* The number of elements with key equivalent to `ke`.
|
| 837 |
+
|
| 838 |
+
*Complexity:* Average case 𝑂(`a_tran.count(ke)`), worst case
|
| 839 |
+
𝑂(`a_tran.size()`).
|
| 840 |
+
|
| 841 |
+
``` cpp
|
| 842 |
+
b.contains(k)
|
| 843 |
+
```
|
| 844 |
+
|
| 845 |
+
*Effects:* Equivalent to `b.find(k) != b.end()`.
|
| 846 |
+
|
| 847 |
+
``` cpp
|
| 848 |
+
a_tran.contains(ke)
|
| 849 |
+
```
|
| 850 |
+
|
| 851 |
+
*Effects:* Equivalent to `a_tran.find(ke) != a_tran.end()`.
|
| 852 |
+
|
| 853 |
+
``` cpp
|
| 854 |
+
b.equal_range(k)
|
| 855 |
+
```
|
| 856 |
+
|
| 857 |
+
*Result:* `pair<iterator, iterator>`;
|
| 858 |
+
`pair<const_iterator, const_iterator>` for constant `b`.
|
| 859 |
+
|
| 860 |
+
*Returns:* A range containing all elements with keys equivalent to `k`.
|
| 861 |
+
Returns `make_pair(b.end(), b.end())` if no such elements exist.
|
| 862 |
+
|
| 863 |
+
*Complexity:* Average case 𝑂(`b.count(k)`), worst case 𝑂(`b.size()`).
|
| 864 |
+
|
| 865 |
+
``` cpp
|
| 866 |
+
a_tran.equal_range(ke)
|
| 867 |
+
```
|
| 868 |
+
|
| 869 |
+
*Result:* `pair<iterator, iterator>`;
|
| 870 |
+
`pair<const_iterator, const_iterator>` for constant `a_tran`.
|
| 871 |
+
|
| 872 |
+
*Returns:* A range containing all elements with keys equivalent to `ke`.
|
| 873 |
+
Returns `make_pair(a_tran.end(), a_tran.end())` if no such elements
|
| 874 |
+
exist.
|
| 875 |
+
|
| 876 |
+
*Complexity:* Average case 𝑂(`a_tran.count(ke)`), worst case
|
| 877 |
+
𝑂(`a_tran.size()`).
|
| 878 |
+
|
| 879 |
+
``` cpp
|
| 880 |
+
b.bucket_count()
|
| 881 |
+
```
|
| 882 |
+
|
| 883 |
+
*Result:* `size_type`
|
| 884 |
+
|
| 885 |
+
*Returns:* The number of buckets that `b` contains.
|
| 886 |
+
|
| 887 |
+
*Complexity:* Constant.
|
| 888 |
+
|
| 889 |
+
``` cpp
|
| 890 |
+
b.max_bucket_count()
|
| 891 |
+
```
|
| 892 |
+
|
| 893 |
+
*Result:* `size_type`
|
| 894 |
+
|
| 895 |
+
*Returns:* An upper bound on the number of buckets that `b` can ever
|
| 896 |
+
contain.
|
| 897 |
+
|
| 898 |
+
*Complexity:* Constant.
|
| 899 |
+
|
| 900 |
+
``` cpp
|
| 901 |
+
b.bucket(k)
|
| 902 |
+
```
|
| 903 |
+
|
| 904 |
+
*Result:* `size_type`
|
| 905 |
+
|
| 906 |
+
*Preconditions:* `b.bucket_count() > 0`.
|
| 907 |
+
|
| 908 |
+
*Returns:* The index of the bucket in which elements with keys
|
| 909 |
+
equivalent to `k` would be found, if any such element existed. The
|
| 910 |
+
return value is in the range `[0, b.bucket_count())`.
|
| 911 |
+
|
| 912 |
+
*Complexity:* Constant.
|
| 913 |
+
|
| 914 |
+
``` cpp
|
| 915 |
+
b.bucket_size(n)
|
| 916 |
+
```
|
| 917 |
+
|
| 918 |
+
*Result:* `size_type`
|
| 919 |
+
|
| 920 |
+
*Preconditions:* `n` shall be in the range `[0, b.bucket_count())`.
|
| 921 |
+
|
| 922 |
+
*Returns:* The number of elements in the `n`ᵗʰ bucket.
|
| 923 |
+
|
| 924 |
+
*Complexity:* 𝑂(`b.bucket_size(n)`)
|
| 925 |
+
|
| 926 |
+
``` cpp
|
| 927 |
+
b.begin(n)
|
| 928 |
+
```
|
| 929 |
+
|
| 930 |
+
*Result:* `local_iterator`; `const_local_iterator` for constant `b`.
|
| 931 |
+
|
| 932 |
+
*Preconditions:* `n` is in the range `[0, b.bucket_count())`.
|
| 933 |
+
|
| 934 |
+
*Returns:* An iterator referring to the first element in the bucket. If
|
| 935 |
+
the bucket is empty, then `b.begin(n) == b.end(n)`.
|
| 936 |
+
|
| 937 |
+
*Complexity:* Constant.
|
| 938 |
+
|
| 939 |
+
``` cpp
|
| 940 |
+
b.end(n)
|
| 941 |
+
```
|
| 942 |
+
|
| 943 |
+
*Result:* `local_iterator`; `const_local_iterator` for constant `b`.
|
| 944 |
+
|
| 945 |
+
*Preconditions:* `n` is in the range `[0, b.bucket_count())`.
|
| 946 |
+
|
| 947 |
+
*Returns:* An iterator which is the past-the-end value for the bucket.
|
| 948 |
+
|
| 949 |
+
*Complexity:* Constant.
|
| 950 |
+
|
| 951 |
+
``` cpp
|
| 952 |
+
b.cbegin(n)
|
| 953 |
+
```
|
| 954 |
+
|
| 955 |
+
*Result:* `const_local_iterator`
|
| 956 |
+
|
| 957 |
+
*Preconditions:* `n` shall be in the range `[0, b.bucket_count())`.
|
| 958 |
+
|
| 959 |
+
*Returns:* An iterator referring to the first element in the bucket. If
|
| 960 |
+
the bucket is empty, then `b.cbegin(n) == b.cend(n)`.
|
| 961 |
+
|
| 962 |
+
*Complexity:* Constant.
|
| 963 |
+
|
| 964 |
+
``` cpp
|
| 965 |
+
b.cend(n)
|
| 966 |
+
```
|
| 967 |
+
|
| 968 |
+
*Result:* `const_local_iterator`
|
| 969 |
+
|
| 970 |
+
*Preconditions:* `n` is in the range `[0, b.bucket_count())`.
|
| 971 |
+
|
| 972 |
+
*Returns:* An iterator which is the past-the-end value for the bucket.
|
| 973 |
+
|
| 974 |
+
*Complexity:* Constant.
|
| 975 |
+
|
| 976 |
+
``` cpp
|
| 977 |
+
b.load_factor()
|
| 978 |
+
```
|
| 979 |
+
|
| 980 |
+
*Result:* `float`
|
| 981 |
+
|
| 982 |
+
*Returns:* The average number of elements per bucket.
|
| 983 |
+
|
| 984 |
+
*Complexity:* Constant.
|
| 985 |
+
|
| 986 |
+
``` cpp
|
| 987 |
+
b.max_load_factor()
|
| 988 |
+
```
|
| 989 |
+
|
| 990 |
+
*Result:* `float`
|
| 991 |
+
|
| 992 |
+
*Returns:* A positive number that the container attempts to keep the
|
| 993 |
+
load factor less than or equal to. The container automatically increases
|
| 994 |
+
the number of buckets as necessary to keep the load factor below this
|
| 995 |
+
number.
|
| 996 |
+
|
| 997 |
+
*Complexity:* Constant.
|
| 998 |
+
|
| 999 |
+
``` cpp
|
| 1000 |
+
a.max_load_factor(z)
|
| 1001 |
+
```
|
| 1002 |
+
|
| 1003 |
+
*Result:* `void`
|
| 1004 |
+
|
| 1005 |
+
*Preconditions:* `z` is positive. May change the container’s maximum
|
| 1006 |
+
load factor, using `z` as a hint.
|
| 1007 |
+
|
| 1008 |
+
*Complexity:* Constant.
|
| 1009 |
+
|
| 1010 |
+
``` cpp
|
| 1011 |
+
a.rehash(n)
|
| 1012 |
+
```
|
| 1013 |
+
|
| 1014 |
+
*Result:* `void`
|
| 1015 |
+
|
| 1016 |
+
*Ensures:* `a.bucket_count() >= a.size() / a.max_load_factor()` and
|
| 1017 |
+
`a.bucket_count() >= n`.
|
| 1018 |
+
|
| 1019 |
+
*Complexity:* Average case linear in `a.size()`, worst case quadratic.
|
| 1020 |
+
|
| 1021 |
+
``` cpp
|
| 1022 |
+
a.reserve(n)
|
| 1023 |
+
```
|
| 1024 |
+
|
| 1025 |
+
*Effects:* Equivalent to `a.rehash(ceil(n / a.max_load_factor()))`.
|
| 1026 |
|
| 1027 |
Two unordered containers `a` and `b` compare equal if
|
| 1028 |
`a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
|
| 1029 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 1030 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
|
|
|
| 1044 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 1045 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 1046 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 1047 |
`operator!=` on unordered containers is undefined unless the `Pred`
|
| 1048 |
function object has the same behavior for both containers and the
|
| 1049 |
+
equality comparison function for `Key` is a refinement[^1]
|
| 1050 |
+
|
| 1051 |
+
of the partition into equivalent-key groups produced by `Pred`.
|
| 1052 |
|
| 1053 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 1054 |
associative container are of at least the forward iterator category. For
|
| 1055 |
unordered associative containers where the key type and value type are
|
| 1056 |
the same, both `iterator` and `const_iterator` are constant iterators.
|
| 1057 |
|
| 1058 |
+
The `insert`, `insert_range`, and `emplace` members shall not affect the
|
| 1059 |
+
validity of references to container elements, but may invalidate all
|
| 1060 |
+
iterators to the container. The `erase` members shall invalidate only
|
| 1061 |
+
iterators and references to the erased elements, and preserve the
|
| 1062 |
+
relative order of the elements that are not erased.
|
| 1063 |
|
| 1064 |
+
The `insert`, `insert_range`, and `emplace` members shall not affect the
|
| 1065 |
+
validity of iterators if `(N+n) <= z * B`, where `N` is the number of
|
| 1066 |
+
elements in the container prior to the insert operation, `n` is the
|
| 1067 |
+
number of elements inserted, `B` is the container’s bucket count, and
|
| 1068 |
+
`z` is the container’s maximum load factor.
|
| 1069 |
|
| 1070 |
The `extract` members invalidate only iterators to the removed element,
|
| 1071 |
and preserve the relative order of the elements that are not erased;
|
| 1072 |
pointers and references to the removed element remain valid. However,
|
| 1073 |
accessing the element through such pointers and references while the
|
| 1074 |
element is owned by a `node_type` is undefined behavior. References and
|
| 1075 |
pointers to an element obtained while it is owned by a `node_type` are
|
| 1076 |
invalidated if the element is successfully inserted.
|
| 1077 |
|
| 1078 |
+
The member function templates `find`, `count`, `equal_range`,
|
| 1079 |
+
`contains`, `extract`, and `erase` shall not participate in overload
|
| 1080 |
+
resolution unless the *qualified-id*s `Pred::is_transparent` and
|
| 1081 |
+
`Hash::is_transparent` are both valid and denote types [[temp.deduct]].
|
| 1082 |
+
Additionally, the member function templates `extract` and `erase` shall
|
| 1083 |
+
not participate in overload resolution if
|
| 1084 |
+
`is_convertible_v<K&&, iterator> || is_convertible_v<K&&, const_iterator>`
|
| 1085 |
+
is `true`, where `K` is the type substituted as the first template
|
| 1086 |
+
argument.
|
| 1087 |
|
| 1088 |
A deduction guide for an unordered associative container shall not
|
| 1089 |
participate in overload resolution if any of the following are true:
|
| 1090 |
|
| 1091 |
- It has an `InputIterator` template parameter and a type that does not
|