Check parent pointers

This commit is contained in:
2024-01-18 16:23:25 -08:00
parent 7849623597
commit 0bcad7686f

View File

@@ -349,6 +349,19 @@ void rotate(Node **node, bool dir) {
updateMaxVersion(l);
}
void checkParentPointers(Node *node, bool &success) {
for (int i = 0; i < 2; ++i) {
if (node->child[i] != nullptr) {
if (node->child[i]->parent != node) {
fprintf(stderr, "%.*s child %d has parent pointer %p. Expected %p\n",
node->len, (const char *)(node + 1), i,
(void *)node->child[i]->parent, (void *)node);
}
checkParentPointers(node->child[i], success);
}
}
}
int64_t checkMaxVersion(Node *node, bool &success) {
int64_t expected = std::max(node->pointVersion, node->rangeVersion);
for (int i = 0; i < 2; ++i) {
@@ -385,6 +398,7 @@ bool checkInvariants(Node *node) {
assert(std::is_sorted(keys.begin(), keys.end()));
checkMaxVersion(node, success);
checkParentPointers(node, success);
// TODO Compare logical contents of map with
// reference implementation