Skip to content

Commit

Permalink
Closes #90 - makes MergingDigest be consistent on serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdunning committed Aug 6, 2017
1 parent d05568e commit 0e0614b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 7 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
In release 3.2

The following issues are fixed in this release

[Issue #90](https://github.com/tdunning/t-digest/issues/90) Serialization for MergingDigest

[Issue #92](https://github.com/tdunning/t-digest/issues/92) Serialization for AVLTreeDigest
2 changes: 1 addition & 1 deletion src/main/java/com/tdunning/math/stats/AVLTreeDigest.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public double compression() {
*/
@Override
public int byteSize() {
return 4 + 8 * 2 + 8 + 4 + summary.size() * 12;
return 32 + summary.size() * 12;
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/tdunning/math/stats/MergingDigest.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ public int byteSize() {
compress();
// format code, compression(float), buffer-size(int), temp-size(int), #centroids-1(int),
// then two doubles per centroid
return lastUsedCell * 16 + 36;
return lastUsedCell * 16 + 32;
}

@Override
Expand All @@ -780,14 +780,10 @@ public void asBytes(ByteBuffer buf) {
buf.putInt(Encoding.VERBOSE_ENCODING.code);
buf.putDouble(min);
buf.putDouble(max);
buf.putFloat((float) compression);
buf.putInt(mean.length);
buf.putInt(tempMean.length);
buf.putDouble(compression);
buf.putInt(lastUsedCell);
for (int i = 0; i < lastUsedCell; i++) {
buf.putDouble(weight[i]);
}
for (int i = 0; i < lastUsedCell; i++) {
buf.putDouble(mean[i]);
}
}
Expand All @@ -814,11 +810,11 @@ public static MergingDigest fromBytes(ByteBuffer buf) {
if (encoding == Encoding.VERBOSE_ENCODING.code) {
double min = buf.getDouble();
double max = buf.getDouble();
double compression = buf.getFloat();
double compression = buf.getDouble();
int n = buf.getInt();
MergingDigest r = new MergingDigest(compression);
r.setMinMax(min, max);
r.lastUsedCell = buf.getInt();
r.lastUsedCell = n;
for (int i = 0; i < n; i++) {
r.weight[i] = buf.getDouble();
r.mean[i] = buf.getDouble();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/tdunning/math/stats/TDigestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public double nextDouble() {
@Test
public void testSerialization() {
Random gen = getRandom();
final double compression = randomDouble() * 100;
final double compression = 20 + randomDouble() * 100;
TDigest dist = factory(compression).create();
for (int i = 0; i < 100000; i++) {
double x = gen.nextDouble();
Expand Down

0 comments on commit 0e0614b

Please sign in to comment.