com.bigdata.btree.raba
Class MutableValueBuffer

java.lang.Object
  extended by com.bigdata.btree.raba.MutableValueBuffer
All Implemented Interfaces:
IRaba, Iterable<byte[]>

public class MutableValueBuffer
extends Object
implements IRaba

A flyweight mutable implementation exposing the backing byte[][], permitting nulls and not supporting search. It is assumed that caller maintains a dense byte[][] in the sense that all entries in [0:nvalues] are defined, even if some of entries are null. The implementation is NOT thread-safe for mutation.

Version:
$Id: MutableValueBuffer.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
 int nvalues
          The #of entries with valid data.
 byte[][] values
          The backing array.
 
Constructor Summary
MutableValueBuffer(int nvalues)
          Create a new, empty byte[][] of the specified capacity.
MutableValueBuffer(int nvalues, byte[][] values)
          Create a view of a byte[][].
MutableValueBuffer(int capacity, IRaba src)
          Builds a mutable value buffer.
 
Method Summary
 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).
protected  void assertNotFull()
           
 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)
          Return the byte[] at the specified index.
 boolean isEmpty()
          True iff the logical byte[][] is empty.
 boolean isFull()
          True iff the logical byte[][] is full.
 boolean isKeys()
          For B+Tree values.
 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.
protected  boolean rangeCheck(int index)
           
 int search(byte[] searchKey)
          Search for the given searchKey in the key buffer (optional operation).
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nvalues

public int nvalues
The #of entries with valid data.


values

public final byte[][] values
The backing array.

Constructor Detail

MutableValueBuffer

public MutableValueBuffer(int nvalues)
Create a new, empty byte[][] of the specified capacity.

Parameters:
nvalues - The capacity of the byte[][].

MutableValueBuffer

public MutableValueBuffer(int nvalues,
                          byte[][] values)
Create a view of a byte[][]. All elements in the array are visible in the view.

Parameters:
nvalues - The #of entries in the array with valid data.
values - The backing byte[][].

MutableValueBuffer

public MutableValueBuffer(int capacity,
                          IRaba src)
Builds a mutable value buffer.

Parameters:
capacity - The capacity of the new instance (this is based on the branching factor for the B+Tree).
src - The source data.
Throws:
IllegalArgumentException - if the capacity is LT the IRaba.size() of the src.
IllegalArgumentException - if the source is null.
Method Detail

isReadOnly

public final boolean isReadOnly()
Mutable.

Specified by:
isReadOnly in interface IRaba

isKeys

public final boolean isKeys()
For B+Tree values.

Specified by:
isKeys in interface IRaba
Returns:
true if the IRaba represents B+Tree keys and false if it represents B+Tree values.

size

public final int size()
Description copied from interface: IRaba
The #of entries in the logical byte[][].

Specified by:
size in interface IRaba

isEmpty

public final boolean isEmpty()
Description copied from interface: IRaba
True iff the logical byte[][] is empty.

Specified by:
isEmpty in interface IRaba

isFull

public final boolean isFull()
Description copied from interface: IRaba
True iff the logical byte[][] is full.

Specified by:
isFull in interface IRaba

capacity

public final int capacity()
Description copied from interface: IRaba
The capacity of the logical byte[][].

Specified by:
capacity in interface IRaba

rangeCheck

protected final boolean rangeCheck(int index)
                            throws IndexOutOfBoundsException
Throws:
IndexOutOfBoundsException

get

public final byte[] get(int index)
Description copied from interface: IRaba
Return the byte[] at the specified index. For greater efficiency, implementations MAY return a reference to an internal the byte[].

Specified by:
get in interface IRaba
Parameters:
index - The index in [0:IRaba.size()-1].
Returns:
The byte[] value at that index and null if a null value was stored at that index.

length

public final int length(int index)
Description copied from interface: IRaba
The length of the byte[] at that index.

Specified by:
length in interface IRaba
Parameters:
index - The index in [0:IRaba.size()-1].
Returns:
The length of the byte[] at that index.

isNull

public final boolean isNull(int index)
Description copied from interface: IRaba
Return true 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.

Specified by:
isNull in interface IRaba
Parameters:
index - The index in [0:IRaba.size()-1].

copy

public final int copy(int index,
                      OutputStream out)
Description copied from interface: IRaba
Copy the value at the specified index onto the output stream. This is often used with an ByteArrayBuffer so that the same backing byte[] can be overwritten by each visited key.

Specified by:
copy in interface IRaba
Parameters:
index - The index in [0:IRaba.size()-1].
Returns:
The #of bytes copied.

iterator

public final Iterator<byte[]> iterator()
Description copied from interface: IRaba
Iterator visits the byte[] elements in the view order. If an element is null, then the iterator will report a null for that element.

Specified by:
iterator in interface IRaba
Specified by:
iterator in interface Iterable<byte[]>

assertNotFull

protected void assertNotFull()
Throws:
IllegalStateException - unless there is room to store another value.

set

public void set(int index,
                byte[] key)
Description copied from interface: IRaba
Set the byte[] value at the specified index (optional operation).

Specified by:
set in interface IRaba
Parameters:
index - The index in [0:IRaba.size()-1].
key - The byte[] value.

add

public int add(byte[] key)
Description copied from interface: IRaba
Append a byte[] value to the end of the logical byte[][] (optional operation).

Specified by:
add in interface IRaba
Parameters:
key - A value.
Returns:
The #of values in the logical byte[][] (postcondition).

add

public int add(byte[] key,
               int off,
               int len)
Description copied from interface: IRaba
Append a byte[] value to the end of the logical byte[][] (optional operation).

Specified by:
add in interface IRaba
Parameters:
key - A value
off - The offset of the first byte to be copied.
len - The #of bytes to be copied.
Returns:
The #of values in the logical byte[][] (postcondition).

add

public int add(DataInput in,
               int len)
        throws IOException
Description copied from interface: IRaba
Append a byte[] value to the end of the logical byte[][] (optional operation).

Specified by:
add in interface IRaba
Parameters:
in - The input stream from which the byte[] will be read.
len - The #of bytes to be read.
Returns:
The #of values in the logical byte[][] (postcondition).
Throws:
IOException

search

public final int search(byte[] searchKey)
Description copied from interface: IRaba
Search for the given searchKey in the key buffer (optional operation). Whether or not search is supported depends on whether the logical byte[][] is ordered. However, the efficiency of search, where supported, depends on the implementation. Some implementations support binary search of the coded byte[] values. Others may require a mixture of binary and linear search, etc.

 entryIndex = -entryIndex - 1
 
or just
 entryIndex = -entryIndex
 
if you are looking for the first key after the searchKey.

Specified by:
search in interface IRaba
Parameters:
searchKey - The search key.
Returns:
index of the search key, if it is found; otherwise, (-(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.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.