This is an automated email from the ASF dual-hosted git repository. leerho pushed a commit to branch Fix_getResultAndReset in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit 8d7e7188ead3c3abf40ddbc6177bcae8dd0605da Author: Lee Rhodes <lee...@gmail.com> AuthorDate: Mon Aug 4 12:14:08 2025 -0700 In process commit --- .../quantiles/DirectUpdateDoublesSketch.java | 7 ++++++ .../quantiles/HeapUpdateDoublesSketch.java | 29 +++++++++++++++++++++- .../quantiles/UpdateDoublesSketch.java | 29 +++++++++++++--------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java index 716638da7..dbf34c81e 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java @@ -62,6 +62,7 @@ import org.apache.datasketches.common.MemorySegmentRequest; final class DirectUpdateDoublesSketch extends DirectUpdateDoublesSketchR { private MemorySegmentRequest mSegReq = null; + //**CONSTRUCTORS** private DirectUpdateDoublesSketch(final int k, final MemorySegment seg, final MemorySegmentRequest mSegReq) { super(k, seg); //Checks k this.mSegReq = mSegReq; @@ -99,6 +100,10 @@ final class DirectUpdateDoublesSketch extends DirectUpdateDoublesSketchR { return new DirectUpdateDoublesSketch(k, dstSeg, mSegReq); } + static DirectUpdateDoublesSketch(final DirectUpdateDoublesSketch skIn) { + return null; + } + /** * Wrap this sketch around the given non-compact MemorySegment image of a DoublesSketch. * @@ -130,6 +135,8 @@ final class DirectUpdateDoublesSketch extends DirectUpdateDoublesSketchR { return new DirectUpdateDoublesSketch(k, srcSeg, mSegReq); } + //**END CONSTRUCTORS** + @Override public boolean isReadOnly() { return false; diff --git a/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java index 300e3e440..30a2bdd9b 100644 --- a/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java @@ -96,7 +96,7 @@ final class HeapUpdateDoublesSketch extends UpdateDoublesSketch { */ private double[] combinedBuffer_; - //**CONSTRUCTORS********************************************************** + //**CONSTRUCTORS** private HeapUpdateDoublesSketch(final int k) { super(k); //Checks k } @@ -120,6 +120,24 @@ final class HeapUpdateDoublesSketch extends UpdateDoublesSketch { return huds; } + /** + * Returns a copy of the given sketch + * @param skIn the given sketch + * @return a copy of the given sketch + */ + static HeapUpdateDoublesSketch copy(final HeapUpdateDoublesSketch skIn) { + final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.newInstance(skIn.k_); + if (skIn.n_ > 0) { + skCopy.n_ = skIn.n_; + skCopy.combinedBuffer_ = skIn.combinedBuffer_.clone(); + skCopy.baseBufferCount_ = skIn.baseBufferCount_; + skCopy.bitPattern_ = skIn.bitPattern_; + skCopy.minItem_ = skIn.minItem_; + skCopy.maxItem_ = skIn.maxItem_; + } + return skCopy; + } + /** * Heapifies the given srcSeg, which must be a MemorySegment image of a DoublesSketch and may have data. * @@ -166,6 +184,8 @@ final class HeapUpdateDoublesSketch extends UpdateDoublesSketch { return huds; } + //**END CONSTRUCTORS** + @Override public double getMaxItem() { if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); } @@ -183,6 +203,13 @@ final class HeapUpdateDoublesSketch extends UpdateDoublesSketch { return n_; } + @Override + HeapUpdateDoublesSketch getResultAndReset() { + final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.copy(this); + reset(); + return skCopy; + } + @Override public boolean hasMemorySegment() { return false; diff --git a/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java index 5f12a0461..ba9309f5f 100644 --- a/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java @@ -72,16 +72,26 @@ public abstract class UpdateDoublesSketch extends DoublesSketch { return DirectCompactDoublesSketch.createFromUpdateSketch(this, dstSeg); } - @Override - public abstract void update(double item); + /** + * Returns a copy of this sketch and then resets this sketch with the same value of <i>k</i>. + * @return a copy of this sketch and then resets this sketch with the same value of <i>k</i>. + */ + abstract UpdateDoublesSketch getResultAndReset(); + + /** + * Grows the combined buffer to the given spaceNeeded + * + * @param currentSpace the current allocated space + * @param spaceNeeded the space needed + * @return the enlarged combined buffer with data from the original combined buffer. + */ + abstract double[] growCombinedBuffer(int currentSpace, int spaceNeeded); @Override boolean isCompact() { return false; } - //Puts - /** * Puts the minimum item * @@ -124,12 +134,7 @@ public abstract class UpdateDoublesSketch extends DoublesSketch { */ abstract void putBitPattern(long bitPattern); - /** - * Grows the combined buffer to the given spaceNeeded - * - * @param currentSpace the current allocated space - * @param spaceNeeded the space needed - * @return the enlarged combined buffer with data from the original combined buffer. - */ - abstract double[] growCombinedBuffer(int currentSpace, int spaceNeeded); + @Override + public abstract void update(double item); + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@datasketches.apache.org For additional commands, e-mail: commits-h...@datasketches.apache.org