Search in sources :

Example 6 with CornerCase

use of org.apache.datasketches.SetOperationCornerCases.CornerCase in project sketches-core by DataSketches.

the class AnotB method notB.

/**
 * This is part of a multistep, stateful AnotB operation and sets the given Tuple sketch as the
 * second (or <i>n+1</i>th) argument <i>B</i> of <i>A-AND-NOT-B</i>.
 * Performs an <i>AND NOT</i> operation with the existing internal state of this AnotB operator.
 *
 * <p>An input argument of null or empty is ignored.</p>
 *
 * <p>Rationale: A <i>null</i> for the second or following arguments is more tolerable because
 * <i>A NOT null</i> is still <i>A</i> even if we don't know exactly what the null represents. It
 * clearly does not have any content that overlaps with <i>A</i>. Also, because this can be part of
 * a multistep operation with multiple <i>notB</i> steps. Other following steps can still produce
 * a valid result.</p>
 *
 * <p>Use {@link #getResult(boolean)} to obtain the result.</p>
 *
 * @param skB The incoming Tuple sketch for the second (or following) argument <i>B</i>.
 */
@SuppressWarnings("unchecked")
public void notB(final Sketch<S> skB) {
    // ignore
    if (skB == null) {
        return;
    }
    final long thetaLongB = skB.getThetaLong();
    final int countB = skB.getRetainedEntries();
    final boolean emptyB = skB.isEmpty();
    final int id = SetOperationCornerCases.createCornerCaseId(thetaLong_, curCount_, empty_, thetaLongB, countB, emptyB);
    final CornerCase cCase = CornerCase.caseIdToCornerCase(id);
    final AnotbAction anotbAction = cCase.getAnotbAction();
    switch(anotbAction) {
        case EMPTY_1_0_T:
            {
                reset();
                break;
            }
        case DEGEN_MIN_0_F:
            {
                reset();
                thetaLong_ = min(thetaLong_, thetaLongB);
                empty_ = false;
                break;
            }
        case DEGEN_THA_0_F:
            {
                empty_ = false;
                curCount_ = 0;
                // thetaLong_ is ok
                break;
            }
        case TRIM_A:
            {
                thetaLong_ = min(thetaLong_, thetaLongB);
                final DataArrays<S> da = trimAndCopyDataArrays(hashArr_, summaryArr_, thetaLong_, true);
                hashArr_ = da.hashArr;
                curCount_ = (hashArr_ == null) ? 0 : hashArr_.length;
                summaryArr_ = da.summaryArr;
                // empty_ = is whatever SkA is,
                break;
            }
        case SKETCH_A:
            {
                // result is already in A
                break;
            }
        case FULL_ANOTB:
            {
                // both A and B should have valid entries.
                thetaLong_ = min(thetaLong_, thetaLongB);
                final DataArrays<S> daR = getCopyOfResultArraysTuple(thetaLong_, curCount_, hashArr_, summaryArr_, skB);
                hashArr_ = daR.hashArr;
                curCount_ = (hashArr_ == null) ? 0 : hashArr_.length;
                summaryArr_ = daR.summaryArr;
            // empty_ = is whatever SkA is,
            }
    }
}
Also used : CornerCase(org.apache.datasketches.SetOperationCornerCases.CornerCase) AnotbAction(org.apache.datasketches.SetOperationCornerCases.AnotbAction)

Aggregations

CornerCase (org.apache.datasketches.SetOperationCornerCases.CornerCase)6 AnotbAction (org.apache.datasketches.SetOperationCornerCases.AnotbAction)5 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)3