|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.btree.raba.AbstractKeyBuffer
com.bigdata.btree.raba.MutableKeyBuffer
public class MutableKeyBuffer
A flyweight mutable implementation exposing the backing byte[][] and supporting search.
| Field Summary | |
|---|---|
byte[][] |
keys
An array containing the keys. |
int |
nkeys
The #of defined keys. |
| Constructor Summary | |
|---|---|
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 array of keys but sharing the key references with the provided MutableKeyBuffer. |
|
| Method Summary | |
|---|---|
protected int |
_binarySearch(int searchKeyOffset,
byte[] searchKey)
Binary search. |
protected int |
_linearSearch(int searchKeyOffset,
byte[] searchKey)
Linear search. |
protected int |
_prefixMatchLength(int prefixLength,
byte[] searchKey)
Test the search key against the leading prefix shared by all bytes in the key buffer. |
int |
add(byte[] key)
Append a byte[] value to the end of the logical byte[][] (optional operation). |
int |
add(byte[] key,
int off,
int len)
Append a byte[] value to the end of the logical byte[][] (optional operation). |
int |
add(DataInput in,
int len)
Append a byte[] value to the end of the logical byte[][] (optional operation). |
void |
assertKeysMonotonic()
Verifies that the keys are in sort order and that undefined keys are [null]. |
int |
capacity()
The maximum #of keys that may be held in the buffer (its capacity). |
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. |
byte[] |
getPrefix()
Computes the #of leading bytes shared by all keys and returns a new byte[] containing those bytes. |
int |
getPrefixLength()
Computes the length of the prefix by computed by counting the #of leading bytes that match for the first and last key in the buffer. |
int |
insert(int index,
byte[] key)
Insert a key into the buffer at the specified index, incrementing the #of keys in the buffer by one and moving down all keys from that index on down by one (towards the end of the array). |
boolean |
isEmpty()
True iff the logical byte[][] is empty. |
boolean |
isFull()
True iff the key buffer can not contain another key. |
boolean |
isKeys()
Instances are searchable and do not allow nulls. |
boolean |
isNull(int index)
Return true iff the byte[] at that index is
null. |
boolean |
isReadOnly()
Mutable. |
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 and moving up all keys from that index on down by one (towards the start of the array). |
int |
search(byte[] searchKey)
Search for the given searchKey in the key buffer (optional operation). |
void |
set(int index,
byte[] key)
Set the key at the specified index. |
int |
size()
The #of entries in the logical byte[][]. |
String |
toString()
|
| Methods inherited from class com.bigdata.btree.raba.AbstractKeyBuffer |
|---|
iterator |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public int nkeys
public final byte[][] keys
| Constructor Detail |
|---|
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)
MutableKeyBuffer.
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.| Method Detail |
|---|
public final byte[] get(int index)
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
index - The index in [0:IRaba.size()-1].
public final int copy(int index,
OutputStream out)
IRabaByteArrayBuffer so that the same backing
byte[] can be overwritten by each visited key.
index - The index in [0:IRaba.size()-1].
public final boolean isNull(int index)
IRabatrue iff the byte[] at that index is
null. If IRaba.isKeys() would return
true then this method MUST return false since
nulls are not permitted for B+Tree keys.
index - The index in [0:IRaba.size()-1].public final boolean isEmpty()
IRaba
public final int size()
IRaba
public final int capacity()
public final boolean isFull()
public final boolean isReadOnly()
public final boolean isKeys()
nulls.
true if the IRaba represents B+Tree keys and
false if it represents B+Tree values.
public final void set(int index,
byte[] key)
index - The index in [0:nkeys-1].key - The key (non-null).public final int add(byte[] key)
IRaba
key - A value.
public final int add(byte[] key,
int off,
int len)
IRaba
key - A valueoff - The offset of the first byte to be copied.len - The #of bytes to be copied.
public int add(DataInput in,
int len)
throws IOException
IRaba
in - The input stream from which the byte[] will be read.len - The #of bytes to be read.
IOException
public final int insert(int index,
byte[] key)
index - The index in [0:nkeys] (you are allowed to append using this
method).key - The key.
public final int remove(int index)
index - The index in [0:nkeys-1].key - The key.
public String toString()
toString in class Objectpublic final int search(byte[] searchKey)
IRaba
entryIndex = -entryIndex - 1or just
entryIndex = -entryIndexif you are looking for the first key after the searchKey.
searchKey - 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.
protected final int _prefixMatchLength(int prefixLength,
byte[] searchKey)
AbstractKeyBuffer
_prefixMatchLength in class AbstractKeyBufferprefixLength - The length of the prefix shared by all keys in the buffer.searchKey - The search key.
protected final int _linearSearch(int searchKeyOffset,
byte[] searchKey)
AbstractKeyBuffer
_linearSearch in class AbstractKeyBuffer
protected final int _binarySearch(int searchKeyOffset,
byte[] searchKey)
AbstractKeyBuffer
_binarySearch in class AbstractKeyBufferpublic final void assertKeysMonotonic()
public int getPrefixLength()
getPrefixLength in class AbstractKeyBufferpublic byte[] getPrefix()
getPrefix in class AbstractKeyBuffer
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||