-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset.cpp
81 lines (65 loc) · 1.5 KB
/
set.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include "xl/list.hpp"
#include "set.hpp"
//////////////////////////////////////////////////////////////////////////////
void dump(auto n, decltype(n) p)
{
xl::list<std::pair<decltype(n), decltype(n)>> q{{n, p}};
do
{
for (auto m(q.size()); m--;)
{
auto const [n, p](q.front());
q.erase(q.begin());
if (n)
{
q.insert(
q.end(),
{
{xsg::detail::left_node(n, p), n},
{xsg::detail::right_node(n, p), n}
}
);
std::cout << '{' << n->kv_ << '}';
}
else
{
std::cout << "{null}";
}
std::cout << ' ';
}
std::cout << std::endl;
}
while (q.size() && std::any_of(q.cbegin(), q.cend(),
[](auto const p) noexcept { return std::get<0>(p); }));
}
//////////////////////////////////////////////////////////////////////////////
int main()
{
xsg::set<int> s{4, 3, 2, 1};
dump(s.root(), {});
std::cout << s.contains(3u) << std::endl;
std::cout << s.contains(100ull) << std::endl;
std::for_each(
s.cbegin(),
s.cend(),
[](auto&& p) noexcept
{
std::cout << p << std::endl;
}
);
std::cout << "eq: " << (s == xsg::set<int>{1, 2, 3, 4}) << std::endl;
//s.erase(std::next(s.cbegin()));
s.erase(std::next(s.cbegin()));
s.erase(std::prev(s.cend()));
dump(s.root(), {});
std::for_each(
s.cbegin(),
s.cend(),
[](auto&& p) noexcept
{
std::cout << p << std::endl;
}
);
return 0;
}