/** * Simple pass that merges entries with the same value */ private static int mergeSameBuckets(double[] values, double[] weights, int nextIndex) { sort(values, weights, nextIndex); int current = 0; for (int i = 1; i < nextIndex; i++) { if (values[current] == values[i]) { weights[current] += weights[i]; } else { current++; values[current] = values[i]; weights[current] = weights[i]; } } return current + 1; }
/** * Dump the entries in the queue back into the bucket arrays * The values are guaranteed to be sorted in increasing order after this method completes */ private void store(PriorityQueue<Entry> queue) { nextIndex = 0; for (Entry entry : queue) { if (entry.isValid()) { values[nextIndex] = entry.getValue(); weights[nextIndex] = entry.getWeight(); nextIndex++; } } sort(values, weights, nextIndex); }
public void mergeWith(NumericHistogram other) { int count = nextIndex + other.nextIndex; double[] newValues = new double[count]; double[] newWeights = new double[count]; concat(newValues, this.values, this.nextIndex, other.values, other.nextIndex); concat(newWeights, this.weights, this.nextIndex, other.weights, other.nextIndex); count = mergeSameBuckets(newValues, newWeights, count); if (count <= maxBuckets) { // copy back into this.values/this.weights System.arraycopy(newValues, 0, this.values, 0, count); System.arraycopy(newWeights, 0, this.weights, 0, count); nextIndex = count; return; } sort(newValues, newWeights, count); store(mergeBuckets(newValues, newWeights, count, maxBuckets)); }
/** * Simple pass that merges entries with the same value */ private static int mergeSameBuckets(double[] values, double[] weights, int nextIndex) { sort(values, weights, nextIndex); int current = 0; for (int i = 1; i < nextIndex; i++) { if (values[current] == values[i]) { weights[current] += weights[i]; } else { current++; values[current] = values[i]; weights[current] = weights[i]; } } return current + 1; }
/** * Dump the entries in the queue back into the bucket arrays * The values are guaranteed to be sorted in increasing order after this method completes */ private void store(PriorityQueue<Entry> queue) { nextIndex = 0; for (Entry entry : queue) { if (entry.isValid()) { values[nextIndex] = entry.getValue(); weights[nextIndex] = entry.getWeight(); nextIndex++; } } sort(values, weights, nextIndex); }
public void mergeWith(NumericHistogram other) { int count = nextIndex + other.nextIndex; double[] newValues = new double[count]; double[] newWeights = new double[count]; concat(newValues, this.values, this.nextIndex, other.values, other.nextIndex); concat(newWeights, this.weights, this.nextIndex, other.weights, other.nextIndex); count = mergeSameBuckets(newValues, newWeights, count); if (count <= maxBuckets) { // copy back into this.values/this.weights System.arraycopy(newValues, 0, this.values, 0, count); System.arraycopy(newWeights, 0, this.weights, 0, count); nextIndex = count; return; } sort(newValues, newWeights, count); store(mergeBuckets(newValues, newWeights, count, maxBuckets)); }