ByteTreeNode

This commit is contained in:
redkale
2024-10-05 16:04:08 +08:00
parent 04e539ab0f
commit a2ac9ff896

View File

@@ -15,14 +15,28 @@ package org.redkale.util;
*/ */
public class ByteTreeNode<T> { public class ByteTreeNode<T> {
protected final byte index;
protected final ByteTreeNode<T> parent;
protected T value; protected T value;
protected ByteTreeNode<T>[] nodes = new ByteTreeNode[127]; protected ByteTreeNode<T>[] nodes = new ByteTreeNode[127];
protected ByteTreeNode() {} protected ByteTreeNode() {
this(null, 0);
}
private ByteTreeNode(ByteTreeNode<T> parent, int index) {
this.parent = parent;
if (index < 0 || index >= nodes.length) {
throw new RedkaleException(index + " is illegal");
}
this.index = (byte) index;
}
public static <T> ByteTreeNode<T> create() { public static <T> ByteTreeNode<T> create() {
return new ByteTreeNode(); return new ByteTreeNode(null, 0);
} }
public ByteTreeNode<T> getNode(byte b) { public ByteTreeNode<T> getNode(byte b) {
@@ -33,6 +47,14 @@ public class ByteTreeNode<T> {
return ch >= nodes.length ? null : nodes[ch]; return ch >= nodes.length ? null : nodes[ch];
} }
public ByteTreeNode<T> getParent() {
return parent;
}
public byte getIndex() {
return index;
}
public T getValue() { public T getValue() {
return value; return value;
} }
@@ -56,7 +78,7 @@ public class ByteTreeNode<T> {
} }
ByteTreeNode s = n.nodes[ch]; ByteTreeNode s = n.nodes[ch];
if (s == null) { if (s == null) {
s = new ByteTreeNode(); s = new ByteTreeNode(n, ch);
n.nodes[ch] = s; n.nodes[ch] = s;
} }
n = s; n = s;