ByteStrings formed by concatenation of other ByteStrings, without
copying the data in the pieces. The concatenation is represented as a tree whose leaf nodes are
each a com.google.protobuf.ByteString.LeafByteString .
Most of the operation here is inspired by the now-famous paper BAP95 Ropes: an Alternative to Strings hans-j. boehm, russ atkinson and michael plass
The algorithms described in the paper have been implemented for character strings in com.google.common.string.Rope and in the c++ class cord.cc.
Fundamentally the Rope algorithm represents the collection of pieces as a binary tree. BAP95 uses a Fibonacci bound relating depth to a minimum sequence length, sequences that are too short relative to their depth cause a tree rebalance. More precisely, a tree of depth d is "balanced" in the terminology of BAP95 if its length is at least F(d+2), where F(n) is the n-the Fibonacci number. Thus for depths 0, 1, 2, 3, 4, 5,... we have minimum lengths 1, 2, 3, 5, 8, 13,...
| Modifier and Type | Class and Description |
|---|---|
| private static class | RopeByteString.Balancer
This class implements the balancing algorithm of BAP95. |
| private static class | RopeByteString.PieceIterator
This class is a continuable tree traversal, which keeps the state information which would exist on the stack in a recursive traversal instead on a stack of "Bread Crumbs". |
| private class | RopeByteString.RopeInputStream
This class is the |
| Modifier and Type | Field and Description |
|---|---|
| private final ByteString | |
| private final int | |
| private static final int[] | minLengthByDepth
BAP95. |
| private final ByteString | |
| private static final long | |
| private final int | |
| private final int |
| Access | Constructor and Description |
|---|---|
| private | RopeByteString(ByteString
string on the left of this node, should have left, ByteString size() > 0string on the right of this node, should have right)size() > 0Create a new RopeByteString, which can be thought of as a new tree node, by recording references to the two given strings. |
| Modifier and Type | Method and Description |
|---|---|
| public ByteBuffer | asReadOnlyByteBuffer()
Implements abstract com. java.nio.ByteBuffer whose content is equal to the contents of
this byte string.
|
| public List | asReadOnlyByteBufferList()
Implements abstract com. java.nio.ByteBuffer objects such that the concatenation
of their contents is equal to the contents of this byte string.
|
| public byte | Returns: the valueindex of byte index)Implements abstract com. |
| pack-priv static ByteString | Returns: concatenation representing the same sequence as the given stringsstring on the left left, ByteString string on the right right)Concatenate the given strings while performing various optimizations to slow the growth rate of tree depth and tree node count. |
| private static ByteString | Returns: string formed by copying data bytesstring on the left left, ByteString string on the right right)Concatenates two strings by copying data values. |
| public void | copyTo(ByteBuffer
ByteBuffer to copy into. target)Implements abstract com. |
| protected void | copyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy)
Implements abstract com. copyTo(byte[], int, int, int).
|
| public boolean | equals(Object
the reference object with which to compare. other)Implements abstract com. |
| private boolean | Returns: true if the values of this string equals the value of the given onestring of the same length as this one other)Determines if this string is equal to another of the same length by iterating over the leaf nodes. |
| protected int | getTreeDepth()
Implements abstract com. ByteString, if any, whose root is this
node.
|
| pack-priv byte | internalByteAt(int
index of byte index)Implements abstract com. |
| protected boolean | Returns: true if the tree is balancedImplements abstract com. |
| public boolean | isValidUtf8()
Implements abstract com. ByteString represents a well-formed UTF-8 byte sequence, such that
the original bytes can be converted to a String object and then round tripped back to bytes
without loss.
|
| public ByteString. | iterator()
Overrides com. Implements java. ByteString. over the bytes in the ByteString.
|
| public CodedInputStream | newCodedInput()
Implements abstract com. CodedInputStream which can be used to read the bytes.
|
| public InputStream | newInput()
Implements abstract com. InputStream which can be used to read the bytes.
|
| pack-priv static RopeByteString | Returns: an unsafe instance for testing onlystring on the left of this node left, ByteString string on the right of this node right)Create a new RopeByteString for testing only while bypassing all the defenses of |
| protected int | partialHash(int
starting hash value h, int offset into this value to start looking at data values offset, int number of data values to include in the hash computation length)Implements abstract com. |
| protected int | partialIsValidUtf8(int
either state, int 0 (if this is the initial decoding operation) or the value returned
from a call to a partial decoding method for the previous bytesoffset of the first byte to check offset, int number of bytes to check length)Implements abstract com. |
| private void | |
| public int | |
| public ByteString | Returns: substring leaf node or treestart at this index beginIndex, int the last character is the one before this index endIndex)Implements abstract com. |
| protected String | toStringInternal(Charset
encode using this charset charset)Implements abstract com. String by decoding the bytes using the specified charset.
|
| pack-priv Object | |
| public void | writeTo(OutputStream
the output stream to which to write the data. outputStream)Implements abstract com. |
| pack-priv void | writeTo(ByteOutput
the output target to receive the bytes output)Implements abstract com. ByteString to the provided ByteOutput.
|
| pack-priv void | writeToInternal(OutputStream out, int sourceOffset, int numberToWrite)
Implements abstract com. writeTo(OutputStream, int, int) that assumes all error checking has
already been done.
|