Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions reference/unordered_map/unordered_map/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ void clear() noexcept;
## 計算量
本関数呼び出し前のコンテナの要素数([`size`](size.md)`()`)に比例

### 計算量に関する備考
- 多くの実装(GCC libstdc++, LLVM libc++ など)は
1. 全ての要素を走査して各要素を破棄
2. 全てのバケットを走査して各バケットを初期化
Comment thread
akinomyoga marked this conversation as resolved.
Outdated

という手順を取るため、実行時間は概ね [`size`](size.md)`()` + [`bucket_count`](bucket_count.md)`()` に比例する傾向がある。
Comment thread
math-hiyoko marked this conversation as resolved.
Outdated
規格がコンテナに対して定義する計算量は「コンテナに格納している要素に対する操作の数の計算量」であるためバケットの走査を考慮せず「コンテナの全要素を削除する」として、全要素数Nに対してO(N)に規定されるが、実行時間に影響する時間計算量としてはバケット数Cに対して線形となる。
Comment thread
math-hiyoko marked this conversation as resolved.
Outdated


## 備考
Comment thread
akinomyoga marked this conversation as resolved.
Outdated
- `clear()` は バケット数([`bucket_count`](bucket_count.md)`()`)を縮小することを規格上は要求していない。
Comment thread
math-hiyoko marked this conversation as resolved.
Outdated
実装によっては `clear()` 後もバケット配列が維持され、動的メモリが残る場合がある。
- メモリを確実に解放したいときには以下のように操作を行う
```CPP
Comment thread
math-hiyoko marked this conversation as resolved.
Outdated
std::unordered_map<std::string, int> tmp;
s.swap(tmp);
```


## 例
```cpp example
Expand Down
18 changes: 18 additions & 0 deletions reference/unordered_map/unordered_multimap/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ void clear() noexcept;
## 計算量
本関数呼び出し前のコンテナの要素数([`size`](size.md)`()`)に比例

### 計算量に関する備考
- 多くの実装(GCC libstdc++, LLVM libc++ など)は
1. 全ての要素を走査して各要素を破棄
2. 全てのバケットを走査して各バケットを初期化

という手順を取るため、実行時間は概ね [`size`](size.md)`()` + [`bucket_count`](bucket_count.md)`()` に比例する傾向がある。
規格がコンテナに対して定義する計算量は「コンテナに格納している要素に対する操作の数の計算量」であるためバケットの走査を考慮せず「コンテナの全要素を削除する」として、全要素数Nに対してO(N)に規定されるが、実行時間に影響する時間計算量としてはバケット数Cに対して線形となる。


## 備考
- `clear()` は バケット数([`bucket_count`](bucket_count.md)`()`)を縮小することを規格上は要求していない。
実装によっては `clear()` 後もバケット配列が維持され、動的メモリが残る場合がある。
- メモリを確実に解放したいときには以下のように操作を行う
```CPP
std::unordered_multimap<std::string, int> tmp;
s.swap(tmp);
```


## 例
```cpp example
Expand Down
18 changes: 18 additions & 0 deletions reference/unordered_set/unordered_multiset/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ void clear() noexcept;
## 計算量
本関数呼び出し前のコンテナの要素数([`size`](size.md)`()`)に比例

### 計算量に関する備考
- 多くの実装(GCC libstdc++, LLVM libc++ など)は
1. 全ての要素を走査して各要素を破棄
2. 全てのバケットを走査して各バケットを初期化

という手順を取るため、実行時間は概ね [`size`](size.md)`()` + [`bucket_count`](bucket_count.md)`()` に比例する傾向がある。
規格がコンテナに対して定義する計算量は「コンテナに格納している要素に対する操作の数の計算量」であるためバケットの走査を考慮せず「コンテナの全要素を削除する」として、全要素数Nに対してO(N)に規定されるが、実行時間に影響する時間計算量としてはバケット数Cに対して線形となる。


## 備考
- `clear()` は バケット数([`bucket_count`](bucket_count.md)`()`)を縮小することを規格上は要求していない。
実装によっては `clear()` 後もバケット配列が維持され、動的メモリが残る場合がある。
- メモリを確実に解放したいときには以下のように操作を行う
```CPP
std::unordered_multiset<int> tmp;
s.swap(tmp);
```


## 例
```cpp example
Expand Down
18 changes: 18 additions & 0 deletions reference/unordered_set/unordered_set/clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ void clear() noexcept;
## 計算量
本関数呼び出し前のコンテナの要素数([`size`](size.md)`()`)に比例

### 計算量に関する備考
- 多くの実装(GCC libstdc++, LLVM libc++ など)は
1. 全ての要素を走査して各要素を破棄
2. 全てのバケットを走査して各バケットを初期化

という手順を取るため、実行時間は概ね [`size`](size.md)`()` + [`bucket_count`](bucket_count.md)`()` に比例する傾向がある。
規格がコンテナに対して定義する計算量は「コンテナに格納している要素に対する操作の数の計算量」であるためバケットの走査を考慮せず「コンテナの全要素を削除する」として、全要素数Nに対してO(N)に規定されるが、実行時間に影響する時間計算量としてはバケット数Cに対して線形となる。


## 備考
- `clear()` は バケット数([`bucket_count`](bucket_count.md)`()`)を縮小することを規格上は要求していない。
実装によっては `clear()` 後もバケット配列が維持され、動的メモリが残る場合がある。
- メモリを確実に解放したいときには以下のように操作を行う
```CPP
std::unordered_set<int> tmp;
s.swap(tmp);
```


## 例
```cpp example
Expand Down