public class TableWithTwoServiceBits
extends java.lang.Object
Every integer is encoded on 32 bits and stores two informations:
-) a reference on 30 bits
-) 2 service bits (the two rightmost bits: less significant bits)
Modifier and Type | Field and Description |
---|---|
int[] |
elements
The array whose elements are 32 bits integers: they contain a reference (on 30 bits) and the two service bits
|
Constructor and Description |
---|
TableWithTwoServiceBits(int nElements)
Initialize the array (static array with 'nElements')
|
Modifier and Type | Method and Description |
---|---|
int |
elementAt(int index)
Retrieve the integer reference stored at position 'index'
|
java.lang.String |
elementToString(int i)
Return a string representing the i-th element stored in the table.
|
static int |
extractReferenceFromInteger(int v)
Retrieve the integer reference stored in an integer value 'v'
|
static int |
extractTwoServiceBitsFromInteger(int v)
Retrieve the two service bits stored in 'v'
|
int |
getFirstServiceBit(int index) |
int |
getSecondServiceBit(int index) |
void |
set(int index,
int element)
Set the value of the integer reference stored at position 'index'
|
void |
setFirstServiceBit(int index)
Set the first service bit to '1'
|
void |
setSecondServiceBit(int index)
Set the second service bit to '1'
|
static int |
storeReferenceAndServiceBitsIntoInteger(int ref,
int serviceBits)
Store a value 'ref' (on 30 bits) and two service bits into an integer (on 32 bits)
|
public int[] elements
public TableWithTwoServiceBits(int nElements)
public int elementAt(int index)
index
- the index (position) of the reference in the arraypublic void set(int index, int element)
Warning:
-) it works only if the element is not already set
-) the two service bits are deleted: they are set to '0'
index
- the index (position) of the reference in the arrayelement
- the value of the reference (an integer on 30 bits)public int getFirstServiceBit(int index)
public int getSecondServiceBit(int index)
public void setFirstServiceBit(int index)
public void setSecondServiceBit(int index)
public java.lang.String elementToString(int i)
The result contains an integer value, and the two service bits. Service bits are printed from the right: the right-most bit represents the first service bits
public static int extractReferenceFromInteger(int v)
v
- the input valuepublic static int extractTwoServiceBitsFromInteger(int v)
v
- the input valuepublic static int storeReferenceAndServiceBitsIntoInteger(int ref, int serviceBits)
element
- the value of the reference to be stored (on 30 bits)serviceBits
- an integer (it must be in 0..3) representing service bits: '2' means '10', '3' means '11', '1' means 01, '0' means '00'