Skip to content

Commit

Permalink
Rename MutableLong accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed May 28, 2024
1 parent 92cad0e commit 60a0ba2
Show file tree
Hide file tree
Showing 51 changed files with 402 additions and 405 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,24 @@ public RowSet makeRowSet() {
RowSetUtils.forAllInvertedLongRanges(rowSet, nullsForCol, (first, last) -> {
if (first > 0) {
// Advance to (first - 1)
keysIterator.getNextRowSequenceWithLength(first - 1 - position.longValue());
keysIterator.getNextRowSequenceWithLength(first - 1 - position.get());
build.addKey(keysIterator.peekNextKey());
// Advance to first
keysIterator.getNextRowSequenceWithLength(1);
build.addKey(keysIterator.peekNextKey());

position.setValue(first);
position.set(first);
}

if (last < indexSize - 1) {
// Advance to last
keysIterator.getNextRowSequenceWithLength(last - position.longValue());
keysIterator.getNextRowSequenceWithLength(last - position.get());
build.addKey(keysIterator.peekNextKey());
// Advance to (last + 1)
keysIterator.getNextRowSequenceWithLength(1);
build.addKey(keysIterator.peekNextKey());

position.setValue(last + 1);
position.set(last + 1);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public Long uniqueIdPrev(long index) {
@Override
public void loadData(MutableLong data, long index, boolean usePrev) {
final ColumnSource<Long> columnSource = table().getColumnSource("Value", long.class);
data.setValue(usePrev ? columnSource.getPrevLong(index) : columnSource.getLong(index));
data.set(usePrev ? columnSource.getPrevLong(index) : columnSource.getLong(index));
}
},
nKeys);
Expand Down
6 changes: 3 additions & 3 deletions Util/src/main/java/io/deephaven/util/mutable/MutableLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public MutableLong(final long value) {
this.value = value;
}

public long longValue() {
public long get() {
return value;
}

public void setValue(long value) {
public void set(long value) {
this.value = value;
}

Expand All @@ -40,7 +40,7 @@ public long addAndGet(long addend) {
}

public long getAndAdd(long addend) {
long old = longValue();
long old = get();
value += addend;
return old;
}
Expand Down
22 changes: 11 additions & 11 deletions Util/src/test/java/io/deephaven/util/mutable/MutableLongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,73 @@ public class MutableLongTest {

@Test
public void longValue() {
assertEquals(123, new MutableLong(123).longValue());
assertEquals(123, new MutableLong(123).get());
}

@Test
public void setValue() {
MutableLong v = new MutableLong(321);
v.setValue(999);
assertEquals(999, v.longValue());
v.set(999);
assertEquals(999, v.get());
}

@Test
public void add() {
MutableLong v = new MutableLong(1000);
v.add(10);
assertEquals(1010, v.longValue());
assertEquals(1010, v.get());
}

@Test
public void addAndGet() {
MutableLong v = new MutableLong(1000);
long result = v.addAndGet(10);
assertEquals(1010, result);
assertEquals(1010, v.longValue());
assertEquals(1010, v.get());
}

@Test
public void getAndAdd() {
MutableLong v = new MutableLong(1000);
long result = v.getAndAdd(10);
assertEquals(1000, result);
assertEquals(1010, v.longValue());
assertEquals(1010, v.get());
}

@Test
public void getAndIncrement() {
MutableLong v = new MutableLong(1000);
long result = v.getAndIncrement();
assertEquals(1000, result);
assertEquals(1001, v.longValue());
assertEquals(1001, v.get());
}

@Test
public void increment() {
MutableLong v = new MutableLong(1000);
v.increment();
assertEquals(1001, v.longValue());
assertEquals(1001, v.get());
}

@Test
public void decrement() {
MutableLong v = new MutableLong(1000);
v.decrement();
assertEquals(999, v.longValue());
assertEquals(999, v.get());
}

@Test
public void incrementAndGet() {
MutableLong v = new MutableLong(1000);
long result = v.incrementAndGet();
assertEquals(1001, result);
assertEquals(1001, v.longValue());
assertEquals(1001, v.get());
}

@Test
public void subtract() {
MutableLong v = new MutableLong(1000);
v.subtract(10);
assertEquals(990, v.longValue());
assertEquals(990, v.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ static void updateCrc32(final CRC32 crc32, final long v) {
long fixedCost() {
final MutableLong accum = new MutableLong(0);
fixedCostOk.forEachRowKey((final long v) -> {
accum.setValue(accum.longValue() ^ v);
accum.set(accum.get() ^ v);
return true;
});
indicesChunk.setSize(chunkSz);
fixedCostOk.fillRowKeyChunk(indicesChunk);
final int sz = indicesChunk.size();
for (int i = 0; i < sz; ++i) {
accum.setValue(accum.longValue() ^ indicesChunk.get(i));
accum.set(accum.get() ^ indicesChunk.get(i));
}
return accum.longValue();
return accum.get();
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ public static RowSet readExternalCompressedDelta(@NotNull final DataInput in) th

final MutableLong pending = new MutableLong(-1);
final LongConsumer consume = v -> {
final long s = pending.longValue();
final long s = pending.get();
if (s == -1) {
pending.setValue(v);
pending.set(v);
} else if (v < 0) {
builder.appendRange(s, -v);
pending.setValue(-1);
pending.set(-1);
} else {
builder.appendKey(s);
pending.setValue(v);
pending.set(v);
}
};

Expand Down Expand Up @@ -204,8 +204,8 @@ public static RowSet readExternalCompressedDelta(@NotNull final DataInput in) th
}
} while (true);

if (pending.longValue() >= 0) {
builder.appendKey(pending.longValue());
if (pending.get() >= 0) {
builder.appendKey(pending.get());
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,23 @@ public static void forAllInvertedLongRanges(final RowSet sourceRowSet, final Row
final RowSequence.Iterator sourceProbe = sourceRowSet.getRowSequenceIterator();
final MutableLong sourceOffset = new MutableLong();
destRowSet.forAllRowKeyRanges((start, end) -> {
final long sourceStart = sourceOffset.longValue() + sourceProbe.advanceAndGetPositionDistance(start);
final long sourceStart = sourceOffset.get() + sourceProbe.advanceAndGetPositionDistance(start);
final long sourceEnd = sourceStart + sourceProbe.advanceAndGetPositionDistance(end);
if (!hasPending.booleanValue()) {
pendingStart.setValue(sourceStart);
pendingEnd.setValue(sourceEnd);
pendingStart.set(sourceStart);
pendingEnd.set(sourceEnd);
hasPending.setValue(true);
} else if (pendingEnd.longValue() + 1 == sourceStart) {
pendingEnd.setValue(sourceEnd);
} else if (pendingEnd.get() + 1 == sourceStart) {
pendingEnd.set(sourceEnd);
} else {
lrc.accept(pendingStart.longValue(), pendingEnd.longValue());
pendingStart.setValue(sourceStart);
pendingEnd.setValue(sourceEnd);
lrc.accept(pendingStart.get(), pendingEnd.get());
pendingStart.set(sourceStart);
pendingEnd.set(sourceEnd);
}
sourceOffset.setValue(sourceEnd);
sourceOffset.set(sourceEnd);
});
if (hasPending.booleanValue()) {
lrc.accept(pendingStart.longValue(), pendingEnd.longValue());
lrc.accept(pendingStart.get(), pendingEnd.get());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ public final WritableRowSet subSetForPositions(RowSequence positions) {
final RowSequence.Iterator iter = getRowSequenceIterator();
final RowSetBuilderSequential builder = RowSetFactory.builderSequential();
positions.forEachRowKeyRange((start, end) -> {
if (currentOffset.longValue() < start) {
if (currentOffset.get() < start) {
// skip items until the beginning of this range
iter.getNextRowSequenceWithLength(start - currentOffset.longValue());
currentOffset.setValue(start);
iter.getNextRowSequenceWithLength(start - currentOffset.get());
currentOffset.set(start);
}
if (!iter.hasMore()) {
return false;
}
iter.getNextRowSequenceWithLength(end + 1 - currentOffset.longValue())
iter.getNextRowSequenceWithLength(end + 1 - currentOffset.get())
.forAllRowKeyRanges(builder::appendRange);
currentOffset.setValue(end + 1);
currentOffset.set(end + 1);
return iter.hasMore();
});
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ private int getIndexForRankWithAcc(final int fromIndex, final long pos) {
private int getIndexForRankNoAcc(final int fromIndex, final long pos, final MutableLong prevCardMu) {
int i = fromIndex;
final long posp1 = pos + 1;
long card = (prevCardMu == null) ? 0 : prevCardMu.longValue();
long card = (prevCardMu == null) ? 0 : prevCardMu.get();
long prevCard;
while (true) {
prevCard = card;
Expand All @@ -2146,13 +2146,13 @@ private int getIndexForRankNoAcc(final int fromIndex, final long pos, final Muta
++i;
if (i == size) {
if (prevCardMu != null) {
prevCardMu.setValue(prevCard);
prevCardMu.set(prevCard);
}
return size;
}
}
if (prevCardMu != null) {
prevCardMu.setValue(prevCard);
prevCardMu.set(prevCard);
}
return i;
}
Expand Down Expand Up @@ -2183,7 +2183,7 @@ public long get(final long pos) {
if (rankIndex == size) {
return -1;
}
prevCard = prevCardMu.longValue();
prevCard = prevCardMu.get();
}
return get(rankIndex, pos - prevCard);
}
Expand Down Expand Up @@ -2216,7 +2216,7 @@ public void getKeysForPositions(final PrimitiveIterator.OfLong inputPositions, f
}
return;
}
prevCardinality = prevCardMu.longValue();
prevCardinality = prevCardMu.get();
}
final long key = get(fromIndex, pos - prevCardinality);
outputKeys.accept(key);
Expand Down Expand Up @@ -3833,9 +3833,9 @@ boolean forEachLongInSpanWithOffsetAndMaxCount(final int i, final long offset, L
return false;
}
n.increment();
return n.longValue() < maxCount;
return n.get() < maxCount;
});
return n.longValue() >= maxCount; // The only way we get to maxCount is if lc never returns false above.
return n.get() >= maxCount; // The only way we get to maxCount is if lc never returns false above.
}

boolean forEachLongInSpanWithOffset(final int i, final long offset, LongAbortableConsumer lc) {
Expand Down Expand Up @@ -3870,9 +3870,9 @@ boolean forEachLongInSpanWithMaxCount(final int i, LongAbortableConsumer lc, fin
return false;
}
n.increment();
return n.longValue() < maxCount;
return n.get() < maxCount;
});
return n.longValue() >= maxCount; // The only way we get to maxCount is if lc never returns false above.
return n.get() >= maxCount; // The only way we get to maxCount is if lc never returns false above.
}

boolean forEachLongInSpan(final int i, LongAbortableConsumer lc) {
Expand Down Expand Up @@ -4097,7 +4097,7 @@ protected T subrangeByPosInternal(final long firstPos, final long lastPos) {
if (startIdx == size) {
return null;
}
cardBeforeStart = prevCardMu.longValue();
cardBeforeStart = prevCardMu.get();
}
final int endIdx;
final long endOffset;
Expand All @@ -4112,7 +4112,7 @@ protected T subrangeByPosInternal(final long firstPos, final long lastPos) {
endOffset = getSpanCardinalityAtIndex(endIdx) - 1;
} else {
endIdx = ansIdx;
final long cardBeforeEnd = prevCardMu.longValue();
final long cardBeforeEnd = prevCardMu.get();
endOffset = effectiveLastPos - cardBeforeEnd;
}
}
Expand Down Expand Up @@ -4573,7 +4573,7 @@ public RowSequence getRowSequenceByPosition(final long startPositionInclusive, f
if (startIdx == size) {
return RowSequenceFactory.EMPTY;
}
cardBeforeStart = prevCardMu.longValue();
cardBeforeStart = prevCardMu.get();
}
final int endIdx;
final long endOffset;
Expand All @@ -4584,7 +4584,7 @@ public RowSequence getRowSequenceByPosition(final long startPositionInclusive, f
endOffset = endPositionInclusive - cardBeforeEnd;
} else {
final int ansIdx = getIndexForRankNoAcc(startIdx, endPositionInclusive, prevCardMu);
cardBeforeEnd = prevCardMu.longValue();
cardBeforeEnd = prevCardMu.get();
if (ansIdx == size) {
endIdx = size - 1;
endOffset = getSpanCardinalityAtIndex(endIdx) - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,13 @@ private int endIndex(
int i = fromIndex;
while (true) {
if (i == arr.size - 1) {
prevCardMu.setValue(prevCard);
prevCardMu.set(prevCard);
return i;
}
final long spanCard = arr.getSpanCardinalityAtIndex(i);
final long card = prevCard + spanCard;
if (cardTarget <= card) {
prevCardMu.setValue(prevCard);
prevCardMu.set(prevCard);
return i;
}
++i;
Expand Down Expand Up @@ -427,7 +427,7 @@ private long nextRowSequenceWithLength(final long desiredNumberOfKeys) {
currEndOffset = currStartOffset + boundedNumberOfKeys - 1;
} else {
currCardBeforeEndIdx =
(prevCardMu != null) ? prevCardMu.longValue() : arr.cardinalityBeforeWithAcc(currEndIdx);
(prevCardMu != null) ? prevCardMu.get() : arr.cardinalityBeforeWithAcc(currEndIdx);
final long spanCardAtStartIdx = arr.getSpanCardinalityAtIndexMaybeAcc(currStartIdx);
final long cardAtStartIdx = currCardBeforeStartIdx + spanCardAtStartIdx;
final long firstSpanCount = spanCardAtStartIdx - currStartOffset;
Expand Down Expand Up @@ -467,7 +467,7 @@ private long nextRowSequenceWithLength(final long desiredNumberOfKeys) {
currEndIdx =
endIndex(currStartIdx, currStartOffset, currCardBeforeStartIdx, boundedNumberOfKeys, prevCardMu);
currCardBeforeEndIdx =
(prevCardMu != null) ? prevCardMu.longValue() : arr.cardinalityBeforeWithAcc(currEndIdx);
(prevCardMu != null) ? prevCardMu.get() : arr.cardinalityBeforeWithAcc(currEndIdx);
final long keysBeforeLastSpan =
keysAvailableInStartSpan + currCardBeforeEndIdx - currCardBeforeStartIdx
- currStartIdxSpanCardinality;
Expand Down
Loading

0 comments on commit 60a0ba2

Please sign in to comment.