Search in sources :

Example 21 with ResizeFactor

use of com.yahoo.sketches.ResizeFactor in project sketches-core by DataSketches.

the class HeapQuickSelectSketch method reset.

@Override
public final void reset() {
    final ResizeFactor rf = getResizeFactor();
    final int lgArrLongsSM = Util.startingSubMultiple(lgNomLongs_ + 1, rf, MIN_LG_ARR_LONGS);
    if (lgArrLongsSM == lgArrLongs_) {
        final int arrLongs = cache_.length;
        assert (1 << lgArrLongs_) == arrLongs;
        java.util.Arrays.fill(cache_, 0L);
    } else {
        cache_ = new long[1 << lgArrLongsSM];
        lgArrLongs_ = lgArrLongsSM;
    }
    hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, lgArrLongs_);
    empty_ = true;
    curCount_ = 0;
    thetaLong_ = (long) (getP() * MAX_THETA_LONG_AS_DOUBLE);
}
Also used : ResizeFactor(com.yahoo.sketches.ResizeFactor)

Example 22 with ResizeFactor

use of com.yahoo.sketches.ResizeFactor in project sketches-core by DataSketches.

the class HeapQuickSelectSketch method resizeCache.

//Must resize. Changes lgArrLongs_ and cache_. theta and count don't change.
// Used by hashUpdate()
private final void resizeCache() {
    final ResizeFactor rf = getResizeFactor();
    final int lgTgtLongs = lgNomLongs_ + 1;
    final int lgDeltaLongs = lgTgtLongs - lgArrLongs_;
    //rf_.lg() could be 0
    final int lgResizeFactor = max(min(rf.lg(), lgDeltaLongs), 1);
    // new tgt size
    lgArrLongs_ += lgResizeFactor;
    final long[] tgtArr = new long[1 << lgArrLongs_];
    final int newCount = HashOperations.hashArrayInsert(cache_, tgtArr, lgArrLongs_, thetaLong_);
    //Assumes no dirty values.
    assert newCount == curCount_;
    curCount_ = newCount;
    cache_ = tgtArr;
    hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, lgArrLongs_);
}
Also used : ResizeFactor(com.yahoo.sketches.ResizeFactor)

Aggregations

ResizeFactor (com.yahoo.sketches.ResizeFactor)22 Test (org.testng.annotations.Test)11 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)6 Family (com.yahoo.sketches.Family)5 PreambleUtil.extractResizeFactor (com.yahoo.sketches.sampling.PreambleUtil.extractResizeFactor)3 ArrayList (java.util.ArrayList)3 SketchesException (com.yahoo.sketches.SketchesException)2 WritableMemory (com.yahoo.memory.WritableMemory)1 ArrayOfBooleansSerDe (com.yahoo.sketches.ArrayOfBooleansSerDe)1 Family.objectToFamily (com.yahoo.sketches.Family.objectToFamily)1