From 3e90bb45a6ce1d74354e32609b4cdecaa6717de0 Mon Sep 17 00:00:00 2001 From: juziia <50221211+juziia@users.noreply.github.com> Date: Sat, 13 Aug 2022 20:33:33 +0800 Subject: [PATCH] This condition will not hold method canRedistribute is to determine whether a node will still be greater than or equal to M / 2-1 after removing a Key. However, the condition for entering the current method is that the number of keys of the node must be less than or equal to M / 2-1,So I don't think this greater than 0 condition is going to hold --- src/main/java/ds/bplus/bptree/BPlusTree.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/main/java/ds/bplus/bptree/BPlusTree.java b/src/main/java/ds/bplus/bptree/BPlusTree.java index 1d36cd2..556f942 100644 --- a/src/main/java/ds/bplus/bptree/BPlusTree.java +++ b/src/main/java/ds/bplus/bptree/BPlusTree.java @@ -1563,7 +1563,6 @@ private TreeNode handleLeafNodeRedistributionOrMerging(TreeNode mnode, int nnum = canRedistribute(nptr); int pnum = canRedistribute(pptr); - int snum = canRedistribute(splitNode); boolean isLeftOfNext = (parentPointerIndex > parentKeyIndex); boolean splitNodeIsLeftChild = parentKeyIndex == parentPointerIndex; @@ -1587,22 +1586,6 @@ else if(pnum > 0 && ppar) { } else { redistributeNodes(splitNode, pptr, true, parent, parentKeyIndex); } - } else if(snum > 0) { - if(nptr != null) { - //System.out.println("\t -- Redistributing next node with elements from split"); - if(splitNodeIsLeftChild) { - redistributeNodes(nptr, splitNode, true, parent, parentKeyIndex); - } else { - redistributeNodes(nptr, splitNode, true, parent, parentKeyIndex+1); - } - } else { - //System.out.println("\t -- Redistributing prev with elements from split"); - if(splitNodeIsLeftChild) { - redistributeNodes(pptr, splitNode, false, parent, parentKeyIndex-1); - } else { - redistributeNodes(pptr, splitNode, false, parent, parentKeyIndex); - } - } } // we can't redistribute, try merging with next else if(npar) {