public static void ValidateNode(IBTreeNode node) { if (!OdbConfiguration.IsBTreeValidationEnabled()) return; var nbKeys = node.GetNbKeys(); if (node.HasParent() && nbKeys < node.GetDegree() - 1) { var degree = (node.GetDegree() - 1).ToString(); throw new BTreeNodeValidationException("Node with less than " + degree + " keys"); } var maxNbKeys = node.GetDegree() * 2 - 1; var nbChildren = node.GetNbChildren(); var maxNbChildren = node.GetDegree() * 2; if (nbChildren != 0 && nbKeys == 0) throw new BTreeNodeValidationException("Node with no key but with children : " + node); for (var i = 0; i < nbKeys; i++) { if (node.GetKeyAndValueAt(i) == null) { var keyIndex = i.ToString(); throw new BTreeNodeValidationException("Null key at " + keyIndex + " on node " + node); } CheckValuesOfChild(node.GetKeyAndValueAt(i), node.GetChildAt(i, false)); } for (var i = nbKeys; i < maxNbKeys; i++) { if (node.GetKeyAndValueAt(i) != null) throw new BTreeNodeValidationException(string.Concat("Not Null key at ", i.ToString(), " on node " + node)); } IBTreeNode previousNode = null; for (var i = 0; i < nbChildren; i++) { if (node.GetChildAt(i, false) == null) throw new BTreeNodeValidationException(string.Concat("Null child at index ", i.ToString(), " on node " + node)); if (previousNode != null && previousNode == node.GetChildAt(i, false)) throw new BTreeNodeValidationException(string.Concat("Two equals children at index ", i.ToString(), " : " + previousNode)); previousNode = node.GetChildAt(i, false); } for (var i = nbChildren; i < maxNbChildren; i++) { if (node.GetChildAt(i, false) != null) throw new BTreeNodeValidationException(string.Concat("Not Null child at ", i.ToString(), " on node " + node)); } }
public static void ValidateNode(IBTreeNode node) { if (!OdbConfiguration.IsBTreeValidationEnabled()) { return; } int nbKeys = node.GetNbKeys(); if (node.HasParent() && nbKeys < node.GetDegree() - 1) { string degree = (node.GetDegree() - 1).ToString(); throw new BTreeNodeValidationException("Node with less than " + degree + " keys"); } int maxNbKeys = node.GetDegree() * 2 - 1; int nbChildren = node.GetNbChildren(); int maxNbChildren = node.GetDegree() * 2; if (nbChildren != 0 && nbKeys == 0) { throw new BTreeNodeValidationException("Node with no key but with children : " + node); } for (int i = 0; i < nbKeys; i++) { if (node.GetKeyAndValueAt(i) == null) { string keyIndex = i.ToString(); throw new BTreeNodeValidationException("Null key at " + keyIndex + " on node " + node); } CheckValuesOfChild(node.GetKeyAndValueAt(i), node.GetChildAt(i, false)); } for (int i = nbKeys; i < maxNbKeys; i++) { if (node.GetKeyAndValueAt(i) != null) { throw new BTreeNodeValidationException(string.Concat("Not Null key at ", i.ToString(), " on node " + node)); } } IBTreeNode previousNode = null; for (int i = 0; i < nbChildren; i++) { if (node.GetChildAt(i, false) == null) { throw new BTreeNodeValidationException(string.Concat("Null child at index ", i.ToString(), " on node " + node)); } if (previousNode != null && previousNode == node.GetChildAt(i, false)) { throw new BTreeNodeValidationException(string.Concat("Two equals children at index ", i.ToString(), " : " + previousNode)); } previousNode = node.GetChildAt(i, false); } for (int i = nbChildren; i < maxNbChildren; i++) { if (node.GetChildAt(i, false) != null) { throw new BTreeNodeValidationException(string.Concat("Not Null child at ", i.ToString(), " on node " + node)); } } }