+
+ if (node->depth < 0) {
+ printf("%s:%d Tree statistics inconsistency detected! "
+ "Negative depth: %ld\n",
+ __func__, __LINE__, node->depth);
+ }
+
+ if (node->children != children) {
+ printf("%s:%d Tree statistics inconsistency detected! "
+ "child count mismatch. Expected %ld, got %ld\n",
+ __func__, __LINE__, children, node->children);
+ trap();
+ }
+
+ for (i = 0; i < 4 && node->children; i++) {
+ if (!node->child[i])
+ continue;
+
+ if (node->depth == node->child[i]->depth + 1)
+ break;
+
+ if (node->child[i]->depth > node->depth) {
+ printf("%s:%d Tree statistics inconsistency detected! "
+ "child depth mismatch %ld > %ld\n",
+ __func__, __LINE__, node->child[i]->depth,
+ node->depth);
+ }
+ }
+
+ if (i == 4) {
+ printf("%s:%d Tree statistics inconsistency detected! "
+ "child depth mismatch.",
+ __func__, __LINE__);
+ trap();
+ }