MCPcopy Create free account
hub / github.com/apache/poi / doRedBlackInsert

Method doRedBlackInsert

src/java/org/apache/poi/util/BinaryTree.java:812–880  ·  view source on GitHub ↗

complicated red-black insert stuff. Based on Sun's TreeMap implementation, though it's barely recognizeable any more @param inserted_node the node to be inserted @param index _KEY or _VALUE

(Node inserted_node, int index)

Source from the content-addressed store, hash-verified

810 * @param index _KEY or _VALUE
811 */
812 private void doRedBlackInsert(Node inserted_node, int index)
813 {
814 Node current_node = inserted_node;
815
816 makeRed(current_node, index);
817 while ((current_node != null) && (current_node != _root[ index ])
818 && (isRed(current_node.getParent(index), index)))
819 {
820 if (isLeftChild(getParent(current_node, index), index))
821 {
822 Node y = getRightChild(getGrandParent(current_node, index),
823 index);
824
825 if (isRed(y, index))
826 {
827 makeBlack(getParent(current_node, index), index);
828 makeBlack(y, index);
829 makeRed(getGrandParent(current_node, index), index);
830 current_node = getGrandParent(current_node, index);
831 }
832 else
833 {
834 if (isRightChild(current_node, index))
835 {
836 current_node = getParent(current_node, index);
837 rotateLeft(current_node, index);
838 }
839 makeBlack(getParent(current_node, index), index);
840 makeRed(getGrandParent(current_node, index), index);
841 if (getGrandParent(current_node, index) != null)
842 {
843 rotateRight(getGrandParent(current_node, index),
844 index);
845 }
846 }
847 }
848 else
849 {
850
851 // just like clause above, except swap left for right
852 Node y = getLeftChild(getGrandParent(current_node, index),
853 index);
854
855 if (isRed(y, index))
856 {
857 makeBlack(getParent(current_node, index), index);
858 makeBlack(y, index);
859 makeRed(getGrandParent(current_node, index), index);
860 current_node = getGrandParent(current_node, index);
861 }
862 else
863 {
864 if (isLeftChild(current_node, index))
865 {
866 current_node = getParent(current_node, index);
867 rotateRight(current_node, index);
868 }
869 makeBlack(getParent(current_node, index), index);

Callers 2

insertValueMethod · 0.95
putMethod · 0.95

Calls 12

makeRedMethod · 0.95
isRedMethod · 0.95
getParentMethod · 0.95
isLeftChildMethod · 0.95
getParentMethod · 0.95
getRightChildMethod · 0.95
getGrandParentMethod · 0.95
makeBlackMethod · 0.95
isRightChildMethod · 0.95
rotateLeftMethod · 0.95
rotateRightMethod · 0.95
getLeftChildMethod · 0.95

Tested by

no test coverage detected