Search in sources :

Example 1 with DiffDepth

use of org.sirix.diff.DiffDepth in project sirix by sirixdb.

the class DiffSunburstAxis method processFirstChild.

/**
 * Process first child.
 *
 * @param pDepth
 *          depth of diff
 * @param pNextDepth
 *          depth of next diff
 * @return {@code true} if axis has more nodes, {@code false} otherwise
 */
private boolean processFirstChild(@Nonnegative final int pDepth, @Nonnegative final int pNextDepth) {
    assert pDepth >= 0;
    assert pNextDepth >= 0;
    processLastItem(pNextDepth);
    if (mModel.getIsPruned()) {
        if (mDiff != DiffType.SAMEHASH) {
            mPrunedNodes += mDescendantCount - 1;
        }
        final boolean isOldTransaction = (mDiff == DiffType.DELETED || mDiff == DiffType.MOVEDFROM || mDiff == DiffType.REPLACEDOLD);
        final DiffDepth depthCont = mDiffCont.getDepth();
        final int depth = isOldTransaction ? depthCont.getOldDepth() : depthCont.getNewDepth();
        if (mIndex + mPrunedNodes + 1 < mSize) {
            final DiffTuple nextDiffCont = mDiffs.get(mIndex + mPrunedNodes + 1);
            final DiffType nextDiff = nextDiffCont.getDiff();
            final boolean nextIsOldTransaction = (nextDiff == DiffType.DELETED || nextDiff == DiffType.MOVEDFROM || nextDiff == DiffType.REPLACEDOLD);
            final DiffDepth nextDepthCont = nextDiffCont.getDepth();
            final int nextDepth = nextIsOldTransaction ? nextDepthCont.getOldDepth() : nextDepthCont.getNewDepth();
            if (depth == nextDepth) {
                mAngle += mExtension;
                mMoved = Moved.STARTRIGHTSIBL;
                determineIfHasNext();
                return true;
            } else {
                processStacks(depth, nextDepth);
                mMoved = Moved.ANCHESTSIBL;
                determineIfHasNext();
                return true;
            }
        }
    } else {
        mDiffStack.push(mModificationCount);
        mAngleStack.push(mAngle);
        mExtensionStack.push(mExtension);
        mParentStack.push(mIndex);
        mDescendantsStack.push(mDescendantCount);
        mDepth++;
        mMoved = Moved.CHILD;
    }
    determineIfHasNext();
    return true;
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) DiffDepth(org.sirix.diff.DiffDepth) DiffType(org.sirix.diff.DiffFactory.DiffType)

Example 2 with DiffDepth

use of org.sirix.diff.DiffDepth in project sirix by sirixdb.

the class DiffSunburstAxis method hasNext.

@Override
public boolean hasNext() {
    if (getNext()) {
        return true;
    }
    resetToLastKey();
    // Fail if there is no node anymore.
    if (!mHasNext) {
        return false;
    }
    // Setup everything.
    mDiffCont = mDiffs.get(mIndex + mPrunedNodes + 1);
    mDiff = mDiffCont.getDiff();
    final boolean isOldTransaction = (mDiff == DiffType.DELETED || mDiff == DiffType.MOVEDFROM || mDiff == DiffType.REPLACEDOLD);
    final long nodeKey = isOldTransaction ? mDiffCont.getOldNodeKey() : mDiffCont.getNewNodeKey();
    final DiffDepth depthCont = mDiffCont.getDepth();
    mOrigDepth = isOldTransaction ? depthCont.getOldDepth() : depthCont.getNewDepth();
    setTransaction(isOldTransaction ? mOldRtx : mNewRtx);
    // Move to next key.
    getTransaction().moveTo(nodeKey);
    if (mDiff == DiffType.UPDATED) {
        mOldRtx.moveTo(mDiffCont.getOldNodeKey());
    }
    if (mDiff == DiffType.REPLACEDOLD) {
        mNewRtx.moveTo(mDiffCont.getNewNodeKey());
    }
    if (mIndex + mPrunedNodes + 2 < mSize) {
        final DiffTuple nextDiffCont = mDiffs.get(mIndex + mPrunedNodes + 2);
        final DiffType nextDiff = nextDiffCont.getDiff();
        final boolean nextIsOldTransaction = (nextDiff == DiffType.DELETED || nextDiff == DiffType.MOVEDFROM || nextDiff == DiffType.REPLACEDOLD);
        final DiffDepth nextDepthCont = nextDiffCont.getDepth();
        final int nextDepth = nextIsOldTransaction ? nextDepthCont.getOldDepth() : nextDepthCont.getNewDepth();
        // Always follow first child if there is one.
        if (nextDepth > mOrigDepth) {
            return processFirstChild(mOrigDepth, nextDepth);
        }
        // Then follow right sibling if there is one.
        if (mOrigDepth == nextDepth) {
            return processRightSibling(nextDepth);
        }
        // Then follow right sibling on stack.
        if (nextDepth < mOrigDepth) {
            return processNextFollowing(mOrigDepth, nextDepth);
        }
    }
    // Then end.
    processLastItem(1);
    mHasNext = false;
    return true;
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) DiffDepth(org.sirix.diff.DiffDepth) DiffType(org.sirix.diff.DiffFactory.DiffType)

