|
1 | 1 | package algorithms.orthogonalRangeSearching;
|
2 | 2 |
|
| 3 | +/** |
| 4 | + * This class is the node class for building a range tree. |
| 5 | + * @param <T> Generic type of the node class |
| 6 | + */ |
3 | 7 | public class RangeTreeNode<T> {
|
4 |
| - T val; |
5 |
| - int height; |
6 |
| - RangeTreeNode<T> left = null; |
7 |
| - RangeTreeNode<T> right = null; |
8 |
| - RangeTreeNode<T> parent = null; |
9 |
| - RangeTreeNode<T> yTree = null; |
10 |
| - |
11 |
| - public RangeTreeNode(T val) { |
12 |
| - this.val = val; |
13 |
| - } |
14 |
| - |
15 |
| - public RangeTreeNode(T val, RangeTreeNode<T> left, RangeTreeNode<T> right) { |
16 |
| - this.val = val; |
17 |
| - this.left = left; |
18 |
| - this.right = right; |
19 |
| - } |
20 |
| - |
21 |
| - public T getVal() { |
22 |
| - return this.val; |
23 |
| - } |
24 |
| - |
25 |
| - public int getHeight() { |
26 |
| - return this.height; |
27 |
| - } |
28 |
| - |
29 |
| - public RangeTreeNode<T> getLeft() { |
30 |
| - return this.left; |
31 |
| - } |
32 |
| - |
33 |
| - public RangeTreeNode<T> getRight() { |
34 |
| - return this.right; |
35 |
| - } |
36 |
| - |
37 |
| - public RangeTreeNode<T> getParent() { |
38 |
| - return this.parent; |
39 |
| - } |
40 |
| - |
41 |
| - public RangeTreeNode<T> getYTree() { |
42 |
| - return this.yTree; |
43 |
| - } |
44 |
| - |
45 |
| - public void setVal(T val) { |
46 |
| - this.val = val; |
47 |
| - } |
48 |
| - |
49 |
| - public void setLeft(RangeTreeNode<T> left) { |
50 |
| - this.left = left; |
51 |
| - } |
52 |
| - |
53 |
| - public void setRight(RangeTreeNode<T> right) { |
54 |
| - this.right = right; |
55 |
| - } |
56 |
| - |
57 |
| - public void setParent(RangeTreeNode<T> parent) { |
58 |
| - this.parent = parent; |
59 |
| - } |
60 |
| - |
61 |
| - public void setHeight(int height) { |
62 |
| - this.height = height; |
63 |
| - } |
64 |
| - |
65 |
| - public void setYTree(RangeTreeNode<T> yTree) { |
66 |
| - this.yTree = yTree; |
67 |
| - } |
68 |
| - |
69 |
| - @Override |
70 |
| - public boolean equals(Object other) { |
71 |
| - if (other == this) { |
72 |
| - return true; |
73 |
| - } |
74 |
| - if (!(other instanceof RangeTreeNode)) { |
75 |
| - return false; |
76 |
| - } |
77 |
| - RangeTreeNode<T> node = (RangeTreeNode<T>) other; |
78 |
| - return this.val == node.val; |
79 |
| - } |
80 |
| - |
81 |
| - @Override |
82 |
| - public String toString() { |
83 |
| - return String.valueOf(this.val); |
84 |
| - } |
| 8 | + private T val; |
| 9 | + private int height; |
| 10 | + private RangeTreeNode<T> left = null; |
| 11 | + private RangeTreeNode<T> right = null; |
| 12 | + private RangeTreeNode<T> parent = null; |
| 13 | + private RangeTreeNode<T> yTree = null; |
| 14 | + |
| 15 | + public RangeTreeNode(T val) { |
| 16 | + this.val = val; |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor for range tree node |
| 21 | + * @param val value of node |
| 22 | + * @param left left child of node |
| 23 | + * @param right right child of node |
| 24 | + */ |
| 25 | + public RangeTreeNode(T val, RangeTreeNode<T> left, RangeTreeNode<T> right) { |
| 26 | + this.val = val; |
| 27 | + this.left = left; |
| 28 | + this.right = right; |
| 29 | + } |
| 30 | + |
| 31 | + public T getVal() { |
| 32 | + return this.val; |
| 33 | + } |
| 34 | + |
| 35 | + public int getHeight() { |
| 36 | + return this.height; |
| 37 | + } |
| 38 | + |
| 39 | + public RangeTreeNode<T> getLeft() { |
| 40 | + return this.left; |
| 41 | + } |
| 42 | + |
| 43 | + public RangeTreeNode<T> getRight() { |
| 44 | + return this.right; |
| 45 | + } |
| 46 | + |
| 47 | + public RangeTreeNode<T> getParent() { |
| 48 | + return this.parent; |
| 49 | + } |
| 50 | + |
| 51 | + public RangeTreeNode<T> getYTree() { |
| 52 | + return this.yTree; |
| 53 | + } |
| 54 | + |
| 55 | + public void setVal(T val) { |
| 56 | + this.val = val; |
| 57 | + } |
| 58 | + |
| 59 | + public void setLeft(RangeTreeNode<T> left) { |
| 60 | + this.left = left; |
| 61 | + } |
| 62 | + |
| 63 | + public void setRight(RangeTreeNode<T> right) { |
| 64 | + this.right = right; |
| 65 | + } |
| 66 | + |
| 67 | + public void setParent(RangeTreeNode<T> parent) { |
| 68 | + this.parent = parent; |
| 69 | + } |
| 70 | + |
| 71 | + public void setHeight(int height) { |
| 72 | + this.height = height; |
| 73 | + } |
| 74 | + |
| 75 | + public void setYTree(RangeTreeNode<T> yTree) { |
| 76 | + this.yTree = yTree; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public boolean equals(Object other) { |
| 81 | + if (other == this) { |
| 82 | + return true; |
| 83 | + } |
| 84 | + if (!(other instanceof RangeTreeNode)) { |
| 85 | + return false; |
| 86 | + } |
| 87 | + RangeTreeNode<T> node = (RangeTreeNode<T>) other; |
| 88 | + return this.val == node.val; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public String toString() { |
| 93 | + return String.valueOf(this.val); |
| 94 | + } |
85 | 95 |
|
86 | 96 | }
|
0 commit comments