![]() |
Home | Libraries | People | FAQ | More |
Table 24.4. Interface
differences.
表 24.4. 接口的差異。
|
Associative Containers 關聯式容器 |
Unordered Associative Containers 無序關聯式容器 |
|---|---|
|
Parameterized by an ordering relation |
Parameterized by a function object
|
|
Keys can be compared using 鍵值可以使用 |
Keys can be hashed using 鍵值可以用 |
|
Constructors have optional extra parameters for the comparison object. 構造函數有可選的額外參數用於比較用的函數對象。 |
Constructors have optional extra parameters for the initial minimum number of buckets, a hash function and an equality object. 構造函數有可選的額外參數,用於初始化最小的桶數量、散列函數和等同性函數對象。 |
|
Keys
|
Keys 鍵值 |
|
Member function 成員函數 |
No equivalent. Since the elements aren't ordered |
|
如果 k 不在容器中, |
如果 k 不在容器中, |
|
|
|
|
Iterators, pointers and references to the container's
elements are never invalidated. |
Iterators can be invalidated by calls to insert or rehash. Pointers and references to the container's elements are never invalidated. 調 用 insert 或 rehash 可能引起迭代器失效。而指向容器元素的指針和引用則不會失效。 |
|
Iterators iterate through the container in the order defined by the comparison object. 迭代器按照由比較函數對像所定義的順序遍歷容器。 |
Iterators iterate through the container in an arbitrary order, that can change as elements are inserted. Although, equivalent elements are always adjacent. 迭代器按任意順序遍歷容器,由元素被插入時還可能改變。不過,相等的元素總是保持連續的。 |
|
No equivalent 無對應物 |
Local iterators can be used to iterate through individual buckets. (I don't think that the order of local iterators and iterators are required to have any correspondence.) 局部迭代器可以用於遍歷單個桶。(我不認為局部迭代器和迭代器的順序有任何對應物) |
|
Can be compared using the 可以用 |
No comparison operators are defined in the standard,
although implementations
might extend the containers to support 在標準中沒有定義比較操作符,不過 實
現對容器進行擴展以支持 |
|
|
When inserting with a hint, implementations are permitted to ignore the hint. 在帶提示的插入操作時,實現被允許可以忽略提示。 |
|
|
The containers' hash or predicate function can throw
exceptions from 容器的散列函數和謂詞函數可以從 |
Table 24.5. Complexity
Guarantees
表 24.5. 複雜度保證
|
Operation 操作 |
Associative Containers 關聯式容器 |
Unordered Associative Containers 無序關聯式容器 |
|---|---|---|
|
Construction of empty container 空容器的構造 |
constant 常數 |
O(n) where n is the minimum number of buckets. O(n) 其中 n 為桶的最小數量。 |
|
Construction of container from a range of N elements 從帶有 N 個元素的區間構造容器 |
O(N
log N),
O(N)
if the range is sorted with O(N
log N),
O(N)
如果區間已按 |
Average case O(N), worst case O(N2) 平均情況 O(N), 最壞情況 O(N2) |
|
Insert a single element 插入單個元素 |
logarithmic 對數 |
Average case constant, worst case linear 平均情況為常數時間,最壞情況為線性時間 |
|
Insert a single element with a hint 帶提示插入單個元素 |
Amortized constant if t elements inserted right after hint, logarithmic otherwise 如果插入的元素恰好在提示位置之後,則為分期常數時間,否則為對數時間 |
Average case constant, worst case linear (ie. the same as a normal insert). 平均情況為常數時間,最壞情況為線性時間(即與普通插入一樣) |
|
Inserting a range of N elements 插入 N 個元素的區間 |
N
log( |
Average case O(N),
worst case O(N
* 平均情況為 O(N),
最壞情況為 O(N
* |
|
Erase by key,
|
O(log( |
Average case: O( 平均情況:O( |
|
Erase a single element by iterator 通過迭代器刪除單個元素 |
Amortized constant 分期常數時間 |
Average case: O(1), Worst case: O( 平均情況:O(1),最壞情況:O( |
|
Erase a range of N elements 刪除 N 個元素的區間 |
O(log( |
Average case: O(N),
Worst case: O( 平均情況:O(N),
最壞情況: O( |
|
Clearing the container 清空容器 |
O( |
O( |
|
Find 查找 |
logarithmic 對數時間 |
Average case: O(1), Worst case: O( 平均情況:O(1),最壞情況: O( |
|
Count 計數 |
O(log( |
Average case: O(1), Worst case: O( 平均情況:O(1),最壞情況: O( |
|
|
logarithmic 對數時間 |
Average case: O( 平均情況:O( |
|
|
logarithmic 對數時間 |
n/a 無 |