protected boolean matchesExpressionTree(ExpNode root,ISpaceProxy space,Transaction txn,int readModifier,int max) throws SQLException {
  if (root == null)   return true;
  if (_traversalOrder != null) {
    for (int i=0; i < _traversalOrder.length; i++) {
      ExpNode node=_traversalOrder[i];
      if (i < _traversalOrder.length - 1)       node.accept(this,space,txn,readModifier,Integer.MAX_VALUE);
 else       node.accept(this,space,txn,readModifier,max);
    }
    return getResults(root);
  }
  Stack<ExpNode> stack=new Stack<ExpNode>();
  Stack<ExpNode> stack2=new Stack<ExpNode>();
  stack.push(root);
  while (!stack.isEmpty()) {
    ExpNode curr=stack.pop();
    if (!(curr instanceof ValueNode))     stack2.push(curr);
    if (curr.getTemplate() == null) {
      if (curr.getLeftChild() != null)       stack.push(curr.getLeftChild());
      if (curr.getRightChild() != null)       stack.push(curr.getRightChild());
    }
  }
  _traversalOrder=new ExpNode[stack2.size()];
  int index=0;
  while (!stack2.isEmpty()) {
    ExpNode node=stack2.pop();
    _traversalOrder[index++]=node;
    if (stack2.isEmpty())     node.accept(this,space,txn,readModifier,max);
 else     node.accept(this,space,txn,readModifier,Integer.MAX_VALUE);
  }
  return getResults(root);
}

protected boolean matchesExpressionTree ( ExpNode root , ISpaceProxy space , Transaction txn , int readModifier , int max ) throws SQLException { if ( root == null ) return true ; if ( _traversalOrder != null ) { for ( int i = 0 ; i < _traversalOrder . length ; i ++ ) { ExpNode node = _traversalOrder [ i ] ; if ( i < _traversalOrder . length - 1 ) node . accept ( this , space , txn , readModifier , Integer . MAX_VALUE ) ; else node . accept ( this , space , txn , readModifier , max ) ; } return getResults ( root ) ; } Stack < ExpNode > stack = new Stack < ExpNode > ( ) ; Stack < ExpNode > stack2 = new Stack < ExpNode > ( ) ; stack . push ( root ) ; while ( ! stack . isEmpty ( ) ) { ExpNode curr = stack . pop ( ) ; if ( ! ( curr instanceof ValueNode ) ) stack2 . push ( curr ) ; if ( curr . getTemplate ( ) == null ) { if ( curr . getLeftChild ( ) != null ) stack . push ( curr . getLeftChild ( ) ) ; if ( curr . getRightChild ( ) != null ) stack . push ( curr . getRightChild ( ) ) ; } } _traversalOrder = new ExpNode [ stack2 . size ( ) ] ; int index = 0 ; while ( ! stack2 . isEmpty ( ) ) { ExpNode node = stack2 . pop ( ) ; _traversalOrder [ index ++ ] = node ; if ( stack2 . isEmpty ( ) ) node . accept ( this , space , txn , readModifier , max ) ; else node . accept ( this , space , txn , readModifier , Integer . MAX_VALUE ) ; } return getResults ( root ) ; }
traverse the binary expression tree non - recursively using a custom stack the tree has to be traversed in postorder - the parent is traversed after its children .
