Class BinaryTree


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

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

      Constructors 
      Constructor Description
      BinaryTree​(int depth)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      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​(java.io.InputStream in, 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 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.
    • Constructor Detail

      • BinaryTree

        public BinaryTree​(int depth)
    • 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 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 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 in,
                                 int totalNumberOfValues)
                          throws java.io.IOException
        Decodes the packed binary tree from the specified stream.
        Throws:
        java.io.IOException