Skip to content

Commit 8a55241

Browse files
author
lrhodes
committed
small refactoring.
1 parent 07f4628 commit 8a55241

8 files changed

Lines changed: 33 additions & 51 deletions

File tree

src/main/java/com/yahoo/sketches/hll/AbstractCoupons.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ static final int find(final int[] array, final int lgArrInts, final int coupon)
160160
int probe = coupon & arrMask;
161161
final int loopIndex = probe;
162162
do {
163-
final int arrVal = array[probe];
164-
if (arrVal == EMPTY) { //Compares on entire coupon
163+
final int couponAtIdx = array[probe];
164+
if (couponAtIdx == EMPTY) {
165165
return ~probe; //empty
166166
}
167-
else if (coupon == arrVal) { //Compares on entire coupon
167+
else if (coupon == couponAtIdx) {
168168
return probe; //duplicate
169169
}
170170
final int stride = ((coupon & KEY_MASK_26) >>> lgArrInts) | 1;

src/main/java/com/yahoo/sketches/hll/CouponHashSet.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ HllSketchImpl couponUpdate(final int coupon) {
105105
}
106106
couponIntArr[~index] = coupon; //found empty
107107
couponCount++;
108-
final boolean promote = checkGrowOrPromote();
109-
if (!promote) { return this; }
110-
return promoteHeapListOrSetToHll(this);
108+
if (checkGrowOrPromote()) {
109+
return promoteHeapListOrSetToHll(this);
110+
}
111+
return this;
111112
}
112113

113114
@Override
@@ -122,17 +123,16 @@ int getPreInts() {
122123

123124
private boolean checkGrowOrPromote() {
124125
if ((RESIZE_DENOM * couponCount) > (RESIZE_NUMER * (1 << lgCouponArrInts))) {
125-
if (lgCouponArrInts == (lgConfigK - 3)) {
126-
return true; // promote
126+
if (lgCouponArrInts == (lgConfigK - 3)) { //at max size
127+
return true; // promote to HLL
127128
}
128129
couponIntArr = growHashSet(couponIntArr, ++lgCouponArrInts);
129130
}
130131
return false;
131132
}
132133

133134
private static final int[] growHashSet(final int[] coupIntArr, final int tgtLgCoupArrSize) {
134-
final int tgtArrSize = 1 << tgtLgCoupArrSize;
135-
final int[] tgtCouponIntArr = new int[tgtArrSize]; //create tgt
135+
final int[] tgtCouponIntArr = new int[1 << tgtLgCoupArrSize]; //create tgt
136136
final int len = coupIntArr.length;
137137
for (int i = 0; i < len; i++) { //scan input arr for non-zero values
138138
final int fetched = coupIntArr[i];

src/main/java/com/yahoo/sketches/hll/CouponList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ HllSketchImpl couponUpdate(final int coupon) {
108108
couponCount++;
109109
if (couponCount >= len) { //array full
110110
if (lgConfigK < 8) {
111-
return promoteHeapListOrSetToHll(this);//oooFlag = false
111+
return promoteHeapListOrSetToHll(this); //oooFlag = false
112112
}
113113
return promoteHeapListToSet(this); //oooFlag = true
114114
}

src/main/java/com/yahoo/sketches/hll/CubicInterpolation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class CubicInterpolation {
1616
* @param x x
1717
* @return cubic interpolation
1818
*/
19+
//Used by AbstractCoupons
1920
//In C: again-two-registers cubic_interpolate_using_table L1377
2021
static double usingXAndYTables(final double[] xArr, final double[] yArr,
2122
final double x) {
@@ -56,6 +57,7 @@ private static double interpolateUsingXAndYTables(final double[] xArr, final dou
5657
* @return cubic interpolation
5758
*/
5859
//In C: again-two-registers cubic_interpolate_with_x_arr_and_y_stride L1411
60+
// Used by HllEstimators
5961
static double usingXArrAndYStride(
6062
final double[] xArr, final double yStride, final double x) {
6163
final int xArrLen = xArr.length;

src/main/java/com/yahoo/sketches/hll/Hll6Array.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,6 @@ Hll6Array copy() {
5151
return new Hll6Array(this);
5252
}
5353

54-
@Override
55-
HllSketchImpl couponUpdate(final int coupon) {
56-
final int configKmask = (1 << getLgConfigK()) - 1;
57-
final int slotNo = HllUtil.getLow26(coupon) & configKmask;
58-
final int newVal = HllUtil.getValue(coupon);
59-
assert newVal > 0;
60-
61-
final int curVal = getSlot(slotNo);
62-
if (newVal > curVal) {
63-
putSlot(slotNo, newVal);
64-
hipAndKxQIncrementalUpdate(this, curVal, newVal);
65-
if (curVal == 0) {
66-
decNumAtCurMin(); //overloaded as num zeros
67-
assert getNumAtCurMin() >= 0;
68-
}
69-
}
70-
return this;
71-
}
72-
7354
@Override
7455
PairIterator getIterator() {
7556
return new HeapHll6Iterator(1 << lgConfigK);

src/main/java/com/yahoo/sketches/hll/Hll8Array.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,6 @@ Hll8Array copy() {
4848
return new Hll8Array(this);
4949
}
5050

51-
@Override
52-
HllSketchImpl couponUpdate(final int coupon) {
53-
final int configKmask = (1 << getLgConfigK()) - 1;
54-
final int slotNo = HllUtil.getLow26(coupon) & configKmask;
55-
final int newVal = HllUtil.getValue(coupon);
56-
assert newVal > 0;
57-
58-
final int curVal = getSlot(slotNo);
59-
if (newVal > curVal) {
60-
putSlot(slotNo, newVal);
61-
hipAndKxQIncrementalUpdate(this, curVal, newVal);
62-
if (curVal == 0) {
63-
decNumAtCurMin(); //overloaded as num zeros
64-
assert getNumAtCurMin() >= 0;
65-
}
66-
}
67-
return this;
68-
}
69-
7051
@Override
7152
PairIterator getIterator() {
7253
return new HeapHll8Iterator(1 << lgConfigK);

src/main/java/com/yahoo/sketches/hll/HllArray.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ void addToHipAccum(final double delta) {
7878
hipAccum += delta;
7979
}
8080

81+
@Override //used by HLL6 and HLL8, overridden by HLL4
82+
HllSketchImpl couponUpdate(final int coupon) {
83+
final int configKmask = (1 << getLgConfigK()) - 1;
84+
final int slotNo = HllUtil.getLow26(coupon) & configKmask;
85+
final int newVal = HllUtil.getValue(coupon);
86+
assert newVal > 0;
87+
88+
final int curVal = getSlot(slotNo);
89+
if (newVal > curVal) {
90+
putSlot(slotNo, newVal);
91+
hipAndKxQIncrementalUpdate(this, curVal, newVal);
92+
if (curVal == 0) {
93+
decNumAtCurMin(); //overloaded as num zeros
94+
assert getNumAtCurMin() >= 0;
95+
}
96+
}
97+
return this;
98+
}
99+
81100
@Override
82101
void decNumAtCurMin() {
83102
numAtCurMin--;

src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import com.yahoo.memory.Memory;
1414
import com.yahoo.memory.WritableMemory;
15-
1615
import com.yahoo.sketches.Family;
1716
import com.yahoo.sketches.SketchesArgumentException;
1817

@@ -561,7 +560,7 @@ public void putMemory(final WritableMemory dstMem) {
561560
* performance at the cost of slightly increased serialization time.
562561
*/
563562
public void putMemory(final WritableMemory dstMem, final boolean compact) {
564-
if (isDirect() && isCompact() == compact) {
563+
if (isDirect() && (isCompact() == compact)) {
565564
final Memory srcMem = getMemory();
566565
srcMem.copyTo(0, dstMem, 0, getStorageBytes());
567566
} else {

0 commit comments

Comments
 (0)