Class BinaryTree

java.lang.Object
org.apache.commons.compress.archivers.zip.BinaryTree

class BinaryTree extends Object
Binary tree of positive values.
Since:
1.7
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Value in the array indicating a non leaf node
    private final int[]
    The array representing the binary tree.
    private static final int
    Value in the array indicating an undefined node
  • Constructor Summary

    Constructors
    Constructor
    Description
    BinaryTree(int depth)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addLeaf(int node, int path, int depth, int value)
    Adds a leaf to the tree.
    (package private) static BinaryTree
    decode(InputStream inputStream, int totalNumberOfValues)
    Decodes the packed binary tree from the specified stream.
    int
    read(BitStream stream)
    Reads a value from the specified bit stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNDEFINED

      private static final int UNDEFINED
      Value in the array indicating an undefined node
      See Also:
    • NODE

      private static final int NODE
      Value in the array indicating a non leaf node
      See Also:
    • 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.
  • Constructor Details

    • BinaryTree

      public BinaryTree(int depth)
  • Method Details

    • 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 appended
      path - the path to the leaf (bits are parsed from the right to the left)
      depth - the number of nodes in the path
      value - the value of the leaf (must be positive)
    • read

      public int read(BitStream stream) throws 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:
      IOException
    • decode

      static BinaryTree decode(InputStream inputStream, int totalNumberOfValues) throws IOException
      Decodes the packed binary tree from the specified stream.
      Throws:
      IOException