/** * Adds a leaf to the tree. * * @param node the index of the node where the path is appended * @param path the path to the leaf (bits are parsed from the right to the left) * @param depth the number of nodes in the path * @param value the value of the leaf (must be positive) */ public void addLeaf(final int node, final int path, final int depth, final int value) { if (depth == 0) { // end of the path reached, add the value to the current node if (tree[node] == UNDEFINED) { tree[node] = value; } else { throw new IllegalArgumentException("Tree value at index " + node + " has already been assigned (" + tree[node] + ")"); } } else { // mark the current node as a non leaf node tree[node] = NODE; // move down the path recursively final int nextChild = 2 * node + 1 + (path & 1); addLeaf(nextChild, path >>> 1, depth - 1, value); } }
final int bitLength = originalBitLengths[k]; if (bitLength > 0) { tree.addLeaf(0, Integer.reverse(codes[k] << 16), bitLength, k);
/** * Adds a leaf to the tree. * * @param node the index of the node where the path is appended * @param path the path to the leaf (bits are parsed from the right to the left) * @param depth the number of nodes in the path * @param value the value of the leaf (must be positive) */ public void addLeaf(final int node, final int path, final int depth, final int value) { if (depth == 0) { // end of the path reached, add the value to the current node if (tree[node] == UNDEFINED) { tree[node] = value; } else { throw new IllegalArgumentException("Tree value at index " + node + " has already been assigned (" + tree[node] + ")"); } } else { // mark the current node as a non leaf node tree[node] = NODE; // move down the path recursively final int nextChild = 2 * node + 1 + (path & 1); addLeaf(nextChild, path >>> 1, depth - 1, value); } }
final int bitLength = originalBitLengths[k]; if (bitLength > 0) { tree.addLeaf(0, Integer.reverse(codes[k] << 16), bitLength, k);