Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Oct 1, 2023
1 parent b27bafa commit ae9138a
Show file tree
Hide file tree
Showing 58 changed files with 802 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class BooleanArrayVector extends AbstractVector implements BooleanV

private final boolean[] values;

private final BooleanBlock block;

public BooleanArrayVector(boolean[] values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public BooleanArrayVector(boolean[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BooleanVectorBlock(this);
}

@Override
public BooleanBlock asBlock() {
return new BooleanVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class BooleanBigArrayVector extends AbstractVector implements Boole

private final BitArray values;

private final BooleanBlock block;

public BooleanBigArrayVector(BitArray values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public BooleanBigArrayVector(BitArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BooleanVectorBlock(this);
}

@Override
public BooleanBlock asBlock() {
return new BooleanVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ public BooleanBlock build() {
finish();
BooleanBlock block;
if (hasNonNullValue && positionCount == 1 && valueCount == 1) {
block = new ConstantBooleanVector(values[0], 1, blockFactory).asBlock();
block = blockFactory.newConstantBooleanBlockWith(values[0], 1, estimatedBytes);
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
if (isDense() && singleValued()) {
block = new BooleanArrayVector(values, positionCount, blockFactory).asBlock();
block = blockFactory.newBooleanArrayVector(values, positionCount, estimatedBytes).asBlock();
} else {
block = new BooleanArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, blockFactory);
block = blockFactory.newBooleanArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, estimatedBytes);
}
}
/*
Expand All @@ -202,7 +202,7 @@ public BooleanBlock build() {
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(block.ramBytesUsed() - estimatedBytes, false);
// blockFactory.adjustBreaker(block.ramBytesUsed() - estimatedBytes, false);
built();
return block;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public BooleanVector build() {
finish();
BooleanVector vector;
if (valueCount == 1) {
vector = new ConstantBooleanVector(values[0], 1, blockFactory);
vector = blockFactory.newConstantBooleanBlockWith(values[0], 1, estimatedBytes).asVector();
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
vector = new BooleanArrayVector(values, valueCount, blockFactory);
vector = blockFactory.newBooleanArrayVector(values, valueCount, estimatedBytes);
}
/*
* Update the breaker with the actual bytes used.
Expand All @@ -67,7 +67,7 @@ public BooleanVector build() {
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(vector.ramBytesUsed() - estimatedBytes, false);
// blockFactory.adjustBreaker(vector.ramBytesUsed() - estimatedBytes, false);
built();
return vector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
final class BooleanVectorFixedBuilder implements BooleanVector.FixedBuilder {
private final BlockFactory blockFactory;
private final boolean[] values;
private final long preAdjustedBytes;
/**
* The next value to write into. {@code -1} means the vector has already
* been built.
*/
private int nextIndex;

BooleanVectorFixedBuilder(int size, BlockFactory blockFactory) {
blockFactory.adjustBreaker(ramBytesUsed(size), false);
preAdjustedBytes = ramBytesUsed(size);
blockFactory.adjustBreaker(preAdjustedBytes, false);
this.blockFactory = blockFactory;
this.values = new boolean[size];
}
Expand Down Expand Up @@ -54,16 +56,20 @@ public BooleanVector build() {
}
nextIndex = -1;
if (values.length == 1) {
return new ConstantBooleanVector(values[0], 1, blockFactory);
return blockFactory.newConstantBooleanBlockWith(values[0], 1, preAdjustedBytes).asVector();
}
return new BooleanArrayVector(values, values.length, blockFactory);
return blockFactory.newBooleanArrayVector(values, values.length, preAdjustedBytes);
}

@Override
public void close() {
if (nextIndex >= 0) {
// If nextIndex < 0 we've already built the vector
blockFactory.adjustBreaker(-ramBytesUsed(values.length), false);
blockFactory.adjustBreaker(-preAdjustedBytes, false);
}
}

boolean isReleased() {
return nextIndex < 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ public final class BytesRefArrayVector extends AbstractVector implements BytesRe

private final BytesRefArray values;

private final BytesRefBlock block;

public BytesRefArrayVector(BytesRefArray values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public BytesRefArrayVector(BytesRefArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BytesRefVectorBlock(this);
}

@Override
public BytesRefBlock asBlock() {
return new BytesRefVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantBooleanVector extends AbstractVector implements Boole

private final boolean value;

private final BooleanBlock block;

public ConstantBooleanVector(boolean value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantBooleanVector(boolean value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new BooleanVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public boolean getBoolean(int position) {

@Override
public BooleanBlock asBlock() {
return new BooleanVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ public final class ConstantBytesRefVector extends AbstractVector implements Byte
.shallowSizeOfInstance(BytesRef.class);
private final BytesRef value;

private final BytesRefBlock block;

public ConstantBytesRefVector(BytesRef value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantBytesRefVector(BytesRef value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new BytesRefVectorBlock(this);
}

@Override
Expand All @@ -36,7 +39,7 @@ public BytesRef getBytesRef(int position, BytesRef ignore) {

@Override
public BytesRefBlock asBlock() {
return new BytesRefVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantDoubleVector extends AbstractVector implements Double

private final double value;

private final DoubleBlock block;

public ConstantDoubleVector(double value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantDoubleVector(double value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new DoubleVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public double getDouble(int position) {

@Override
public DoubleBlock asBlock() {
return new DoubleVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantIntVector extends AbstractVector implements IntVector

private final int value;

private final IntBlock block;

public ConstantIntVector(int value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantIntVector(int value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new IntVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public int getInt(int position) {

@Override
public IntBlock asBlock() {
return new IntVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantLongVector extends AbstractVector implements LongVect

private final long value;

private final LongBlock block;

public ConstantLongVector(long value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantLongVector(long value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new LongVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public long getLong(int position) {

@Override
public LongBlock asBlock() {
return new LongVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class DoubleArrayVector extends AbstractVector implements DoubleVec

private final double[] values;

private final DoubleBlock block;

public DoubleArrayVector(double[] values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public DoubleArrayVector(double[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new DoubleVectorBlock(this);
}

@Override
public DoubleBlock asBlock() {
return new DoubleVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class DoubleBigArrayVector extends AbstractVector implements Double

private final DoubleArray values;

private final DoubleBlock block;

public DoubleBigArrayVector(DoubleArray values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public DoubleBigArrayVector(DoubleArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new DoubleVectorBlock(this);
}

@Override
public DoubleBlock asBlock() {
return new DoubleVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ public DoubleBlock build() {
finish();
DoubleBlock block;
if (hasNonNullValue && positionCount == 1 && valueCount == 1) {
block = new ConstantDoubleVector(values[0], 1, blockFactory).asBlock();
block = blockFactory.newConstantDoubleBlockWith(values[0], 1, estimatedBytes);
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
if (isDense() && singleValued()) {
block = new DoubleArrayVector(values, positionCount, blockFactory).asBlock();
block = blockFactory.newDoubleArrayVector(values, positionCount, estimatedBytes).asBlock();
} else {
block = new DoubleArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, blockFactory);
block = blockFactory.newDoubleArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, estimatedBytes);
}
}
/*
Expand All @@ -202,7 +202,7 @@ public DoubleBlock build() {
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(block.ramBytesUsed() - estimatedBytes, false);
// blockFactory.adjustBreaker(block.ramBytesUsed() - estimatedBytes, false);
built();
return block;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public DoubleVector build() {
finish();
DoubleVector vector;
if (valueCount == 1) {
vector = new ConstantDoubleVector(values[0], 1, blockFactory);
vector = blockFactory.newConstantDoubleBlockWith(values[0], 1, estimatedBytes).asVector();
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
vector = new DoubleArrayVector(values, valueCount, blockFactory);
vector = blockFactory.newDoubleArrayVector(values, valueCount, estimatedBytes);
}
/*
* Update the breaker with the actual bytes used.
Expand All @@ -67,7 +67,7 @@ public DoubleVector build() {
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(vector.ramBytesUsed() - estimatedBytes, false);
// blockFactory.adjustBreaker(vector.ramBytesUsed() - estimatedBytes, false);
built();
return vector;
}
Expand Down
Loading

0 comments on commit ae9138a

Please sign in to comment.