public class NdRawLinkedList
extends java.lang.Object
NdRawLinkedList stores a list of fixed-sized records. Along with the records themselves, there is also
a bit field associated with each record which can hold a small number of bits of metadata per record.
The underlying format is as follows:
Bytes Content
----------------
4 Pointer to the next block. If this is 0, this is the last block and it is not yet full. The number of
elements will be stored at the position where the last element would normally start. If this points back
to the start of the block, this is the last block and it is full. If this holds any other value, the
block is full and this points to the next block.
headerSize Bit field for this block (the bits for each element are tightly packed)
recordSize The content of the first element in the block
recordSize The content of the second element in the block
... repeated recordsPerBlock times
recordSize If the block is full, this holds the last
stored in linked blocks where each block is an array of record pointers. Each block contains a pointer to the
subsequent block, so they can be chained.
The size of the blocks are generally hardcoded. All blocks are the same size except for the first block whose size may be configured independently. The size of the first block may be zero, in which case the first "block" is simply a pointer to the following block or null.
| Modifier and Type | Class and Description |
|---|---|
static interface |
NdRawLinkedList.ILinkedListVisitor |
| Constructor and Description |
|---|
NdRawLinkedList(Nd nd,
long address,
int elementRecordSize,
int firstBlockRecordCount,
int recordsPerBlock,
int metadataBitsPerRecord) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(NdRawLinkedList.ILinkedListVisitor visitor) |
long |
addMember(short metadataBits)
Adds a new element to the list and returns the record pointer to the start of the newly-allocated object
|
void |
destruct() |
long |
getAddress() |
Nd |
getNd() |
static int |
recordSize(int elementRecordSize,
int recordsPerBlock,
int metadataBitsPerRecord)
Returns the record size for a linked list with the given element record size and number of
records per block
|
int |
size()
Returns the number of elements in this list.
|
public NdRawLinkedList(Nd nd, long address, int elementRecordSize, int firstBlockRecordCount, int recordsPerBlock, int metadataBitsPerRecord)
nd - the Nd objectaddress - pointer to the start of the linked listrecordsPerBlock - number of records per block. This is normally a hardcoded value.public static int recordSize(int elementRecordSize,
int recordsPerBlock,
int metadataBitsPerRecord)
public Nd getNd()
public long getAddress()
public long addMember(short metadataBits)
throws IndexException
metadataBits - the metadata bits to attach to the new member. Use 0 if this list does not use metadata.IndexExceptionpublic void accept(NdRawLinkedList.ILinkedListVisitor visitor) throws IndexException
IndexExceptionpublic void destruct()
throws IndexException
IndexExceptionpublic int size()
throws IndexException
IndexException