Search in sources :

Example 6 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueComparator method compareToReference.

@Override
public int compareToReference(TypeComparator<ShortValue> referencedComparator) {
    ShortValue otherRef = ((ShortValueComparator) referencedComparator).reference;
    int comp = otherRef.compareTo(reference);
    return ascendingComparison ? comp : -comp;
}
Also used : ShortValue(org.apache.flink.types.ShortValue)

Example 7 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class BoxedWrapperRowData method setShort.

@Override
public void setShort(int pos, short value) {
    ShortValue wrap;
    if ((wrap = (ShortValue) fields[pos]) == null) {
        wrap = new ShortValue();
        fields[pos] = wrap;
    }
    wrap.setValue(value);
}
Also used : ShortValue(org.apache.flink.types.ShortValue)

Example 8 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueArrayComparatorTest method getSortedTestData.

@Override
protected ShortValueArray[] getSortedTestData() {
    ShortValueArray lva0 = new ShortValueArray();
    ShortValueArray lva1 = new ShortValueArray();
    lva1.add(new ShortValue((short) 5));
    ShortValueArray lva2 = new ShortValueArray();
    lva2.add(new ShortValue((short) 5));
    lva2.add(new ShortValue((short) 10));
    return new ShortValueArray[] { lva0, lva1 };
}
Also used : ShortValue(org.apache.flink.types.ShortValue)

Example 9 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueArrayTest method testBoundedArray.

@Test
public void testBoundedArray() {
    int count = ShortValueArray.DEFAULT_CAPACITY_IN_BYTES / ShortValueArray.ELEMENT_LENGTH_IN_BYTES;
    ValueArray<ShortValue> lva = new ShortValueArray(ShortValueArray.DEFAULT_CAPACITY_IN_BYTES);
    // fill the array
    for (int i = 0; i < count; i++) {
        assertFalse(lva.isFull());
        assertEquals(i, lva.size());
        assertTrue(lva.add(new ShortValue((short) i)));
        assertEquals(i + 1, lva.size());
    }
    // array is now full
    assertTrue(lva.isFull());
    assertEquals(count, lva.size());
    // verify the array values
    int idx = 0;
    for (ShortValue lv : lva) {
        assertEquals((short) idx++, lv.getValue());
    }
    // add element past end of array
    assertFalse(lva.add(new ShortValue((short) count)));
    assertFalse(lva.addAll(lva));
    // test copy
    assertEquals(lva, lva.copy());
    // test copyTo
    ShortValueArray lvaTo = new ShortValueArray();
    lva.copyTo(lvaTo);
    assertEquals(lva, lvaTo);
    // test clear
    lva.clear();
    assertEquals(0, lva.size());
}
Also used : ShortValue(org.apache.flink.types.ShortValue) Test(org.junit.Test)

Example 10 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class GraphKeyTypeTransformTest method testToShortValue.

// ShortValue
@Test
public void testToShortValue() throws Exception {
    TranslateFunction<LongValue, ShortValue> translator = new LongValueToUnsignedShortValue();
    Assert.assertEquals(new ShortValue((short) 0), translator.translate(new LongValue(0L), shortValue));
    Assert.assertEquals(new ShortValue(Short.MIN_VALUE), translator.translate(new LongValue((long) Short.MAX_VALUE + 1), shortValue));
    Assert.assertEquals(new ShortValue((short) -1), translator.translate(new LongValue(LongValueToUnsignedShortValue.MAX_VERTEX_COUNT - 1), shortValue));
}
Also used : LongValueToUnsignedShortValue(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToUnsignedShortValue) LongValueToUnsignedShortValue(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToUnsignedShortValue) ShortValue(org.apache.flink.types.ShortValue) LongValue(org.apache.flink.types.LongValue) Test(org.junit.Test)

Aggregations

ShortValue (org.apache.flink.types.ShortValue)10 Test (org.junit.Test)4 Random (java.util.Random)3 LongValueToUnsignedShortValue (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToUnsignedShortValue)2 DoubleToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleToLongValueWithProperHashCode)1 DoubleValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleValueToLongValueWithProperHashCode)1 LongValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToLongValueWithProperHashCode)1 StringToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringToLongValueWithProperHashCode)1 StringValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringValueToLongValueWithProperHashCode)1 UnsignedByteToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteToLongValueWithProperHashCode)1 UnsignedByteValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteValueToLongValueWithProperHashCode)1 UnsignedFloatToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatToLongValueWithProperHashCode)1 UnsignedFloatValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatValueToLongValueWithProperHashCode)1 UnsignedIntToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedIntToLongValueWithProperHashCode)1 UnsignedShortToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortToLongValueWithProperHashCode)1 UnsignedShortValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortValueToLongValueWithProperHashCode)1 LongValue (org.apache.flink.types.LongValue)1