static DoublesSketchAccessor wrap(final DoublesSketch ds) { return wrap(ds, false); }
/** * Advancing the iterator and checking existence of the next entry * is combined here for efficiency. This results in an undefined * state of the iterator before the first call of this method. * @return true if the next element exists */ public boolean next() { if (sketchAccessor_ == null) { // initial setup sketchAccessor_ = DoublesSketchAccessor.wrap(sketch_); } else { // advance index within the current level i_++; } if (i_ < sketchAccessor_.numItems()) { return true; } // go to the next non-empty level do { level_++; if (level_ > 0) { bits_ >>>= 1; } if (bits_ == 0L) { return false; // run out of levels } weight_ *= 2; } while ((bits_ & 1L) == 0L); i_ = 0; sketchAccessor_.setLevel(level_); return true; }
/** * Constructs the Auxiliary structure from the DoublesSketch * @param qs a DoublesSketch */ DoublesAuxiliary(final DoublesSketch qs ) { final int k = qs.getK(); final long n = qs.getN(); final long bitPattern = qs.getBitPattern(); final int numSamples = qs.getRetainedItems(); final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(qs); final double[] itemsArr = new double[numSamples]; final long[] cumWtsArr = new long[numSamples + 1]; // the extra slot is very important // Populate from DoublesSketch: // copy over the "levels" and then the base buffer, all with appropriate weights populateFromDoublesSketch(k, n, bitPattern, sketchAccessor, itemsArr, cumWtsArr); // Sort the first "numSamples" slots of the two arrays in tandem, // taking advantage of the already sorted blocks of length k blockyTandemMergeSort(itemsArr, cumWtsArr, numSamples, k); final long total = QuantilesHelper.convertToPrecedingCummulative(cumWtsArr); assert total == n; auxN_ = n; auxSamplesArr_ = itemsArr; auxCumWtsArr_ = cumWtsArr; }
static DoublesSketchAccessor wrap(final DoublesSketch ds) { return wrap(ds, false); }
final double[] combinedBuffer = new double[retainedItems]; final DoublesSketchAccessor accessor = DoublesSketchAccessor.wrap(sketch); assert hcds.baseBufferCount_ == accessor.numItems();
final DoublesSketchAccessor samples = DoublesSketchAccessor.wrap(this); long total = 0; int weight = 1;
final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(sketch); Util.checkSplitPointsOrder(splitPoints);
private static void checkToFromByteArray2(int k, int n) { DoublesSketch qs = buildAndLoadQS(k, n); byte[] byteArr; Memory mem; DoublesSketch qs2; // from compact byteArr = qs.toByteArray(true); mem = Memory.wrap(byteArr); qs2 = UpdateDoublesSketch.heapify(mem); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0); } // ordered, non-compact byteArr = qs.toByteArray(false); mem = Memory.wrap(byteArr); qs2 = DoublesSketch.heapify(mem); final DoublesSketchAccessor dsa = DoublesSketchAccessor.wrap(qs2); dsa.sort(); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0); } // not ordered, not compact byteArr = qs.toByteArray(false); mem = Memory.wrap(byteArr); qs2 = DoublesSketch.heapify(mem); for (double f = 0.1; f < 0.95; f += 0.1) { assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0); } }
final DoublesSketchAccessor dsa = DoublesSketchAccessor.wrap(sketch, !compact);
final DoublesSketchAccessor inputAccessor = DoublesSketchAccessor.wrap(sketch); assert bbCount == inputAccessor.numItems();
ret = HeapUpdateDoublesSketch.newInstance(myMaxK); final DoublesSketchAccessor otherAccessor = DoublesSketchAccessor.wrap(other); for (int i = 0; i < otherAccessor.numItems(); ++i) { ret.update(otherAccessor.get(i)); ret = myQS; final DoublesSketchAccessor otherAccessor = DoublesSketchAccessor.wrap(other); for (int i = 0; i < otherAccessor.numItems(); ++i) { ret.update(otherAccessor.get(i));
/** * Advancing the iterator and checking existence of the next entry * is combined here for efficiency. This results in an undefined * state of the iterator before the first call of this method. * @return true if the next element exists */ public boolean next() { if (sketchAccessor_ == null) { // initial setup sketchAccessor_ = DoublesSketchAccessor.wrap(sketch_); } else { // advance index within the current level i_++; } if (i_ < sketchAccessor_.numItems()) { return true; } // go to the next non-empty level do { level_++; if (level_ > 0) { bits_ >>>= 1; } if (bits_ == 0L) { return false; // run out of levels } weight_ *= 2; } while ((bits_ & 1L) == 0L); i_ = 0; sketchAccessor_.setLevel(level_); return true; }
/** * Constructs the Auxiliary structure from the DoublesSketch * @param qs a DoublesSketch */ DoublesAuxiliary(final DoublesSketch qs ) { final int k = qs.getK(); final long n = qs.getN(); final long bitPattern = qs.getBitPattern(); final int numSamples = qs.getRetainedItems(); final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(qs); final double[] itemsArr = new double[numSamples]; final long[] cumWtsArr = new long[numSamples + 1]; // the extra slot is very important // Populate from DoublesSketch: // copy over the "levels" and then the base buffer, all with appropriate weights populateFromDoublesSketch(k, n, bitPattern, sketchAccessor, itemsArr, cumWtsArr); // Sort the first "numSamples" slots of the two arrays in tandem, // taking advantage of the already sorted blocks of length k blockyTandemMergeSort(itemsArr, cumWtsArr, numSamples, k); final long total = QuantilesHelper.convertToPrecedingCummulative(cumWtsArr); assert total == n; auxN_ = n; auxSamplesArr_ = itemsArr; auxCumWtsArr_ = cumWtsArr; }
final DoublesSketchAccessor samples = DoublesSketchAccessor.wrap(this); long total = 0; int weight = 1;