Package io.github.olyutorskii.aletojio
Class BitPool
java.lang.Object
io.github.olyutorskii.aletojio.BitPool
Bit pool.
Pushing any size of bits to bit-queue tail.
Chopping any size of bits from bit-queue head.
From MSB to LSB.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
capacity()
Return max available size.boolean
Chop boolean value from head of queue.byte
chopByte()
Chop byte value from head of queue.int
chopInt()
Chop int value from head of queue.int
chopInt
(int bitCt) Chop bits and store to lower bits of int value from head of queue.long
chopLong()
Chop long value from head of queue.long
chopLong
(int bitCt) Chop bits and store to lower bits of long value from head of queue.void
clear()
clear bit pool.boolean
Return true if has remaining spaces.boolean
isEmpty()
Return true if empty.void
pushBoolean
(boolean bool) Push boolean value to tail of queue.void
pushByte
(byte bArg) Push byte value to tail of queue.void
pushInt
(int iArg) Push int value to tail of queue.void
pushInt
(int iArg, int bitCt) Push lower bits of int value to tail of queue.void
pushLong
(long lArg) Push long value to tail of queue.void
pushLong
(long lArg, int bitCt) Push lower bits of long value to tail of queue.int
Return remaining spaces.int
size()
Resturn bit size.
-
Field Details
-
DEFAULT_BITS
public static final int DEFAULT_BITSDefault bit size.- See Also:
-
-
Constructor Details
-
BitPool
public BitPool()Constructor.bit size is 512.
-
BitPool
Constructor.- Parameters:
bitLength
- bit length- Throws:
IllegalArgumentException
- length is not positive value
-
-
Method Details
-
size
public int size()Resturn bit size.- Returns:
- bit size
-
capacity
public int capacity()Return max available size.- Returns:
- capacity size
-
isEmpty
public boolean isEmpty()Return true if empty.- Returns:
- true if empty
-
remaining
public int remaining()Return remaining spaces.- Returns:
- remaining spaces.
-
hasRemaining
public boolean hasRemaining()Return true if has remaining spaces.- Returns:
- true if has remaining spaces
-
clear
public void clear()clear bit pool. -
pushBoolean
Push boolean value to tail of queue.- Parameters:
bool
- boolean value- Throws:
IndexOutOfBoundsException
- no more space
-
chopBoolean
Chop boolean value from head of queue.- Returns:
- boolean value
- Throws:
IndexOutOfBoundsException
- not enough bits
-
pushInt
Push int value to tail of queue.- Parameters:
iArg
- int value- Throws:
IndexOutOfBoundsException
- no more space
-
pushInt
Push lower bits of int value to tail of queue.- Parameters:
iArg
- int valuebitCt
- bits from LSB- Throws:
IndexOutOfBoundsException
- bits is not positive or no more space or over 32
-
chopInt
Chop int value from head of queue.- Returns:
- int value
- Throws:
IndexOutOfBoundsException
- not enough bits
-
chopInt
Chop bits and store to lower bits of int value from head of queue.- Parameters:
bitCt
- bits- Returns:
- lower bits filled int value
- Throws:
IndexOutOfBoundsException
- not enough bits or bits is not positive or over 32
-
pushLong
Push long value to tail of queue.- Parameters:
lArg
- long value- Throws:
IndexOutOfBoundsException
- no more space
-
pushLong
Push lower bits of long value to tail of queue.- Parameters:
lArg
- long valuebitCt
- bits from LSB- Throws:
IndexOutOfBoundsException
- bits is not positive or no more space or over 64
-
chopLong
Chop long value from head of queue.- Returns:
- long value
- Throws:
IndexOutOfBoundsException
- not enough bits
-
chopLong
Chop bits and store to lower bits of long value from head of queue.- Parameters:
bitCt
- bits- Returns:
- lower bits filled long value
- Throws:
IndexOutOfBoundsException
- not enough bits or bits is not positive or over 64
-
pushByte
Push byte value to tail of queue.- Parameters:
bArg
- byte value- Throws:
IndexOutOfBoundsException
- no more space
-
chopByte
Chop byte value from head of queue.- Returns:
- byte value
- Throws:
IndexOutOfBoundsException
- not enough bits
-