gpt4 book ai didi

com.netflix.hollow.core.memory.encoding.ZigZag类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 11:15:15 27 4
gpt4 key购买 nike

本文整理了Java中com.netflix.hollow.core.memory.encoding.ZigZag类的一些代码示例,展示了ZigZag类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZigZag类的具体详情如下:
包路径:com.netflix.hollow.core.memory.encoding.ZigZag
类名称:ZigZag

ZigZag介绍

[英]Zig-zag encoding. Used to encode FieldType#INT and FieldType#LONG because smaller absolute values can be encoded using fewer bits.
[中]Z字形编码。用于对FieldType#INT和FieldType#LONG进行编码,因为较小的绝对值可以使用较少的位进行编码。

代码示例

代码示例来源:origin: Netflix/hollow

return data.get(location) == 1;
case INT:
  return ZigZag.decodeInt(VarInt.readVInt(data, location));
case LONG:
  return ZigZag.decodeLong(VarInt.readVLong(data, location));
case DOUBLE:
  long longBits = data.readLongBits(location);

代码示例来源:origin: Netflix/hollow

public int readInt(int ordinal, int fieldIndex) {
  HollowObjectTypeDataElements currentData;
  long value;
  do {
    currentData = this.currentDataVolatile;
    value = readFixedLengthFieldValue(currentData, ordinal, fieldIndex);
  } while(readWasUnsafe(currentData));
  if(value == currentData.nullValueForField[fieldIndex])
    return Integer.MIN_VALUE;
  return ZigZag.decodeInt((int)value);
}

代码示例来源:origin: Netflix/hollow

public long readLong(int ordinal, int fieldIndex) {
  HollowObjectTypeDataElements currentData;
  long value;
  do {
    currentData = this.currentDataVolatile;
    long bitOffset = fieldOffset(currentData, ordinal, fieldIndex);
    int numBitsForField = currentData.bitsPerField[fieldIndex];
    value = currentData.fixedLengthData.getLargeElementValue(bitOffset, numBitsForField);
  } while(readWasUnsafe(currentData));
  if(value == currentData.nullValueForField[fieldIndex])
    return Long.MIN_VALUE;
  return ZigZag.decodeLong(value);
}

代码示例来源:origin: Netflix/hollow

public void setLong(String fieldName, long value) {
  if(value == Long.MIN_VALUE) {
    setNull(fieldName);
  } else {
    int fieldIndex = getSchema().getPosition(fieldName);
    validateFieldType(fieldIndex, fieldName, FieldType.LONG);
    ByteDataBuffer buf = getFieldBuffer(fieldIndex);
    // zig zag encoding
    VarInt.writeVLong(buf, ZigZag.encodeLong(value));
  }
}

代码示例来源:origin: Netflix/hollow

public void setInt(String fieldName, int value) {
  if(value == Integer.MIN_VALUE) {
    setNull(fieldName);
  } else {
    int fieldIndex = getSchema().getPosition(fieldName);
    validateFieldType(fieldIndex, fieldName, FieldType.INT);
    ByteDataBuffer buf = getFieldBuffer(fieldIndex);
    // zig zag encoding
    VarInt.writeVInt(buf, ZigZag.encodeInt(value));
  }
}

代码示例来源:origin: Netflix/hollow

return 0;
  int intVal = VarInt.readVInt(data, offset);
  intVal = ZigZag.decodeInt(intVal);
  return intVal;
case LONG:
    return 0;
  long longVal = VarInt.readVLong(data, offset);
  longVal = ZigZag.decodeLong(longVal);
  return (int)(longVal ^ (longVal >>> 32));
case REFERENCE:

代码示例来源:origin: Netflix/hollow

currentRecordPointer += VarInt.sizeOfVInt(ivalue);
if(rec != null)
  rec.setInt(fieldName, ZigZag.decodeInt(ivalue));
currentRecordPointer += VarInt.sizeOfVLong(lvalue);
if(rec != null)
  rec.setLong(fieldName, ZigZag.decodeLong(lvalue));

代码示例来源:origin: Netflix/hollow

@Test
public void translatesSchemas() {
  HollowObjectWriteRecord rec = new HollowObjectWriteRecord(schema);
  rec.setInt("FieldA", 1023);
  rec.setLong("FieldB", 123556);
  rec.setBoolean("FieldC", true);
  HollowObjectSchema translatedSchema = new HollowObjectSchema("Test", 3);
  translatedSchema.addField("FieldB", FieldType.LONG);
  translatedSchema.addField("FieldD", FieldType.STRING);
  translatedSchema.addField("FieldA", FieldType.INT);
  ByteDataBuffer buf = new ByteDataBuffer(WastefulRecycler.DEFAULT_INSTANCE);
  rec.writeDataTo(buf, translatedSchema);
  long field0 = VarInt.readVLong(buf.getUnderlyingArray(), 0);
  int field0Length = VarInt.sizeOfVLong(field0);
  int field2 = VarInt.readVInt(buf.getUnderlyingArray(), field0Length + 1);
  Assert.assertEquals(123556, ZigZag.decodeLong(field0));
  Assert.assertTrue(VarInt.readVNull(buf.getUnderlyingArray(), field0Length));
  Assert.assertEquals(1023, ZigZag.decodeInt(field2));
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com