Package com.singularsys.jep.walkers
Class TreeAnalyzer
java.lang.Object
com.singularsys.jep.walkers.PostfixTreeWalker
com.singularsys.jep.walkers.TreeAnalyzer
Analyze an expression, counting the number of nodes of each type, and recording which variables,
functions and operators occurred in the expression.
-
Constructor Summary
ConstructorDescriptionCreates an empty tree analyser.TreeAnalyzer
(Node node) Create a new instance and Analyze the node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Analyze a node, results will be added to the current total.A map with each constant and the number of times it occursA map with each function used and the number of times it occurredint
The depth of the treeint
int
int
int
int
int
A map with each operator used and the number of times it occurredString[]
Return the names of the variables, sorted alphabetically.A map with each variable used and the number of times it occurredvoid
merge
(TreeAnalyzer ta) Merge the result with the argument, producing total for all trees.summary()
A short summary stringtoString()
Reports statistics about the tree, number of nodes, depth, and the number of variables, functions, operators and constants with the number of times each occurs.protected void
visit
(ASTConstant node, int nchildren, int depth) Visit a constant nodeprotected void
visit
(ASTFunNode node, int nchildren, int depth) Visit a function nodeprotected void
Visit an operator nodeprotected void
visit
(ASTVarNode node, int nchildren, int depth) Visit a variable nodeMethods inherited from class com.singularsys.jep.walkers.PostfixTreeWalker
suppressExaminingChildren, walk, walkSubEquations
-
Constructor Details
-
TreeAnalyzer
Create a new instance and Analyze the node.- Parameters:
node
- node to analyze- Throws:
JepException
-
TreeAnalyzer
public TreeAnalyzer()Creates an empty tree analyser. Useful for producing combined statistics via themerge(TreeAnalyzer)
method.
-
-
Method Details
-
analyze
Analyze a node, results will be added to the current total.- Parameters:
node
-- Throws:
JepException
-
toString
Reports statistics about the tree, number of nodes, depth, and the number of variables, functions, operators and constants with the number of times each occurs. -
summary
A short summary string- Returns:
- a one line summary
-
visit
Description copied from class:PostfixTreeWalker
Visit a function node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.
-
visit
Description copied from class:PostfixTreeWalker
Visit an operator node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.
-
visit
Description copied from class:PostfixTreeWalker
Visit a variable node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.
-
visit
Description copied from class:PostfixTreeWalker
Visit a constant node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.
-
getMaxDepth
public int getMaxDepth()The depth of the tree- Returns:
- depth, depth of root node is 1
-
getNumConst
public int getNumConst() -
getNumFunctions
public int getNumFunctions() -
getNumNodes
public int getNumNodes() -
getNumOperators
public int getNumOperators() -
getNumVariables
public int getNumVariables() -
getNumUniqueVariables
public int getNumUniqueVariables() -
getOperators
A map with each operator used and the number of times it occurred- Returns:
- a map whose keys are the operators and the values are the number of occurrences
-
getVariables
A map with each variable used and the number of times it occurred- Returns:
- a map whose keys are the variables and the values are the number of occurrences
-
getVariableNames
Return the names of the variables, sorted alphabetically.- Returns:
- an array of variable names
-
getFunctions
A map with each function used and the number of times it occurred -
getConstants
A map with each constant and the number of times it occurs -
merge
Merge the result with the argument, producing total for all trees.- Parameters:
ta
-
-