-
Notifications
You must be signed in to change notification settings - Fork 1
/
intervalmap.cpp
87 lines (71 loc) · 1.88 KB
/
intervalmap.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
82
83
84
85
86
87
#include <iostream>
#include "intervalmap.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() << ',' << n->m_ << '}';
}
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::intervalmap<std::pair<int, int>, int> st;
st.emplace(std::pair(-1, 0), -1);
st.insert({std::pair(0, 1), 0});
st.insert({{std::pair(1, 2), 1}, {std::pair(1, 4), 1}});
st.emplace(std::pair(2, 3), 2);
st.emplace(std::pair(3, 5), 3);
//st.root().reset(st.root().release()->rebuild());
dump(st.root(), {});
std::cout << "height: " << xsg::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(
std::pair(2, 4),
[](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;
}