Exemplo n.º 1
0
 private static void reclaim(
     @NotNull final PatriciaReclaimSourceTraverser source,
     @NotNull final PatriciaReclaimActualTraverser actual) {
   final NodeBase actualNode = actual.currentNode;
   final NodeBase sourceNode = source.currentNode;
   if (actualNode.getAddress() == sourceNode.getAddress()) {
     actual.currentNode = actualNode.getMutableCopy(actual.mainTree);
     actual.getItr();
     actual.wasReclaim = true;
     reclaimActualChildren(source, actual);
   } else {
     @NotNull ByteIterator srcItr = sourceNode.keySequence.iterator();
     @NotNull ByteIterator actItr = actualNode.keySequence.iterator();
     int srcPushes = 0;
     int actPushes = 0;
     while (true) {
       if (srcItr.hasNext()) {
         if (actItr.hasNext()) {
           if (srcItr.next() != actItr.next()) { // key is not matching
             break;
           }
         } else {
           final NodeChildrenIterator children = actual.currentNode.getChildren(srcItr.next());
           final ChildReference child = children.getNode();
           if (child == null) {
             break;
           }
           actual.currentChild = child;
           actual.currentIterator = children;
           actual.moveDown();
           ++actPushes;
           actItr = actual.currentNode.keySequence.iterator();
         }
       } else if (actItr.hasNext()) {
         final NodeChildrenIterator children = source.currentNode.getChildren(actItr.next());
         final ChildReference child = children.getNode();
         if (child == null || !source.isAddressReclaimable(child.suffixAddress)) {
           break; // child can be expired if source parent was already not-current
         }
         source.currentChild = child;
         source.currentIterator = children;
         source.moveDown();
         ++srcPushes;
         srcItr = source.currentNode.keySequence.iterator();
       } else { // both iterators matched, here comes the branching
         reclaimChildren(source, actual);
         break;
       }
     }
     for (int i = 0; i < srcPushes; ++i) {
       source.moveUp();
     }
     for (int i = 0; i < actPushes; ++i) {
       actual.popAndMutate();
     }
   }
 }
Exemplo n.º 2
0
 private static void reclaimChildren(
     @NotNull final PatriciaReclaimSourceTraverser source,
     @NotNull final PatriciaReclaimActualTraverser actual) {
   source.moveToNextReclaimable();
   while (source.isValidPos() && actual.isValidPos()) {
     final ChildReference sourceChild = source.currentChild;
     final int sourceByte = sourceChild.firstByte & 0xff;
     final int actualByte = actual.currentChild.firstByte & 0xff;
     if (sourceByte < actualByte) {
       source.moveRight();
     } else if (sourceByte > actualByte) {
       actual.moveRight();
     } else {
       source.moveDown();
       actual.moveDown();
       reclaim(source, actual);
       actual.popAndMutate();
       source.moveUp();
       source.moveRight();
       actual.moveRight();
     }
   }
 }