Example 3 with DiffDepth

use of org.sirix.diff.DiffDepth in project sirix by sirixdb.

the class Modifications method countDiffs.

/**
 * Count how many differences in the subtree exists and add descendant-or-self
 * count.
 *
 * @return number of differences and descendants
 * @throws SirixException
 *           if sirix can't close the transaction
 */
public Modification countDiffs() throws SirixException {
    int index = mIndex;
    final DiffTuple diffCont = mDiffs.get(index);
    final DiffType diff = diffCont.getDiff();
    final int rootDepth = (diff == DiffType.DELETED || diff == DiffType.MOVEDFROM || diff == DiffType.REPLACEDOLD) ? diffCont.getDepth().getOldDepth() : diffCont.getDepth().getNewDepth();
    int diffCounts = 0;
    int descendantCounts = 1;
    boolean subtract = false;
    diffCounts = incrDiffCounter(index, diffCounts);
    index++;
    if (diffCounts == 1 && index < mDiffs.size()) {
        final DiffTuple cont = mDiffs.get(index);
        final int depth = (cont.getDiff() == DiffType.DELETED || cont.getDiff() == DiffType.MOVEDFROM || cont.getDiff() == DiffType.REPLACEDOLD) ? cont.getDepth().getOldDepth() : cont.getDepth().getNewDepth();
        if (depth == rootDepth + 1) {
            // Current node is modified and has at least one child.
            subtract = true;
        }
    }
    boolean done = false;
    while (!done && index < mDiffs.size()) {
        final DiffTuple currDiffCont = mDiffs.get(index);
        final DiffType currDiff = currDiffCont.getDiff();
        final DiffDepth currDepth = currDiffCont.getDepth();
        final int depth = (currDiff == DiffType.DELETED || currDiff == DiffType.MOVEDFROM || currDiff == DiffType.REPLACEDOLD) ? currDepth.getOldDepth() : currDepth.getNewDepth();
        if (depth <= rootDepth) {
            done = true;
        }
        if (!done) {
            descendantCounts++;
            if (currDiff != DiffType.SAME && currDiff != DiffType.SAMEHASH) {
                diffCounts++;
            }
            index++;
        }
    }
    // Add a factor to add some weighting to the diffCounts.
    return new Modification(TraverseModel.FACTOR * diffCounts, descendantCounts, subtract);
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) DiffType(org.sirix.diff.DiffFactory.DiffType) DiffDepth(org.sirix.diff.DiffDepth)

Example 4 with DiffDepth

use of org.sirix.diff.DiffDepth in project sirix by sirixdb.

the class DiffSunburstAxis method setTempKey.

/**
 * Set temporal key which is the next following node of an {@code inserted},
 * {@code deleted}, {@code updated} or {@code same} node.
 */
private void setTempKey() {
    final int index = mIndex + mPrunedNodes + mDescendantCount;
    final boolean isOldTransaction = (mDiff == DiffType.DELETED || mDiff == DiffType.MOVEDFROM || mDiff == DiffType.REPLACEDOLD);
    final DiffDepth depthCont = mDiffCont.getDepth();
    final int depth = isOldTransaction ? depthCont.getOldDepth() : depthCont.getNewDepth();
    if (index < mSize) {
        DiffTuple nextDiffCont = mDiffs.get(index);
        DiffType nextDiff = nextDiffCont.getDiff();
        boolean nextIsOldTransaction = (nextDiff == DiffType.DELETED || nextDiff == DiffType.MOVEDFROM || nextDiff == DiffType.REPLACEDOLD);
        DiffDepth nextDepthCont = nextDiffCont.getDepth();
        int nextDepth = nextIsOldTransaction ? nextDepthCont.getOldDepth() : nextDepthCont.getNewDepth();
        assert nextDepth <= depth;
        mTempKey = nextIsOldTransaction ? nextDiffCont.getOldNodeKey() : nextDiffCont.getNewNodeKey();
    }
}
Also used : DiffTuple(org.sirix.diff.DiffTuple) DiffDepth(org.sirix.diff.DiffDepth) DiffType(org.sirix.diff.DiffFactory.DiffType)

Aggregations

DiffDepth (org.sirix.diff.DiffDepth)4 DiffType (org.sirix.diff.DiffFactory.DiffType)4 DiffTuple (org.sirix.diff.DiffTuple)4