MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / checkRbTree

Function checkRbTree

check/TestHighsRbTree.cpp:57–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55};
56
57static void checkRbTree(MyRbTree& tree, HighsInt* expectedKeys,
58 HighsInt numExpectedKeys) {
59 std::vector<HighsInt> keys;
60 keys.reserve(numExpectedKeys);
61 if (tree.root != -1) REQUIRE(tree.nodes[tree.root].links.isBlack());
62
63 HighsInt x = tree.first();
64 while (x != -1) {
65 keys.push_back(tree.nodes[x].key);
66 if (tree.nodes[x].links.isRed()) {
67 HighsInt lChild = tree.nodes[x].links.child[0];
68 HighsInt rChild = tree.nodes[x].links.child[1];
69 if (lChild != -1) REQUIRE(tree.nodes[lChild].links.isBlack());
70 if (rChild != -1) REQUIRE(tree.nodes[rChild].links.isBlack());
71 }
72 x = tree.successor(x);
73 REQUIRE((HighsInt)keys.size() <= numExpectedKeys);
74 }
75
76 REQUIRE((HighsInt)keys.size() == numExpectedKeys);
77 std::sort(expectedKeys, expectedKeys + numExpectedKeys);
78 bool isOk = std::equal(keys.begin(), keys.end(), expectedKeys);
79 REQUIRE(isOk);
80}
81
82TEST_CASE("HighsRbTree", "[util]") {
83 std::vector<HighsInt> keys;

Callers 1

Calls 9

reserveMethod · 0.80
push_backMethod · 0.80
successorMethod · 0.80
isBlackMethod · 0.45
firstMethod · 0.45
isRedMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected