private void DeleteRange(uint start, uint length, Node parentNode, Node node, int nodeIndex, int nodeDepth)
{
uint nodeLength = (NodeShift * nodeDepth) >= 32 ? uint.MaxValue : 1u << NodeShift * nodeDepth;
uint nodeStart = nodeLength * (uint)nodeIndex;
if (parentNode != null && (nodeStart >= start + length || nodeStart + nodeLength <= start))
{
// Delete the entire node.
parentNode.array[nodeIndex] = null;
return;
}
if (nodeDepth == 1)
{
// The node is a leaf node.
for (int i = 0; i < NodeSize; i++)
{
uint index = (uint)(nodeStart + i);
if (index >= start && index < start + length)
node.array[i] = null;
}
}
else
{
// The node is a branch node.
for (int i = 0; i < NodeSize; i++)
{
var element = node.array[i] as Node;
if (element != null)
{
DeleteRange(start, length, node, element, i, nodeDepth - 1);
}
}
}
}