public class MutableKeyBuffer extends Object implements IRaba
HTree
bucket page using a
backing byte[][]
. Unlike the keys in a B+Tree, the HTree
keys are NOT ordered and need not be dense. Further, each bucket page is
logically divided into a set of buddy hash buckets. All operations therefore
take place within a buddy bucket. The buddy bucket is identified by its
offset and its extent is identified by the global depth of the bucket page.
While the total #of non-null keys is reported by size()
, this is the
value for the bucket page as a whole. The HTree
must explicitly
examine a buddy hash bucket and count the non-null
keys in order
to know the "size" of a given buddy hash bucket.
Note: Because the slots are divided logically among the buddy buckets any
slot may have a non-null
key and the IRaba
methods as
implemented by this class DO NOT range check the index against
size()
.
Modifier and Type | Field and Description |
---|---|
byte[][] |
keys
An array containing the keys.
|
int |
nkeys
The #of defined keys across the entire bucket page.
|
Constructor and Description |
---|
MutableKeyBuffer(int capacity)
Allocate a mutable key buffer capable of storing capacity keys.
|
MutableKeyBuffer(int nkeys,
byte[][] keys)
Constructor wraps an existing byte[][].
|
MutableKeyBuffer(int capacity,
IRaba src)
Builds a mutable key buffer.
|
MutableKeyBuffer(MutableKeyBuffer src)
Creates a new instance using a new byte[][] but sharing the byte[]
references with the caller's buffer.
|
Modifier and Type | Method and Description |
---|---|
int |
add(byte[] key)
This method is not supported.
|
int |
add(byte[] key,
int off,
int len)
This method is not supported.
|
int |
add(DataInput in,
int len)
This method is not supported.
|
int |
capacity()
The capacity of the logical byte[][].
|
int |
copy(int index,
OutputStream out)
Copy the value at the specified index onto the output stream.
|
byte[] |
get(int index)
Returns a reference to the key at that index.
|
void |
insert(int index,
byte[] key) |
boolean |
isEmpty()
True iff the logical byte[][] is empty.
|
boolean |
isFull()
True iff the logical byte[][] is full.
|
boolean |
isKeys()
Instances are searchable and support duplicate keys.
|
boolean |
isNull(int index)
Return
true iff the byte[] at that index is
null . |
boolean |
isReadOnly()
Mutable.
|
Iterator<byte[]> |
iterator()
Iterator visits the byte[] elements in the view order.
|
int |
length(int index)
The length of the byte[] at that index.
|
int |
remove(int index)
Remove a key in the buffer at the specified index, decrementing the #of
keys in the buffer by one.
|
int |
search(byte[] key)
Used for both lookup and insert.
|
void |
set(int index,
byte[] key)
Set the byte[] value at the specified index (optional operation).
|
int |
size()
The #of entries in the logical byte[][].
|
String |
toString() |
public int nkeys
null
keys (free slots) in that buddy hash bucket.public final byte[][] keys
2^addressBits
.public MutableKeyBuffer(int capacity)
capacity
- The capacity of the key buffer.public MutableKeyBuffer(int nkeys, byte[][] keys)
nkeys
- The #of defined keys in the array.keys
- The array of keys.public MutableKeyBuffer(MutableKeyBuffer src)
src
- An existing instance.public MutableKeyBuffer(int capacity, IRaba src)
capacity
- The capacity of the new instance (this is based on the
branching factor for the B+Tree).src
- The source data.IllegalArgumentException
- if the capacity is LT the IRaba.size()
of the
src.IllegalArgumentException
- if the source is null
.public final byte[] get(int index)
get
in interface IRaba
index
- The index in [0:IRaba.size()
-1].null
if a
null
value was stored at that index.public final int length(int index)
IRaba
length
in interface IRaba
index
- The index in [0:IRaba.size()
-1].public final int copy(int index, OutputStream out)
IRaba
ByteArrayBuffer
so that the same backing
byte[] can be overwritten by each visited key.copy
in interface IRaba
index
- The index in [0:IRaba.size()
-1].public final boolean isNull(int index)
true
iff the byte[] at that index is
null
. If IRaba.isKeys()
would return
true
then this method MUST return false
since
null
s are not permitted for B+Tree keys.isNull
in interface IRaba
index
- The index in [0:IRaba.size()
-1].true
iff the key at that index is null
.public final boolean isEmpty()
IRaba
public final int size()
Note: This is the #of keys in the bucket page (across all buddy buckets on that page). Unless there is only one buddy bucket on the page, you MUST explicitly scan a buddy bucket to determine the #of keys in a buddy bucket on the page.
public final int capacity()
IRaba
public final boolean isFull()
IRaba
public final boolean isReadOnly()
isReadOnly
in interface IRaba
public final boolean isKeys()
public Iterator<byte[]> iterator()
null
, then the iterator will report a null
for
that element.
This iterator visits all keys on the bucket page, including
null
s.
public final void set(int index, byte[] key)
IRaba
set
in interface IRaba
index
- The index in [0:IRaba.size()
-1].key
- The byte[] value.public final void insert(int index, byte[] key)
public final int remove(int index)
index
- The index in [0:capacity()
-1].key
- The key.public final int add(byte[] key)
set(int, byte[])
.add
in interface IRaba
key
- A value.UnsupportedOperationException
public final int add(byte[] key, int off, int len)
set(int, byte[])
.add
in interface IRaba
key
- A valueoff
- The offset of the first byte to be copied.len
- The #of bytes to be copied.UnsupportedOperationException
public int add(DataInput in, int len) throws IOException
set(int, byte[])
.add
in interface IRaba
in
- The input stream from which the byte[] will be read.len
- The #of bytes to be read.UnsupportedOperationException
IOException
public int search(byte[] key)
search
in interface IRaba
key
- The search key.(-(insertion point) - 1)
. The insertion point is
defined as the point at which the key would be inserted. Note
that this guarantees that the return value will be >= 0 if and
only if the key is found.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.