I have an evaluating tree class. Each node has children in a strict order. A server has a list of such trees.
When a client successfully connects to the server, it sends a lot of different HashMaps
to a selected tree for computation. Typical HashMap
s have pairs: [Variable string name, Variable int value].
Each TreeNode
has a complex condition, which can read variables and has operations such as AND, OR, XOR, comparing with other variables or numbers. Each TreeNode
also has statements, which can read/write variables and put new variables to HashMap
s, which can subsequently be read/written in another TreeNode
.
Here is a simplified structure of the trees:
public static class TreeNode {
public static abstract class Condition {
public abstract boolean evaluate(HashMap<String, Integer> contex);
}
public static abstract class Statement {
public abstract void execute(HashMap<String, Integer> contex);
}
private Condition condition;
private List<Statement> statements;
private List<TreeNode> children;
public void run(final HashMap<String, Integer> contex) {
if (condition != null && !condition.evaluate(contex)) {
return;
}
for (final Statement statement : statements) {
statement.execute(contex);
}
for (final TreeNode child : children) {
child.run(contex);
}
}
}
My code currently performs about 200000 iterations/sec on an Intel i7 u3517 for a tree with 100 nodes and an input HashMap
with 10 variables. How can I speed it up?