forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSerialUniqueArray.h
More file actions
66 lines (55 loc) · 1.37 KB
/
USerialUniqueArray.h
File metadata and controls
66 lines (55 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: USerialUniqueArray.h
@Time: 2023/2/27 23:35
@Desc:
***************************/
#ifndef CGRAPH_USERIALUNIQUEARRAY_H
#define CGRAPH_USERIALUNIQUEARRAY_H
#include <vector>
#include <set>
#include "../UtilsObject.h"
CGRAPH_NAMESPACE_BEGIN
template<class T>
class USerialUniqueArray : public UtilsObject {
public:
/**
* 不重复的插入顺序容器中
* @param val
* @return
*/
CVoid uniqueAdd(const T& val) {
// 如果没有,就插入array中
if (inner_set_.find(val) == inner_set_.end()) {
inner_set_.insert(val);
inner_array_.push_back(val);
}
}
/**
* 获取不重复的有序array信息
* @param arr
* @return
*/
CVoid getUniqueArray(std::vector<T>& arr) {
for (const auto& iter : inner_array_) {
arr.push_back(iter);
}
}
/**
* 清空所有内部信息
* @return
*/
CVoid clear() {
inner_set_.clear();
inner_array_.clear();
}
~USerialUniqueArray() override {
clear();
}
private:
std::set<T> inner_set_; // 内部set,留比对使用
std::vector<T> inner_array_; // 内部array,最终提供的排序不重复内容
};
CGRAPH_NAMESPACE_END
#endif //CGRAPH_USERIALUNIQUEARRAY_H