Exemplo n.º 1
0
 private void fetchNext() {
   while (fetchNextKey()) {
     if (pos1 == null || pos2 == null) {
       break;
     }
     @SuppressWarnings("unchecked")
     V v1 = (V) map.binarySearch(root1, current);
     @SuppressWarnings("unchecked")
     V v2 = (V) map.binarySearch(root2, current);
     if (!v1.equals(v2)) {
       break;
     }
   }
 }
Exemplo n.º 2
0
 @SuppressWarnings("unchecked")
 private CursorPos fetchNext(CursorPos p) {
   while (p != null) {
     if (p.index < p.page.getKeyCount()) {
       current = (K) p.page.getKey(p.index++);
       return p;
     }
     p = p.parent;
     if (p == null) {
       break;
     }
     if (p.index + 1 < map.getChildPageCount(p.page)) {
       p = new CursorPos(p.page.getChildPage(++p.index), 0, p);
       p = min(p);
     }
   }
   current = null;
   return p;
 }
Exemplo n.º 3
0
 private boolean fetchNextKey() {
   while (true) {
     if (state == 3) {
       return false;
     }
     if (state == 1) {
       // read from root1
       pos1 = fetchNext(pos1);
       if (pos1 == null) {
         // reached the end of pos1
         state = 2;
         pos2 = null;
         continue;
       }
       pos2 = find(root2, current);
       if (pos2 == null) {
         // not found in root2
         return true;
       }
       if (!pos1.page.equals(pos2.page)) {
         // the page is different,
         // so the entry has possibly changed
         return true;
       }
       while (true) {
         pos1 = pos1.parent;
         if (pos1 == null) {
           // reached end of pos1
           state = 2;
           pos2 = null;
           break;
         }
         pos2 = pos2.parent;
         if (pos2 == null || !pos1.page.equals(pos2.page)) {
           if (pos1.index + 1 < map.getChildPageCount(pos1.page)) {
             pos1 = new CursorPos(pos1.page.getChildPage(++pos1.index), 0, pos1);
             pos1 = min(pos1);
             break;
           }
         }
       }
     }
     if (state == 2) {
       if (pos2 == null) {
         // init reading from root2
         pos2 = new CursorPos(root2, 0, null);
         pos2 = min(pos2);
       }
       // read from root2
       pos2 = fetchNext(pos2);
       if (pos2 == null) {
         // reached the end of pos2
         state = 3;
         current = null;
         continue;
       }
       pos1 = find(root1, current);
       if (pos1 != null) {
         // found a corresponding record
         // so it was not deleted
         // but now we may need to skip pages
         if (!pos1.page.equals(pos2.page)) {
           // the page is different
           pos1 = null;
           continue;
         }
         while (true) {
           pos2 = pos2.parent;
           if (pos2 == null) {
             // reached end of pos1
             state = 3;
             current = null;
             pos1 = null;
             break;
           }
           pos1 = pos1.parent;
           if (pos1 == null || !pos2.page.equals(pos1.page)) {
             if (pos2.index + 1 < map.getChildPageCount(pos2.page)) {
               pos2 = new CursorPos(pos2.page.getChildPage(++pos2.index), 0, pos2);
               pos2 = min(pos2);
               break;
             }
           }
         }
         pos1 = null;
         continue;
       }
       // found no corresponding record
       // so it was deleted
       return true;
     }
   }
 }