Class BinaryTree
- java.lang.Object
-
- org.apache.commons.compress.archivers.zip.BinaryTree
-
class BinaryTree extends java.lang.ObjectBinary tree of positive values.- Since:
- 1.7
-
-
Constructor Summary
Constructors Constructor Description BinaryTree(int depth)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLeaf(int node, int path, int depth, int value)Adds a leaf to the tree.(package private) static BinaryTreedecode(java.io.InputStream inputStream, int totalNumberOfValues)Decodes the packed binary tree from the specified stream.intread(BitStream stream)Reads a value from the specified bit stream.
-
-
-
Field Detail
-
UNDEFINED
private static final int UNDEFINED
Value in the array indicating an undefined node- See Also:
- Constant Field Values
-
NODE
private static final int NODE
Value in the array indicating a non leaf node- See Also:
- Constant Field Values
-
tree
private final int[] tree
The array representing the binary tree. The root is at index 0, the left children are at 2*i+1 and the right children at 2*i+2.
-
-
Method Detail
-
addLeaf
public void addLeaf(int node, int path, int depth, int value)Adds a leaf to the tree.- Parameters:
node- the index of the node where the path is appendedpath- the path to the leaf (bits are parsed from the right to the left)depth- the number of nodes in the pathvalue- the value of the leaf (must be positive)
-
read
public int read(BitStream stream) throws java.io.IOException
Reads a value from the specified bit stream.- Parameters:
stream-- Returns:
- the value decoded, or -1 if the end of the stream is reached
- Throws:
java.io.IOException
-
decode
static BinaryTree decode(java.io.InputStream inputStream, int totalNumberOfValues) throws java.io.IOException
Decodes the packed binary tree from the specified stream.- Throws:
java.io.IOException
-
-