-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiset.cpp
71 lines (58 loc) · 1.37 KB
/
multiset.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
#include <iostream>
#include "multiset.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->key() << '}';
}
else
{
std::cout << "{null}";
}
std::cout << ' ';
}
std::cout << std::endl;
}
while (q.size() && std::any_of(q.cbegin(), q.cend(),
[](auto&& p) noexcept { return std::get<0>(p); }));
}
//////////////////////////////////////////////////////////////////////////////
int main()
{
xsg::multiset<int> st;
st.emplace(-1);
st.insert(0);
st.insert({1, 1});
st.emplace(2);
st.emplace(3);
st.emplace(4);
dump(st.root());
std::cout << "count: " << st.count(1) << std::endl;
std::cout << "height: " << xsg::detail::height(st.root(), {}) << std::endl;
std::cout << "size: " << st.size() << std::endl;
std::for_each(
st.cbegin(),
st.cend(),
[](auto&& k) noexcept
{
std::cout << '(' << k << ')' << std::endl;
}
);
return 0;
}