Пример #1
0
 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));
     }
   }
 }
Пример #2
0
 protected void merge() {
   if (parent != null) {
     parent.deleteKid(this);
     Node<K, V> prev = null;
     Node<K, V> temp = parent;
     while (temp != null && temp.getType() != NodeType.ROOT) {
       prev = temp;
       temp = temp.getParent();
     }
     if (prev != null) {
       for (int i = 0; i < size(); i++) {
         Node<K, V> child = kids.get(i);
         addChild(prev, child);
       }
     }
   }
 }