Private Member Functions | Private Attributes | List of all members
com.google.protobuf.RopeByteString.Balancer Class Reference

Private Member Functions

ByteString balance (ByteString left, ByteString right)
 
ByteString balance (ByteString left, ByteString right)
 
void doBalance (ByteString root)
 
void doBalance (ByteString root)
 
int getDepthBinForLength (int length)
 
int getDepthBinForLength (int length)
 
void insert (ByteString byteString)
 
void insert (ByteString byteString)
 

Private Attributes

final ArrayDeque< ByteStringprefixesStack = new ArrayDeque<>()
 

Detailed Description

This class implements the balancing algorithm of BAP95. In the paper the authors use an array to keep track of pieces, while here we use a stack. The tree is balanced by traversing subtrees in left to right order, and the stack always contains the part of the string we've traversed so far.

One surprising aspect of the algorithm is the result of balancing is not necessarily balanced, though it is nearly balanced. For details, see BAP95.

Definition at line 607 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java.

Member Function Documentation

◆ balance() [1/2]

ByteString com.google.protobuf.RopeByteString.Balancer.balance ( ByteString  left,
ByteString  right 
)
inlineprivate

◆ balance() [2/2]

ByteString com.google.protobuf.RopeByteString.Balancer.balance ( ByteString  left,
ByteString  right 
)
inlineprivate

◆ doBalance() [1/2]

void com.google.protobuf.RopeByteString.Balancer.doBalance ( ByteString  root)
inlineprivate

◆ doBalance() [2/2]

void com.google.protobuf.RopeByteString.Balancer.doBalance ( ByteString  root)
inlineprivate

◆ getDepthBinForLength() [1/2]

int com.google.protobuf.RopeByteString.Balancer.getDepthBinForLength ( int  length)
inlineprivate

◆ getDepthBinForLength() [2/2]

int com.google.protobuf.RopeByteString.Balancer.getDepthBinForLength ( int  length)
inlineprivate

◆ insert() [1/2]

void com.google.protobuf.RopeByteString.Balancer.insert ( ByteString  byteString)
inlineprivate

Push a string on the balance stack (BAP95). BAP95 uses an array and calls the elements in the array 'bins'. We instead use a stack, so the 'bins' of lengths are represented by differences between the elements of minLengthByDepth.

If the length bin for our string, and all shorter length bins, are empty, we just push it on the stack. Otherwise, we need to start concatenating, putting the given string in the "middle" and continuing until we land in an empty length bin that matches the length of our concatenation.

Parameters
byteStringstring to place on the balance stack

Definition at line 657 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java.

◆ insert() [2/2]

void com.google.protobuf.RopeByteString.Balancer.insert ( ByteString  byteString)
inlineprivate

Push a string on the balance stack (BAP95). BAP95 uses an array and calls the elements in the array 'bins'. We instead use a stack, so the 'bins' of lengths are represented by differences between the elements of minLengthByDepth.

If the length bin for our string, and all shorter length bins, are empty, we just push it on the stack. Otherwise, we need to start concatenating, putting the given string in the "middle" and continuing until we land in an empty length bin that matches the length of our concatenation.

Parameters
byteStringstring to place on the balance stack

Definition at line 678 of file protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java.

Member Data Documentation

◆ prefixesStack

final ArrayDeque< ByteString > com.google.protobuf.RopeByteString.Balancer.prefixesStack = new ArrayDeque<>()
private

The documentation for this class was generated from the following file:


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:07