-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintervalmap.cpp
More file actions
81 lines (65 loc) · 1.64 KB
/
intervalmap.cpp
File metadata and controls
81 lines (65 loc) · 1.64 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include "intervalmap.hpp"
//////////////////////////////////////////////////////////////////////////////
void dump(auto n)
{
std::list<decltype(n)> q{n};
do
{
for (auto m(q.size()); m--;)
{
auto const n(q.front());
q.erase(q.begin());
if (n)
{
q.insert(q.end(), {n->l_, n->r_});
std::cout << '{' << n->key() << ',' << n->m_ << '}';
}
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 p; }));
}
//////////////////////////////////////////////////////////////////////////////
int main()
{
sg::intervalmap<std::pair<int, int>, int> st;
st.emplace({-1, 0}, -1);
st.insert({{0, 1}, 0});
st.insert({{{1, 2}, 1}, {std::pair(1, 4), 1}});
st.emplace({2, 3}, 2);
st.emplace({3, 5}, 3);
//st.root().reset(st.root().release()->rebuild());
dump(st.root());
std::cout << "height: " << sg::detail::height(st.root()) << std::endl;
std::cout << "size: " << st.size() << std::endl;
std::cout << "any: " << st.any(std::pair(0, 1)) << std::endl;
std::for_each(
st.crbegin(),
st.crend(),
[](auto&& p) noexcept
{
std::cout << '(' << p.first.first << ',' << p.first.second << ')' << std::endl;
}
);
st.all(
{-1, 0},
[](auto&& p)
{
std::cout << '(' << p.first.first << ',' << p.first.second << ") " <<
p.second << std::endl;
}
);
srandom(time(nullptr));
while (st.size())
{
st.erase(std::next(st.begin(), random() % st.size()));
}
return 0;
}