|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.unipi.di.util.Basics
public class Basics
This class offers various basic procedures to operate on byte arrays, ByteBuffers and BitSets at bit level.
Method Summary | |
---|---|
static byte[] |
BitSet2ByteArray(BitSet X)
Wrap a BitSet into a byte[] |
static ByteBuffer |
BitSet2ByteBuffer(BitSet X)
Wrap a BitSet into a ByteBuffer |
static BitSet |
byteArray2BitSet(byte[] B)
Wrap a byte[] into a BitSet |
static BitSet |
ByteBuffer2BitSet(ByteBuffer B)
Wrap a ByteBuffer into a BitSet |
static byte |
countBitInByte(byte b,
byte off,
byte end,
boolean fast)
Returns the number of bits set to 1 in a portion of byte. |
static int |
countBitInByteArray(byte[] b,
int start,
int end)
Returns the number of bits set to 1 in a portion of byte[]. |
static int |
countBitInByteBuffer(ByteBuffer b,
int start,
int end)
Returns the number of bits set to 1 in a portion of ByteBuffer . |
static void |
fillCounts()
|
static boolean |
getBitFromByte(byte x,
int i)
Returns the value of the selected bit of a byte. |
static boolean |
getBitFromByteArray(byte[] A,
int i)
Returns the value of the selected bit of a byte[]. |
static boolean |
getBitFromByteBuffer(ByteBuffer A,
int i)
Returns the value of the selected bit of a ByteBuffer . |
static boolean |
isEmptyByteArray(byte[] b,
int start,
int end)
Checks is a portion of a byte[] contains bits set to 1 |
static long |
loadFromBitset(BitSet P,
int i,
int b)
Loads a block of bit from a BitSet . |
static int |
loadFromByteArray(byte[] A,
int i,
int b)
Loads a block of bit from a byte[]. |
static int |
loadFromByteBuffer(ByteBuffer A,
int i,
int b)
Loads a block of bit from a ByteBuffer . |
static int |
loadFromFile(RandomAccessFile F,
long i,
int b)
Loads a block of bit from a file. |
static int |
log2(long x)
Returns the log2 of a number. |
static int |
nextSetBitInByte(byte A,
int i)
Returns the position of the first bit set to 1 in a byte after the specified position. |
static int |
nextSetBitInByteArray(byte[] A,
int i)
Returns the position of the first bit set to 1 in a byte[] after the specified position. |
static int |
nextSetBitInByteBuffer(ByteBuffer A,
int i)
Returns the position of the first bit set to 1 in a ByteBuffer after the specified position. |
static byte |
setBitInByte(byte x,
int i,
boolean b)
Set the i-th bit of a byte to the specified value. |
static void |
setBitInByteArray(byte[] A,
int i,
boolean b)
Set the i-th bit of a byte array to the specified value. |
static void |
setBitInByteBuffer(ByteBuffer A,
int i,
boolean b)
Set the i-th bit of a ByteBuffer to the specified value. |
static void |
storeInBitset(BitSet P,
int i,
long x,
int b)
Store the b lower bits of x in the BitSet P[i,i+b-1]. |
static void |
storeInByteArray(byte[] A,
int i,
int x,
int b)
Store the b lower bits of x starting from the i-th bit of byte array A. |
static void |
storeInByteBuffer(ByteBuffer A,
int i,
int x,
int b)
Store the b lower bits of x starting from the i-th bit of ByteBuffer A. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void fillCounts() throws IOException
IOException
public static int log2(long x) throws IOException
x
- is a positive long
IOException
public static BitSet byteArray2BitSet(byte[] B) throws IOException
BitSet
B
- is the byte array to be converted
IOException
public static BitSet ByteBuffer2BitSet(ByteBuffer B) throws IOException
ByteBuffer
into a BitSet
B
- is the byte array to be converted
IOException
public static byte[] BitSet2ByteArray(BitSet X) throws IOException
BitSet
into a byte[]
X
- is the BitSet to be converted
IOException
public static ByteBuffer BitSet2ByteBuffer(BitSet X) throws IOException
BitSet
into a ByteBuffer
X
- is the BitSet to be converted
IOException
public static byte setBitInByte(byte x, int i, boolean b) throws IOException
x
- is a bytei
- is the offset in the byte of the bit to be set, 0 <= i <= 7b
- is the value to set, either true (1) or false (0)
IOException
public static void setBitInByteArray(byte[] A, int i, boolean b) throws IOException
A
- is the byte array whose bit has to be seti
- is the offset of the bit to be set, i is counted from 0b
- is the value to set, either true (1) or false (0)
IOException
public static void setBitInByteBuffer(ByteBuffer A, int i, boolean b) throws IOException
A
- is the ByteBuffer whose bit has to be seti
- is the offset of the bit to be set, i is counted from 0b
- is the value to set, either true (1) or false (0)
BasicException
IOException
public static boolean getBitFromByte(byte x, int i) throws IOException
x
- is the byte from which the bit is readi
- is the offset of the bit to be read, i is counted from 0
IOException
public static boolean getBitFromByteArray(byte[] A, int i) throws IOException
A
- is the byte array from which the bit is readi
- is the offset of the bit to be read, i is counted from 0
IOException
public static boolean getBitFromByteBuffer(ByteBuffer A, int i) throws IOException
ByteBuffer
.
A
- is the ByteBuffer from which the bit is readi
- is the offset of the bit to be read, i is counted from 0
IOException
public static int nextSetBitInByte(byte A, int i) throws IOException
A
- is a bytei
- is the offset from which the next set bit is searched
IOException
public static int nextSetBitInByteArray(byte[] A, int i) throws IOException
A
- is a byte arrayi
- is the offset from which the 1 bit is searched
IOException
public static int nextSetBitInByteBuffer(ByteBuffer A, int i) throws IOException
ByteBuffer
after the specified position.
A
- is a ByteBufferi
- is the offset from which the next set bit is searched
IOException
public static void storeInBitset(BitSet P, int i, long x, int b) throws IOException
P
- is the BitSet to be updatedi
- is the bit-offset (>=0) from which the update of P is executedx
- is the integer whose b lower bits are taken to update Pb
- is the number of bits to update, 0 < b <= 64
IOException
public static void storeInByteArray(byte[] A, int i, int x, int b) throws IOException
A
- is the byte array to be updatedi
- is the bit-offset (>= 0) from which the update of A is executedx
- is the integer whose b lower bits are taken to update Ab
- is the number of bits to update, 0 < b <= 32
IOException
public static void storeInByteBuffer(ByteBuffer A, int i, int x, int b) throws IOException
A
- is the ByteBuffer to be updatedi
- is the bit-offset (>= 0) from which the update of A is executedx
- is the integer whose b lower bits are taken to update Ab
- is the number of bits to update, 0 < b <= 32.
IOException
public static int loadFromFile(RandomAccessFile F, long i, int b) throws IOException
F
- is a RandomAccessFilei
- is the bit-offset (>= 0) in A from which the reading is executedb
- is the number of bits to read, 0 < b <= 32.
IOException
public static int loadFromByteArray(byte[] A, int i, int b) throws IOException
A
- is the byte array to be readi
- is the bit-offset (>= 0) in A from which the reading is executedb
- is the number of bits to read, 0 < b <= 32
IOException
public static int loadFromByteBuffer(ByteBuffer A, int i, int b) throws IOException
ByteBuffer
.
A
- is the ByteBuffer to be readi
- is the bit-offset (>= 0) in A from which the reading is executedb
- is the number of bits to read, 0 < b <= 32
IOException
public static long loadFromBitset(BitSet P, int i, int b) throws IOException
BitSet
.
P
- is the BitSet to be readi
- is the bit-offset (>= 0) in P from which the reading is executedb
- is the number of bits to read, 0 < b <= 64.
b bits in the BitSet P[i,i+b-1]
IOException
public static byte countBitInByte(byte b, byte off, byte end, boolean fast) throws IOException
b
- the byte to scanoff
- the bit to start fromend
- the last bit to countfast
- if true use fast count options (to use this option you will need
to call the fillCounts method before)
IOException
public static int countBitInByteArray(byte[] b, int start, int end) throws IOException
b
- the byte[] to scanstart
- the byte to start from
IOException
public static int countBitInByteBuffer(ByteBuffer b, int start, int end) throws IOException
ByteBuffer
.
b
- the ByteBuffer to scanstart
- the byte to start fromend
- the byte to stop at
IOException
public static boolean isEmptyByteArray(byte[] b, int start, int end) throws IOException
b
- the byte[] to scanstart
- the byte to start fromend
- the byte to stop at
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |