private void addChild(Node<K, V> node, Node<K, V> child) { if (child.getType() == NodeType.LEAF) { LeafNode leaf = (LeafNode) child; for (int i = 0; i < leaf.size(); i++) { node.put((K) leaf.getKeys().get(i), (V) leaf.getValues().get(i)); } } else if (child.getType() == NodeType.GUIDE) { GuideNode guide = (GuideNode) child; for (int i = 0; i < guide.size(); i++) { addChild(node, (Node<K, V>) guide.getKids().get(i)); } } }
protected void split() { int halfGuides = guides.size() / 2; int halfKids = halfGuides + 1; GuideNode<K, V> left = new GuideNode<K, V>(comparator, guides.subList(0, halfGuides), kids.subList(0, halfKids)); GuideNode<K, V> right = new GuideNode<K, V>( comparator, guides.subList(halfGuides + 1, guides.size()), kids.subList(halfKids, kids.size())); left.setLeft(getLeft()); left.setRight(right); getLeft().setRight(left); left.setParent(getParent()); for (Node<K, V> kid : left.kids) { kid.setParent(left); } right.setLeft(left); right.setRight(getRight()); getRight().setLeft(right); right.setParent(getParent()); for (Node<K, V> kid : right.kids) { kid.setParent(right); } parent.insertKid(this, guides.get(halfGuides), left, right); }