1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.http2.hpack;
29
30 import java.util.Arrays;
31
32 import org.apache.hc.core5.util.Asserts;
33
34
35
36
37
38 final class HuffmanNode {
39
40 private final int symbol;
41 private final int bits;
42 private final HuffmanNode[] children;
43
44 HuffmanNode() {
45 this.symbol = 0;
46 this.bits = 8;
47 this.children = new HuffmanNode[256];
48 }
49
50 HuffmanNode(final int symbol, final int bits) {
51 this.symbol = symbol;
52 this.bits = bits;
53 this.children = null;
54 }
55
56 public int getBits() {
57 return this.bits;
58 }
59
60 public int getSymbol() {
61 return this.symbol;
62 }
63
64 public boolean hasChild(final int index) {
65 return this.children != null && this.children[index] != null;
66 }
67
68 public HuffmanNode getChild(final int index) {
69 return this.children != null ? this.children[index] : null;
70 }
71
72 void setChild(final int index, final HuffmanNode child) {
73 Asserts.notNull(this.children, "Children nodes");
74 this.children[index] = child;
75 }
76
77 public boolean isTerminal() {
78 return this.children == null;
79 }
80
81 @Override
82 public String toString() {
83 return "[" +
84 "symbol=" + symbol +
85 ", bits=" + bits +
86 ", children=" + Arrays.toString(children) +
87 ']';
88 }
89
90 }