public Entry[] toArray() {
    FastIterator it = tree.fastIterator();
    if (it == null) {
      return new Entry[0];
    }

    List<Comparable> toBeRemoved = new ArrayList<Comparable>();
    List<RightTuple> result = new ArrayList<RightTuple>();

    RBTree.Node<Comparable<Comparable>, RightTupleList> node;
    while ((node = (RBTree.Node<Comparable<Comparable>, RightTupleList>) it.next(null)) != null) {
      RightTupleList bucket = node.value;
      if (bucket.size() == 0) {
        toBeRemoved.add(node.key);
      } else {
        RightTuple entry = bucket.getFirst();
        while (entry != null) {
          result.add(entry);
          entry = (RightTuple) entry.getNext();
        }
      }
    }

    for (Comparable key : toBeRemoved) {
      tree.delete(key);
    }

    return result.toArray(new LeftTuple[result.size()]);
  }
 public Entry next(Entry object) {
   if (object == null) {
     return null;
   }
   RightTuple rightTuple = (RightTuple) object;
   RightTuple next = (RightTuple) rightTuple.getNext();
   if (next != null) {
     return next;
   }
   Comparable key = getRightIndexedValue(rightTuple);
   next = getNext(key, false);
   return next == null ? null : checkUpperBound(next, upperBound);
 }
Пример #3
0
  public static void doUpdatesExistentialReorderRightMemory(
      BetaMemory bm, BetaNode betaNode, TupleSets<RightTuple> srcRightTuples) {
    TupleMemory rtm = bm.getRightTupleMemory();

    boolean resumeFromCurrent =
        !(betaNode.isIndexedUnificationJoin() || rtm.getIndexType().isComparison());

    // remove all the staged rightTuples from the memory before to readd them all
    // this is to avoid split bucket when an updated rightTuple hasn't been moved yet
    // and so it is the first entry in the wrong bucket

    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
      RightTuple next = rightTuple.getStagedNext();
      if (rightTuple.getMemory() != null) {
        rightTuple.setTempRightTupleMemory(rightTuple.getMemory());

        if (resumeFromCurrent) {
          if (rightTuple.getBlocked() != null) {
            // look for a non-staged right tuple first forward ...
            RightTuple tempRightTuple = (RightTuple) rightTuple.getNext();
            while (tempRightTuple != null && tempRightTuple.getStagedType() != LeftTuple.NONE) {
              // next cannot be an updated or deleted rightTuple
              tempRightTuple = (RightTuple) tempRightTuple.getNext();
            }

            // ... and if cannot find one try backward
            if (tempRightTuple == null) {
              tempRightTuple = (RightTuple) rightTuple.getPrevious();
              while (tempRightTuple != null && tempRightTuple.getStagedType() != LeftTuple.NONE) {
                // next cannot be an updated or deleted rightTuple
                tempRightTuple = (RightTuple) tempRightTuple.getPrevious();
              }
            }

            rightTuple.setTempNextRightTuple(tempRightTuple);
          }
        }

        rightTuple.setTempBlocked(rightTuple.getBlocked());
        rightTuple.setBlocked(null);
        rtm.remove(rightTuple);
      }
      rightTuple = next;
    }

    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
      RightTuple next = rightTuple.getStagedNext();
      if (rightTuple.getTempRightTupleMemory() != null) {

        rtm.add(rightTuple);

        if (resumeFromCurrent) {
          RightTuple tempRightTuple = rightTuple.getTempNextRightTuple();
          if (rightTuple.getBlocked() != null
              && tempRightTuple == null
              && rightTuple.getMemory() == rightTuple.getTempRightTupleMemory()) {
            // the next RightTuple was null, but current RightTuple was added back into the same
            // bucket, so reset as root blocker to re-match can be attempted
            rightTuple.setTempNextRightTuple(rightTuple);
          }
        }

        for (LeftTuple childLeftTuple = rightTuple.getFirstChild(); childLeftTuple != null; ) {
          LeftTuple childNext = childLeftTuple.getRightParentNext();
          childLeftTuple.reAddLeft();
          childLeftTuple = childNext;
        }
      }
      rightTuple = next;
    }
  }