com.bigdata.btree.raba
Class AbstractRaba

java.lang.Object
  extended by com.bigdata.btree.raba.AbstractRaba
All Implemented Interfaces:
IRaba, Iterable<byte[]>
Direct Known Subclasses:
MutableKeysRaba, MutableValuesRaba, ReadOnlyKeysRaba, ReadOnlyValuesRaba

public abstract class AbstractRaba
extends Object
implements IRaba

Abstract base class implements mutation operators and search. A concrete subclass need only indicate if it is mutable, searchable, or allows nulls by overriding the appropriate methods.

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

Field Summary
protected  byte[][] a
          The backing array.
protected  int capacity
          The maximum #of elements in the view of the backing array.
protected  int fromIndex
          The inclusive lower bound of the view.
protected  int toIndex
          The exclusive upper bound of the view.
 
Constructor Summary
AbstractRaba(byte[][] a)
          Create a view of a byte[][].
AbstractRaba(int fromIndex, int toIndex, int capacity, byte[][] a)
          Create a view from a slice of a byte[][].
 
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()
           
protected  void assertNotReadOnly()
           
protected  void assertNullAllowed(byte[] a)
           
 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 isNull(int index)
          Return true iff the byte[] at that index is null.
 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)
           
 AbstractRaba resize(int n)
          Resize the buffer, copying up to n references to the existing data into a new view backed by a new byte[][].
 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()
           
static String toString(IRaba raba)
          If IRaba.isKeys() is true then represents the elements as unsigned byte[]s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.bigdata.btree.raba.IRaba
isKeys, isReadOnly
 

Field Detail

fromIndex

protected final int fromIndex
The inclusive lower bound of the view.


toIndex

protected int toIndex
The exclusive upper bound of the view.

Note: This field is NOT final since it is modified by a subclass which permits mutation.


capacity

protected final int capacity
The maximum #of elements in the view of the backing array.


a

protected final byte[][] a
The backing array.

Constructor Detail

AbstractRaba

public AbstractRaba(byte[][] a)
Create a view of a byte[][]. All elements in the array are visible in the view.

Parameters:
a - The backing byte[][].

AbstractRaba

public AbstractRaba(int fromIndex,
                    int toIndex,
                    int capacity,
                    byte[][] a)
Create a view from a slice of a byte[][].

Parameters:
fromIndex - The index of the first element in the byte[][] which is visible in the view (inclusive lower bound).
toIndex - The index of the first element in the byte[][] beyond the view (exclusive upper bound).
capacity - The #of elements which may be used in the view.
a - The backing byte[][].
Method Detail

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[]>

assertNotReadOnly

protected void assertNotReadOnly()
Throws:
UnsupportedOperationException - if the view is read-only.

assertNotFull

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

assertNullAllowed

protected void assertNullAllowed(byte[] a)
Parameters:
a - A byte[] to be inserted or set on the IRaba.
Throws:
IllegalArgumentException - if the byte[] is null and the implementation does not permit nulls to be stored.

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 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

toString

public static String toString(IRaba raba)
If IRaba.isKeys() is true then represents the elements as unsigned byte[]s. Otherwise represents the elements as signed byte[]s.


resize

public AbstractRaba resize(int n)
Resize the buffer, copying up to n references to the existing data into a new view backed by a new byte[][]. fromIndex will be zero in the new view.

This method requires a public constructor with the following signature:

 ctor(byte[][])
 

Parameters:
n - The size of the new buffer.
Returns:
The new view, backed by a new byte[][].
Throws:
IllegalArgumentException - if n is negative.
RuntimeException - if the AbstractRaba instance does not declare an appropriate ctor.
TODO:
redefine as slice() (view onto the same data) and copy(int n)?


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