@NotThreadSafe public final class LinearProbingIndex extends Object implements Index
The index hash table looks like: ===================================== | fingerprint (byte) | offset (int) | ===================================== | fingerprint (byte) | offset (int) | ===================================== | ... | If fingerprint is zero, it indicates the bucket is empty.
The overall byte array of the index looks like: | key count (int) | the above hash table |
Modifier and Type | Field and Description |
---|---|
static int |
MAX_PROBES
Max number of probes for linear probing.
|
Modifier and Type | Method and Description |
---|---|
int |
byteCount() |
static LinearProbingIndex |
createEmptyIndex() |
byte |
fingerprintHash(byte[] key)
Hashes a key in byte array into a non-zero, one byte fingerprint.
|
byte |
fingerprintHash(ByteBuffer key)
Hashes a key in
ByteBuffer into a non-zero, one byte fingerprint. |
ByteBuffer |
get(ByteBuffer key,
PayloadReader reader)
Gets the bytes of value given the key and payload storage reader.
|
byte[] |
getBytes() |
int |
indexHash(byte[] key)
Hashes a key in byte array to a bucket index in non-negative integer value.
|
int |
indexHash(ByteBuffer key)
Hashes a key in
ByteBuffer to a bucket index in non-negative integer value. |
int |
keyCount() |
Iterator<ByteBuffer> |
keyIterator(PayloadReader reader)
Gets an iterator to iterate over all keys.
|
static LinearProbingIndex |
loadFromByteArray(ByteBuffer buffer)
Creates an instance of linear probing index by loading its content from a buffer.
|
ByteBuffer |
nextKey(ByteBuffer currentKey,
PayloadReader reader)
Gets the next key relative to the current provided key.
|
boolean |
put(byte[] key,
byte[] value,
PayloadWriter writer)
Puts a key into the index and stores key and value data into payload storage.
|
public static final int MAX_PROBES
public static LinearProbingIndex createEmptyIndex()
public static LinearProbingIndex loadFromByteArray(ByteBuffer buffer)
Buffer.position
must be at the beginning of index.buffer
- intput buffer storing the indexpublic int byteCount()
public int keyCount()
public boolean put(byte[] key, byte[] value, PayloadWriter writer) throws IOException
Index
put
in interface Index
key
- bytes of keyvalue
- bytes of valuewriter
- writer to store key-value payloadIOException
public ByteBuffer get(ByteBuffer key, PayloadReader reader)
Index
public byte[] getBytes()
public int indexHash(byte[] key)
key
- key in byte arraypublic int indexHash(ByteBuffer key)
ByteBuffer
to a bucket index in non-negative integer value.key
- key in byte arraypublic byte fingerprintHash(byte[] key)
key
- key in byte arraypublic byte fingerprintHash(ByteBuffer key)
ByteBuffer
into a non-zero, one byte fingerprint.key
- key in byte arraypublic ByteBuffer nextKey(ByteBuffer currentKey, PayloadReader reader)
Index
This could be more efficient than iterating over Index.keyIterator(PayloadReader)
to find
the next key.
public Iterator<ByteBuffer> keyIterator(PayloadReader reader)
Index
This could be more efficient than repeatedly calling
Index.nextKey(ByteBuffer, PayloadReader)
.
keyIterator
in interface Index
reader
- reader to access key-value payloadCopyright © 2023. All Rights Reserved.