| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectpt.tumba.ngram.compression.ByteBuffer
public final class ByteBuffer
Stores a queue of bytes in a buffer with a maximum size. New bytes are added to the tail of the queue, and if the size exceeds the maximum, bytes are removed from the front of the queue. Used to model a sliding window of a fixed width over a stream of bytes presented a byte at a time. The bytes in the current window are accessed through an array of bytes, an offset and a length.
For instance, with a maximum length of 2, beginning with an
 empty buffer and adding bytes 1, 2, 3, and 4 in that order leads to
 queues {1}, {1,2}, {2,3} and
 {3,4}.
| Field Summary | |
|---|---|
| (package private)  byte[] | _bytesArray of bytes used to buffer incoming bytes. | 
| (package private)  int | _lengthNumber of bytes in the context. | 
| private  int | _maxWidthMaximum number of bytes in queue before adding pushes one off. | 
| (package private)  int | _offsetOffset of first byte of current context in buffer. | 
| private static int | BUFFER_SIZE_MULTIPLIERNumber of contexts that fit in the buffer without shifting. | 
| Constructor Summary | |
|---|---|
| ByteBuffer(int maxWidth)Construct a context buffer of given maximum size. | |
| Method Summary | |
|---|---|
|  void | buffer(byte b)Add a byte to the end of the context, removing first element if necessary. | 
|  byte[] | bytes()Current array of bytes backing this byte buffer. | 
|  int | length()Current length of this buffer. | 
| private  int | maxIndex()The maximum index in the buffer. | 
| private  int | nextFreeIndex()Index in the buffer for next element. | 
|  int | offset()Current offset of this buffer into the byte array. | 
| private  void | tampDown()Moves bytes in context down to start of buffer. | 
|  java.lang.String | toString()Return a string representation of this context using the current localization to convert bytes to characters. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
final byte[] _bytes
private final int _maxWidth
int _offset
int _length
private static final int BUFFER_SIZE_MULTIPLIER
| Constructor Detail | 
|---|
public ByteBuffer(int maxWidth)
maxWidth - Maximum number of bytes in a context.| Method Detail | 
|---|
public byte[] bytes()
public int offset()
public int length()
public void buffer(byte b)
b - Byte to push onto the tail of the context.public java.lang.String toString()
toString in class java.lang.Objectprivate int nextFreeIndex()
private int maxIndex()
Index - of last element in the buffer.private void tampDown()
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||