Since we have 'Set' in our name, size() invokes Set.size(), which is
not we provide w.r.t. the number of distinct elements that are contained
in the set.
We are communicating how many ranges are stored, hence the method's name
is 'rangeSize()'.
Change-Id: Iaf9999db86fe03a8e753107638fc2e189b680677
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
out.writeBoolean(closed);
final int closedSize = closedTransactions.size();
out.writeBoolean(closed);
final int closedSize = closedTransactions.size();
- final int purgedSize = purgedTransactions.size();
+ final int purgedSize = purgedTransactions.rangeSize();
WritableObjects.writeLongs(out, closedSize, purgedSize);
closedTransactions.writeEntriesTo(out, closedSize);
purgedTransactions.writeRangesTo(out, purgedSize);
WritableObjects.writeLongs(out, closedSize, purgedSize);
closedTransactions.writeEntriesTo(out, closedSize);
purgedTransactions.writeRangesTo(out, purgedSize);
if (mutable.isEmpty()) {
return of();
}
if (mutable.isEmpty()) {
return of();
}
- if (mutable.size() <= ARRAY_MAX_ELEMENTS) {
+ if (mutable.rangeSize() <= ARRAY_MAX_ELEMENTS) {
return new ImmutableUnsignedLongSet(ImmutableSortedSet.copyOfSorted(mutable.trustedRanges()));
}
return new ImmutableUnsignedLongSet(new TreeSet<>(mutable.trustedRanges()));
return new ImmutableUnsignedLongSet(ImmutableSortedSet.copyOfSorted(mutable.trustedRanges()));
}
return new ImmutableUnsignedLongSet(new TreeSet<>(mutable.trustedRanges()));
@Override
public void writeTo(final DataOutput out) throws IOException {
@Override
public void writeTo(final DataOutput out) throws IOException {
+ out.writeInt(rangeSize());
writeRanges(out);
}
public void writeRangesTo(final @NonNull DataOutput out, final int size) throws IOException {
writeRanges(out);
}
public void writeRangesTo(final @NonNull DataOutput out, final int size) throws IOException {
- if (size != size()) {
- throw new IOException("Mismatched size: expected " + size() + ", got " + size);
+ final int rangeSize = rangeSize();
+ if (size != rangeSize) {
+ throw new IOException("Mismatched size: expected " + rangeSize + ", got " + size);
import com.google.common.annotations.Beta;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.annotations.Beta;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.Range;
import com.google.common.primitives.UnsignedLong;
import java.util.NavigableSet;
import java.util.TreeSet;
import com.google.common.primitives.UnsignedLong;
import java.util.NavigableSet;
import java.util.TreeSet;
return Entry.of(lowerBits, newUpper);
}
return Entry.of(lowerBits, newUpper);
}
+ // Provides compatibility with RangeSet<UnsignedLong> using [lower, upper + 1)
public ImmutableRangeSet<UnsignedLong> toRangeSet() {
public ImmutableRangeSet<UnsignedLong> toRangeSet() {
- return ImmutableRangeSet.copyOf(Collections2.transform(trustedRanges(), Entry::toUnsigned));
+ return ImmutableRangeSet.copyOf(Collections2.transform(trustedRanges(), entry -> Range.closedOpen(
+ UnsignedLong.fromLongBits(entry.lowerBits), UnsignedLong.fromLongBits(entry.upperBits + 1))));
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
-import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
import com.google.common.collect.RangeSet;
-import com.google.common.primitives.UnsignedLong;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@Beta
@VisibleForTesting
public static final class Entry implements Comparable<Entry>, Immutable {
@Beta
@VisibleForTesting
public static final class Entry implements Comparable<Entry>, Immutable {
- final long lowerBits;
- final long upperBits;
+ public final long lowerBits;
+ public final long upperBits;
private Entry(final long lowerBits, final long upperBits) {
this.lowerBits = lowerBits;
private Entry(final long lowerBits, final long upperBits) {
this.lowerBits = lowerBits;
return new Entry(lowerBits, upperBits);
}
return new Entry(lowerBits, upperBits);
}
- @VisibleForTesting
- public @NonNull UnsignedLong lower() {
- return UnsignedLong.fromLongBits(lowerBits);
- }
-
- @VisibleForTesting
- public @NonNull UnsignedLong upper() {
- return UnsignedLong.fromLongBits(upperBits);
- }
-
@NonNull Entry withLower(final long newLowerBits) {
return of(newLowerBits, upperBits);
}
@NonNull Entry withLower(final long newLowerBits) {
return of(newLowerBits, upperBits);
}
return of(lowerBits, newUpperBits);
}
return of(lowerBits, newUpperBits);
}
- // Provides compatibility with RangeSet<UnsignedLong> using [lower, upper + 1)
- @NonNull Range<UnsignedLong> toUnsigned() {
- return Range.closedOpen(UnsignedLong.fromLongBits(lowerBits), UnsignedLong.fromLongBits(upperBits + 1));
- }
-
// These two methods provide the same serialization format as the one we've used to serialize
// Range<UnsignedLong>
static @NonNull Entry readUnsigned(final DataInput in) throws IOException {
// These two methods provide the same serialization format as the one we've used to serialize
// Range<UnsignedLong>
static @NonNull Entry readUnsigned(final DataInput in) throws IOException {
return ranges.isEmpty();
}
return ranges.isEmpty();
}
- public final int size() {
+ public final int rangeSize() {