PackedBitStorage.java
net.minecraft.util.datafix.PackedBitStorage
信息
- 全限定名:net.minecraft.util.datafix.PackedBitStorage
- 类型:public class
- 包:net.minecraft.util.datafix
- 源码路径:src/main/java/net/minecraft/util/datafix/PackedBitStorage.java
- 起始行号:L6
- 职责:
TODO
字段/常量
-
BIT_TO_LONG_SHIFT- 类型:
int - 修饰符:
private static final - 源码定位:
L7 - 说明:
TODO
- 类型:
-
data- 类型:
long[] - 修饰符:
private final - 源码定位:
L8 - 说明:
TODO
- 类型:
-
bits- 类型:
int - 修饰符:
private final - 源码定位:
L9 - 说明:
TODO
- 类型:
-
mask- 类型:
long - 修饰符:
private final - 源码定位:
L10 - 说明:
TODO
- 类型:
-
size- 类型:
int - 修饰符:
private final - 源码定位:
L11 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public PackedBitStorage(int bits, int size) @ L13
- 构造器名:PackedBitStorage
- 源码定位:L13
- 修饰符:public
参数:
- bits: int
- size: int
说明:
TODO
public PackedBitStorage(int bits, int size, long[] data) @ L17
- 构造器名:PackedBitStorage
- 源码定位:L17
- 修饰符:public
参数:
- bits: int
- size: int
- data: long[]
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void set(int index, int value) @ L29
- 方法名:set
- 源码定位:L29
- 返回类型:void
- 修饰符:public
参数:
- index: int
- value: int
说明:
TODO
public int get(int index) @ L44
- 方法名:get
- 源码定位:L44
- 返回类型:int
- 修饰符:public
参数:
- index: int
说明:
TODO
public long[] getRaw() @ L58
- 方法名:getRaw
- 源码定位:L58
- 返回类型:long[]
- 修饰符:public
参数:
- 无
说明:
TODO
public int getBits() @ L62
- 方法名:getBits
- 源码定位:L62
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class PackedBitStorage {
private static final int BIT_TO_LONG_SHIFT = 6;
private final long[] data;
private final int bits;
private final long mask;
private final int size;
public PackedBitStorage(int bits, int size) {
this(bits, size, new long[Mth.roundToward(size * bits, 64) / 64]);
}
public PackedBitStorage(int bits, int size, long[] data) {
Validate.inclusiveBetween(1L, 32L, (long)bits);
this.size = size;
this.bits = bits;
this.data = data;
this.mask = (1L << bits) - 1L;
int requiredLength = Mth.roundToward(size * bits, 64) / 64;
if (data.length != requiredLength) {
throw new IllegalArgumentException("Invalid length given for storage, got: " + data.length + " but expected: " + requiredLength);
}
}
public void set(int index, int value) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
Validate.inclusiveBetween(0L, this.mask, (long)value);
int position = index * this.bits;
int startData = position >> 6;
int endData = (index + 1) * this.bits - 1 >> 6;
int startBit = position ^ startData << 6;
this.data[startData] = this.data[startData] & ~(this.mask << startBit) | (value & this.mask) << startBit;
if (startData != endData) {
int shiftBits = 64 - startBit;
int wantedBits = this.bits - shiftBits;
this.data[endData] = this.data[endData] >>> wantedBits << wantedBits | (value & this.mask) >> shiftBits;
}
}
public int get(int index) {
Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
int position = index * this.bits;
int startData = position >> 6;
int endData = (index + 1) * this.bits - 1 >> 6;
int startBit = position ^ startData << 6;
if (startData == endData) {
return (int)(this.data[startData] >>> startBit & this.mask);
} else {
int shiftBits = 64 - startBit;
return (int)((this.data[startData] >>> startBit | this.data[endData] << shiftBits) & this.mask);
}
}
public long[] getRaw() {
return this.data;
}
public int getBits() {
return this.bits;
}
}引用的其他类
- Mth
- 引用位置:
方法调用 - 关联成员:
Mth.roundToward()
- 引用位置: