| 70 | } |
| 71 | |
| 72 | public byte[] histogram(final boolean include_id) { |
| 73 | ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(); |
| 74 | Output output = new Output(outBuffer); |
| 75 | |
| 76 | int bucketCount = buckets.size(); |
| 77 | try { |
| 78 | if (include_id) { |
| 79 | output.writeByte(id); |
| 80 | } |
| 81 | output.writeShort(bucketCount); |
| 82 | |
| 83 | for (Map.Entry<HistogramBucket, Long> bucket : buckets.entrySet()) { |
| 84 | output.writeFloat(bucket.getKey().getLowerBound()); |
| 85 | output.writeFloat(bucket.getKey().getUpperBound()); |
| 86 | output.writeLong(bucket.getValue(), true); |
| 87 | } |
| 88 | |
| 89 | output.writeLong(this.getUnderflow(), true); |
| 90 | output.writeLong(this.getOverflow(), true); |
| 91 | } finally { |
| 92 | output.close(); |
| 93 | } |
| 94 | return outBuffer.toByteArray(); |
| 95 | } |
| 96 | |
| 97 | public void fromHistogram(byte[] raw, final boolean include_id) { |
| 98 | if (raw.length < 6) { |