Skip to content
Permalink
Browse files
Interim 9
  • Loading branch information
leerho committed Mar 9, 2022
1 parent 5610b3a commit b33196eae6d59b007dba428bdfc20730d10de12a
Showing 7 changed files with 452 additions and 75 deletions.
@@ -34,6 +34,7 @@ public class KllDirectDoublesSketch extends KllDirectSketch {

@Override
public byte[] toByteArray() {

return null;
}

@@ -47,36 +48,5 @@ public byte[] toUpdatableByteArray() {
return null;
}

@Override
int[] getLevelsArray() {
return null;
}

@Override
int getLevelsArrayAt(final int index) {
return 0;
}


@Override
void setLevelsArray(final int[] levels) {

}

@Override
void setLevelsArrayAt(final int index, final int value) {

}

@Override
void setLevelsArrayAtMinusEq(final int index, final int minusEq) {

}

@Override
void setLevelsArrayAtPlusEq(final int index, final int plusEq) {

}

}

@@ -85,9 +85,45 @@ int getDyMinK() {

@Override
int[] getLevelsArray() {
final int lengthInts = getLevelsArrLengthInts();
final int[] levelsArr = new int[lengthInts];
wmem.getIntArray(dataStartBytes, levelsArr, 0, lengthInts);
final int memLengthInts;
final int outLengthInts;
final int[] levelsArr;
final int k = getK();
switch (layout) {
case FLOAT_EMPTY_COMPACT:
case DOUBLE_EMPTY_COMPACT: {
memLengthInts = 0;
outLengthInts = 2;
levelsArr = new int[] {k, k};
break;
}
case FLOAT_SINGLE_COMPACT:
case DOUBLE_SINGLE_COMPACT: {
memLengthInts = 0;
outLengthInts = 2;
levelsArr = new int[] {k - 1, k};
break;
}
case FLOAT_FULL_COMPACT:
case DOUBLE_FULL_COMPACT: {
memLengthInts = getNumLevels();
outLengthInts = getNumLevels() + 1;
levelsArr = new int[outLengthInts];
wmem.getIntArray(dataStartBytes, levelsArr, 0, memLengthInts);
final int itemCapacity = KllHelper.computeTotalItemCapacity(getK(), M, getNumLevels());
levelsArr[getNumLevels()] = itemCapacity;
break;
}
case FLOAT_UPDATABLE:
case DOUBLE_UPDATABLE: {
memLengthInts = getNumLevels() + 1;
outLengthInts = memLengthInts;
levelsArr = new int[outLengthInts];
wmem.getIntArray(dataStartBytes, levelsArr, 0, outLengthInts);
break;
}
default: return null;
}
return levelsArr;
}

@@ -180,22 +216,25 @@ int getItemsArrLengthItems() {
return getLevelsArrayAt(getNumLevels());
}

/**
* For determining the actual length of the array as stored in Memory
* @return the actual length of the array as stored in Memory
*/
int getLevelsArrLengthInts() {
final int lengthInts;
final int memLengthInts;

switch (layout) {
case FLOAT_EMPTY_COMPACT:
case FLOAT_SINGLE_COMPACT:
case DOUBLE_EMPTY_COMPACT:
case DOUBLE_SINGLE_COMPACT: { return 0; }

case FLOAT_FULL_COMPACT: { lengthInts = getNumLevels(); break; }
case DOUBLE_FULL_COMPACT: { lengthInts = getNumLevels(); break; }
case FLOAT_UPDATABLE: { lengthInts = getNumLevels() + 1; break; }
case DOUBLE_UPDATABLE: { lengthInts = getNumLevels() + 1; break; }
default: return 0;
case FLOAT_SINGLE_COMPACT:
case DOUBLE_SINGLE_COMPACT: { memLengthInts = 0; break; }
case FLOAT_FULL_COMPACT:
case DOUBLE_FULL_COMPACT: { memLengthInts = getNumLevels(); break; }
case FLOAT_UPDATABLE:
case DOUBLE_UPDATABLE: { memLengthInts = getNumLevels() + 1; break; }
default: return 0; //can't get here
}
return lengthInts;
return memLengthInts;
}


@@ -455,8 +455,8 @@ public byte[] toUpdatableByteArray() {
wmem.putByte(PREAMBLE_INTS_BYTE_ADR, (byte) PREAMBLE_INTS_DOUBLE);
wmem.putByte(SER_VER_BYTE_ADR, SERIAL_VERSION_EMPTY_FULL);
wmem.putByte(FAMILY_BYTE_ADR, (byte) Family.KLL.getID());
final byte flags = (byte)
((isLevelZeroSorted() ? LEVEL_ZERO_SORTED_BIT_MASK : 0)
final byte flags = (byte) (
(isLevelZeroSorted() ? LEVEL_ZERO_SORTED_BIT_MASK : 0)
| DOUBLES_SKETCH_BIT_MASK
| UPDATABLE_BIT_MASK);
wmem.putByte(FLAGS_BYTE_ADR, flags);
@@ -455,8 +455,8 @@ public byte[] toUpdatableByteArray() {
wmem.putByte(PREAMBLE_INTS_BYTE_ADR, (byte) PREAMBLE_INTS_FLOAT);
wmem.putByte(SER_VER_BYTE_ADR, SERIAL_VERSION_EMPTY_FULL);
wmem.putByte(FAMILY_BYTE_ADR, (byte) Family.KLL.getID());
final byte flags = (byte)
((isLevelZeroSorted() ? LEVEL_ZERO_SORTED_BIT_MASK : 0)
final byte flags = (byte) (
(isLevelZeroSorted() ? LEVEL_ZERO_SORTED_BIT_MASK : 0)
| UPDATABLE_BIT_MASK);
// (leave blank)
wmem.putByte(FLAGS_BYTE_ADR, flags);
@@ -471,9 +471,9 @@ public byte[] toUpdatableByteArray() {
final int len = getLevelsArray().length;
wmem.putIntArray(offset, getLevelsArray(), 0, len);
offset += len * Integer.BYTES;
wmem.putDouble(offset, minValue_);
wmem.putFloat(offset, minValue_);
offset += Float.BYTES;
wmem.putDouble(offset, maxValue_);
wmem.putFloat(offset, maxValue_);
offset += Float.BYTES;
wmem.putFloatArray(offset, items_, getLevelsArrayAt(0), getNumRetained());
return bytes;

0 comments on commit b33196e

Please sign in to comment.