MCPcopy Create free account
hub / github.com/BowenFu/matchit.cpp / balance

Method balance

sample/Red-black-Tree-Rebalancing.cpp:33–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31#if 0
32template <typename T>
33void Node<T>::balance()
34{
35 using namespace matchit;
36
37 constexpr auto dsN = [](auto &&color, auto &&lhs, auto &&value, auto &&rhs)
38 {
39 return and_(app(&Node<T>::color, color), app(&Node<T>::lhs, lhs),
40 app(&Node<T>::value, value), app(&Node<T>::rhs, rhs));
41 };
42
43 Id<std::shared_ptr<Node<T>>> a, b, c, d;
44 Id<T> x, y, z;
45 Id<Node> self;
46 *this = match(*this)(
47 pattern | dsN(Black, some(dsN(Red, some(dsN(Red, a, x, b)), y, c)), z,
48 d) // left-left case
49 =
50 [&]
51 {
52 return Node{Red, std::make_shared<Node>(Black, *a, *x, *b), *y,
53 std::make_shared<Node>(Black, *c, *z, *d)};
54 },
55 pattern | dsN(Black, some(dsN(Red, a, x, some(dsN(Red, b, y, c)))), z,
56 d) // left-right case
57 =
58 [&]
59 {
60 return Node{Red, std::make_shared<Node>(Black, *a, *x, *b), *y,
61 std::make_shared<Node>(Black, *c, *z, *d)};
62 },
63 pattern |
64 dsN(Black, a, x,
65 some(dsN(Red, some(dsN(Red, b, y, c)), z, d))) // right-left case
66 =
67 [&]
68 {
69 return Node{Red, std::make_shared<Node>(Black, *a, *x, *b), *y,
70 std::make_shared<Node>(Black, *c, *z, *d)};
71 },
72 pattern |
73 dsN(Black, a, x,
74 some(dsN(Red, b, y, some(dsN(Red, c, z, d))))) // right-right case
75 =
76 [&]
77 {
78 return Node{Red, std::make_shared<Node>(Black, *a, *x, *b), *y,
79 std::make_shared<Node>(Black, *c, *z, *d)};
80 },
81 pattern | self = expr(self) // do nothing
82 );
83}
84
85#else
86

Callers 1

mainFunction · 0.80

Calls 4

appFunction · 0.85
and_Function · 0.50
matchFunction · 0.50
exprFunction · 0.50

Tested by

no test coverage detected