Kyopro Library
 
読み取り中…
検索中…
一致する文字列を見つけられません
set.hpp
[詳解]
1#include"../../kyopro_library/template.hpp"
2
3/// @brief std::set ラッパー
4template<typename T>
5struct Set:set<T> {
6 using set<T>::set;
8 Set()=default;
9
10 /// @brief コンストラクタ
11 /// @param not_found 指定の値が見つからなかったときに返す値
12 Set(T not_found=-1) { this->not_found=not_found; }
13
14 /// @brief 最小値を返す
15 T min() {
16 if(this->empty()) return not_found;
17 return*this->begin();
18 }
19
20 /// @brief 最大値を返す
21 T max() {
22 if(this->empty())return not_found;
23 return*this->rbegin();
24 }
25
26 /// @brief 最小値を返し、削除する
27 T pop_min() {
28 if(this->empty()) return not_found;
29 T ret=min();
30 this->erase(ret);
31 return ret;
32 }
33
34 /// @brief 最大値を返し、削除する
35 T pop_max() {
36 if(this->empty()) return not_found;
37 T ret=max();
38 this->erase(ret);
39 return ret;
40 }
41
42 /// @brief x が含まれているか否かを返す
43 bool contains(T x) {
44 return this->find(x)!=this->end();
45 }
46
47 /// @brief x を削除する
48 /// @brief x が含まれていたか否かを返す
49 bool discard(T x) {
50 auto itr=this->find(x);
51 if(itr==this->end()) return false;
52 this->erase(itr);
53 return true;
54 }
55
56 /// @brief x より大きい最小の値を返す
57 T gt(T x) {
58 auto itr=this->upper_bound(x);
59 if(itr==this->end()) return not_found;
60 return*itr;
61 }
62
63 /// @brief x 以上の最小の値を返す
64 T ge(T x) {
65 auto itr=this->lower_bound(x);
66 if(itr==this->end()) return not_found;
67 return*itr;
68 }
69
70 /// @brief x 以下の最大の値を返す
71 T le(T x) {
72 auto itr=this->upper_bound(x);
73 if(itr==this->begin()) return not_found;
74 return*prev(itr);
75 }
76
77 /// @brief x 未満の最大値の値を返す
78 T lt(T x) {
79 auto itr=this->lower_bound(x);
80 if(itr==this->begin()) return not_found;
81 return*prev(itr);
82 }
83};
std::set ラッパー
Definition set.hpp:5
T lt(T x)
x 未満の最大値の値を返す
Definition set.hpp:78
Set(T not_found=-1)
コンストラクタ
Definition set.hpp:12
T pop_max()
最大値を返し、削除する
Definition set.hpp:35
T gt(T x)
x より大きい最小の値を返す
Definition set.hpp:57
T pop_min()
最小値を返し、削除する
Definition set.hpp:27
T ge(T x)
x 以上の最小の値を返す
Definition set.hpp:64
T min()
最小値を返す
Definition set.hpp:15
T not_found
Definition set.hpp:7
T le(T x)
x 以下の最大の値を返す
Definition set.hpp:71
T max()
最大値を返す
Definition set.hpp:21
bool contains(T x)
x が含まれているか否かを返す
Definition set.hpp:43
bool discard(T x)
x を削除する
Definition set.hpp:49
Set()=default