public class SegmentsUtil extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
LITTLE_ENDIAN
Constant that flags the byte order.
|
Constructor and Description |
---|
SegmentsUtil() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
allocateReuseBytes(int length)
Allocate bytes that is only for temporary usage, it should not be stored in somewhere else.
|
static char[] |
allocateReuseChars(int length) |
static boolean |
bitGet(MemorySegment[] segments,
int baseOffset,
int index)
read bit from segments.
|
static boolean |
bitGet(MemorySegment segment,
int baseOffset,
int index)
read bit.
|
static void |
bitSet(MemorySegment[] segments,
int baseOffset,
int index)
set bit from segments.
|
static void |
bitSet(MemorySegment segment,
int baseOffset,
int index)
set bit.
|
static void |
bitUnSet(MemorySegment[] segments,
int baseOffset,
int index)
unset bit from segments.
|
static void |
bitUnSet(MemorySegment segment,
int baseOffset,
int index)
unset bit.
|
static void |
copyFromBytes(MemorySegment[] segments,
int offset,
byte[] bytes,
int bytesOffset,
int numBytes)
Copy target segments from source byte[].
|
static void |
copyMultiSegmentsToBytes(MemorySegment[] segments,
int offset,
byte[] bytes,
int bytesOffset,
int numBytes) |
static byte[] |
copyToBytes(MemorySegment[] segments,
int offset,
byte[] bytes,
int bytesOffset,
int numBytes)
Copy segments to target byte[].
|
static byte[] |
copyToBytes(MemorySegment[] segments,
int offset,
int numBytes)
Copy segments to a new byte[].
|
static void |
copyToUnsafe(MemorySegment[] segments,
int offset,
Object target,
int pointer,
int numBytes)
Copy segments to target unsafe pointer.
|
static void |
copyToView(MemorySegment[] segments,
int offset,
int sizeInBytes,
DataOutputView target)
Copy bytes of segments to output view.
|
static boolean |
equals(MemorySegment[] segments1,
int offset1,
MemorySegment[] segments2,
int offset2,
int len)
Equals two memory segments regions.
|
static int |
find(MemorySegment[] segments1,
int offset1,
int numBytes1,
MemorySegment[] segments2,
int offset2,
int numBytes2)
Find equal segments2 in segments1.
|
static boolean |
getBoolean(MemorySegment[] segments,
int offset)
get boolean from segments.
|
static byte |
getByte(MemorySegment[] segments,
int offset)
get byte from segments.
|
static byte[] |
getBytes(MemorySegment[] segments,
int baseOffset,
int sizeInBytes)
Maybe not copied, if want copy, please use copyTo.
|
static double |
getDouble(MemorySegment[] segments,
int offset)
get double from segments.
|
static float |
getFloat(MemorySegment[] segments,
int offset)
get float from segments.
|
static int |
getInt(MemorySegment[] segments,
int offset)
get int from segments.
|
static long |
getLong(MemorySegment[] segments,
int offset)
get long from segments.
|
static short |
getShort(MemorySegment[] segments,
int offset)
get short from segments.
|
static int |
hash(MemorySegment[] segments,
int offset,
int numBytes)
hash segments to int.
|
static int |
hashByWords(MemorySegment[] segments,
int offset,
int numBytes)
hash segments to int, numBytes must be aligned to 4 bytes.
|
static void |
setBoolean(MemorySegment[] segments,
int offset,
boolean value)
set boolean from segments.
|
static void |
setByte(MemorySegment[] segments,
int offset,
byte value)
set byte from segments.
|
static void |
setDouble(MemorySegment[] segments,
int offset,
double value)
set double from segments.
|
static void |
setFloat(MemorySegment[] segments,
int offset,
float value)
set float from segments.
|
static void |
setInt(MemorySegment[] segments,
int offset,
int value)
set int from segments.
|
static void |
setLong(MemorySegment[] segments,
int offset,
long value)
set long from segments.
|
static void |
setShort(MemorySegment[] segments,
int offset,
short value)
set short from segments.
|
public static final boolean LITTLE_ENDIAN
public static byte[] allocateReuseBytes(int length)
ThreadLocal
to reuse bytes to avoid overhead of byte[] new and gc.
If there are methods that can only accept a byte[], instead of a MemorySegment[] parameter, we can allocate a reuse bytes and copy the MemorySegment data to byte[], then call the method. Such as String deserialization.
public static char[] allocateReuseChars(int length)
public static byte[] copyToBytes(MemorySegment[] segments, int offset, int numBytes)
segments
- Source segments.offset
- Source segments offset.numBytes
- the number bytes to copy.public static byte[] copyToBytes(MemorySegment[] segments, int offset, byte[] bytes, int bytesOffset, int numBytes)
segments
- Source segments.offset
- Source segments offset.bytes
- target byte[].bytesOffset
- target byte[] offset.numBytes
- the number bytes to copy.public static void copyMultiSegmentsToBytes(MemorySegment[] segments, int offset, byte[] bytes, int bytesOffset, int numBytes)
public static void copyToUnsafe(MemorySegment[] segments, int offset, Object target, int pointer, int numBytes)
segments
- Source segments.offset
- The position where the bytes are started to be read from these memory segments.target
- The unsafe memory to copy the bytes to.pointer
- The position in the target unsafe memory to copy the chunk to.numBytes
- the number bytes to copy.public static void copyToView(MemorySegment[] segments, int offset, int sizeInBytes, DataOutputView target) throws IOException
segments
- source segmentsoffset
- offset for segmentssizeInBytes
- size in bytestarget
- target output viewIOException
public static void copyFromBytes(MemorySegment[] segments, int offset, byte[] bytes, int bytesOffset, int numBytes)
segments
- target segments.offset
- target segments offset.bytes
- source byte[].bytesOffset
- source byte[] offset.numBytes
- the number bytes to copy.public static byte[] getBytes(MemorySegment[] segments, int baseOffset, int sizeInBytes)
public static boolean equals(MemorySegment[] segments1, int offset1, MemorySegment[] segments2, int offset2, int len)
segments1
- Segments 1offset1
- Offset of segments1 to start equalingsegments2
- Segments 2offset2
- Offset of segments2 to start equalinglen
- Length of the equaled memory regionpublic static int hashByWords(MemorySegment[] segments, int offset, int numBytes)
segments
- Source segments.offset
- Source segments offset.numBytes
- the number bytes to hash.public static int hash(MemorySegment[] segments, int offset, int numBytes)
segments
- Source segments.offset
- Source segments offset.numBytes
- the number bytes to hash.public static void bitUnSet(MemorySegment segment, int baseOffset, int index)
segment
- target segment.baseOffset
- bits base offset.index
- bit index from base offset.public static void bitSet(MemorySegment segment, int baseOffset, int index)
segment
- target segment.baseOffset
- bits base offset.index
- bit index from base offset.public static boolean bitGet(MemorySegment segment, int baseOffset, int index)
segment
- target segment.baseOffset
- bits base offset.index
- bit index from base offset.public static void bitUnSet(MemorySegment[] segments, int baseOffset, int index)
segments
- target segments.baseOffset
- bits base offset.index
- bit index from base offset.public static void bitSet(MemorySegment[] segments, int baseOffset, int index)
segments
- target segments.baseOffset
- bits base offset.index
- bit index from base offset.public static boolean bitGet(MemorySegment[] segments, int baseOffset, int index)
segments
- target segments.baseOffset
- bits base offset.index
- bit index from base offset.public static boolean getBoolean(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setBoolean(MemorySegment[] segments, int offset, boolean value)
segments
- target segments.offset
- value offset.public static byte getByte(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setByte(MemorySegment[] segments, int offset, byte value)
segments
- target segments.offset
- value offset.public static int getInt(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setInt(MemorySegment[] segments, int offset, int value)
segments
- target segments.offset
- value offset.public static long getLong(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setLong(MemorySegment[] segments, int offset, long value)
segments
- target segments.offset
- value offset.public static short getShort(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setShort(MemorySegment[] segments, int offset, short value)
segments
- target segments.offset
- value offset.public static float getFloat(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setFloat(MemorySegment[] segments, int offset, float value)
segments
- target segments.offset
- value offset.public static double getDouble(MemorySegment[] segments, int offset)
segments
- target segments.offset
- value offset.public static void setDouble(MemorySegment[] segments, int offset, double value)
segments
- target segments.offset
- value offset.public static int find(MemorySegment[] segments1, int offset1, int numBytes1, MemorySegment[] segments2, int offset2, int numBytes2)
segments1
- segs to find.segments2
- sub segs.Copyright © 2014–2022 The Apache Software Foundation. All rights reserved.