public static void dpUpdatesExistentialReorderLeftMemory(
      BetaMemory bm, LeftTupleSets srcLeftTuples) {
    LeftTupleMemory ltm = bm.getLeftTupleMemory();

    // sides must first be re-ordered, to ensure iteration integrity
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
      LeftTuple next = leftTuple.getStagedNext();
      if (leftTuple.getMemory() != null) {
        ltm.remove(leftTuple);
      }
      leftTuple = next;
    }

    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
      LeftTuple next = leftTuple.getStagedNext();
      if (leftTuple.getBlocker() == null) {
        ltm.add(leftTuple);
        for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; ) {
          LeftTuple childNext = childLeftTuple.getLeftParentNext();
          childLeftTuple.reAddRight();
          childLeftTuple = childNext;
        }
      }
      leftTuple = next;
    }
  }
  public static LeftTuple deleteLeftChild(
      LeftTuple childLeftTuple, LeftTupleSets trgLeftTuples, LeftTupleSets stagedLeftTuples) {
    switch (childLeftTuple.getStagedType()) {
        // handle clash with already staged entries
      case LeftTuple.INSERT:
        stagedLeftTuples.removeInsert(childLeftTuple);
        break;
      case LeftTuple.UPDATE:
        stagedLeftTuples.removeUpdate(childLeftTuple);
        break;
    }

    LeftTuple next = childLeftTuple.getLeftParentNext();

    trgLeftTuples.addDelete(childLeftTuple);
    childLeftTuple.unlinkFromRightParent();
    childLeftTuple.unlinkFromLeftParent();

    return next;
  }