Skip to content

Commit 8d7e718

Browse files
committed
In process commit
1 parent 9ad6c07 commit 8d7e718

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
final class DirectUpdateDoublesSketch extends DirectUpdateDoublesSketchR {
6363
private MemorySegmentRequest mSegReq = null;
6464

65+
//**CONSTRUCTORS**
6566
private DirectUpdateDoublesSketch(final int k, final MemorySegment seg, final MemorySegmentRequest mSegReq) {
6667
super(k, seg); //Checks k
6768
this.mSegReq = mSegReq;
@@ -99,6 +100,10 @@ static DirectUpdateDoublesSketch newInstance(final int k, final MemorySegment ds
99100
return new DirectUpdateDoublesSketch(k, dstSeg, mSegReq);
100101
}
101102

103+
static DirectUpdateDoublesSketch(final DirectUpdateDoublesSketch skIn) {
104+
return null;
105+
}
106+
102107
/**
103108
* Wrap this sketch around the given non-compact MemorySegment image of a DoublesSketch.
104109
*
@@ -130,6 +135,8 @@ static DirectUpdateDoublesSketch wrapInstance(final MemorySegment srcSeg, final
130135
return new DirectUpdateDoublesSketch(k, srcSeg, mSegReq);
131136
}
132137

138+
//**END CONSTRUCTORS**
139+
133140
@Override
134141
public boolean isReadOnly() {
135142
return false;

src/main/java/org/apache/datasketches/quantiles/HeapUpdateDoublesSketch.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ final class HeapUpdateDoublesSketch extends UpdateDoublesSketch {
9696
*/
9797
private double[] combinedBuffer_;
9898

99-
//**CONSTRUCTORS**********************************************************
99+
//**CONSTRUCTORS**
100100
private HeapUpdateDoublesSketch(final int k) {
101101
super(k); //Checks k
102102
}
@@ -120,6 +120,24 @@ static HeapUpdateDoublesSketch newInstance(final int k) {
120120
return huds;
121121
}
122122

123+
/**
124+
* Returns a copy of the given sketch
125+
* @param skIn the given sketch
126+
* @return a copy of the given sketch
127+
*/
128+
static HeapUpdateDoublesSketch copy(final HeapUpdateDoublesSketch skIn) {
129+
final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.newInstance(skIn.k_);
130+
if (skIn.n_ > 0) {
131+
skCopy.n_ = skIn.n_;
132+
skCopy.combinedBuffer_ = skIn.combinedBuffer_.clone();
133+
skCopy.baseBufferCount_ = skIn.baseBufferCount_;
134+
skCopy.bitPattern_ = skIn.bitPattern_;
135+
skCopy.minItem_ = skIn.minItem_;
136+
skCopy.maxItem_ = skIn.maxItem_;
137+
}
138+
return skCopy;
139+
}
140+
123141
/**
124142
* Heapifies the given srcSeg, which must be a MemorySegment image of a DoublesSketch and may have data.
125143
*
@@ -166,6 +184,8 @@ static HeapUpdateDoublesSketch heapifyInstance(final MemorySegment srcSeg) {
166184
return huds;
167185
}
168186

187+
//**END CONSTRUCTORS**
188+
169189
@Override
170190
public double getMaxItem() {
171191
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
@@ -183,6 +203,13 @@ public long getN() {
183203
return n_;
184204
}
185205

206+
@Override
207+
HeapUpdateDoublesSketch getResultAndReset() {
208+
final HeapUpdateDoublesSketch skCopy = HeapUpdateDoublesSketch.copy(this);
209+
reset();
210+
return skCopy;
211+
}
212+
186213
@Override
187214
public boolean hasMemorySegment() {
188215
return false;

src/main/java/org/apache/datasketches/quantiles/UpdateDoublesSketch.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,26 @@ public CompactDoublesSketch compact(final MemorySegment dstSeg) {
7272
return DirectCompactDoublesSketch.createFromUpdateSketch(this, dstSeg);
7373
}
7474

75-
@Override
76-
public abstract void update(double item);
75+
/**
76+
* Returns a copy of this sketch and then resets this sketch with the same value of <i>k</i>.
77+
* @return a copy of this sketch and then resets this sketch with the same value of <i>k</i>.
78+
*/
79+
abstract UpdateDoublesSketch getResultAndReset();
80+
81+
/**
82+
* Grows the combined buffer to the given spaceNeeded
83+
*
84+
* @param currentSpace the current allocated space
85+
* @param spaceNeeded the space needed
86+
* @return the enlarged combined buffer with data from the original combined buffer.
87+
*/
88+
abstract double[] growCombinedBuffer(int currentSpace, int spaceNeeded);
7789

7890
@Override
7991
boolean isCompact() {
8092
return false;
8193
}
8294

83-
//Puts
84-
8595
/**
8696
* Puts the minimum item
8797
*
@@ -124,12 +134,7 @@ boolean isCompact() {
124134
*/
125135
abstract void putBitPattern(long bitPattern);
126136

127-
/**
128-
* Grows the combined buffer to the given spaceNeeded
129-
*
130-
* @param currentSpace the current allocated space
131-
* @param spaceNeeded the space needed
132-
* @return the enlarged combined buffer with data from the original combined buffer.
133-
*/
134-
abstract double[] growCombinedBuffer(int currentSpace, int spaceNeeded);
137+
@Override
138+
public abstract void update(double item);
139+
135140
}

0 commit comments

Comments
 (0)