Ejemplo n.º 1
0
  /**
   * Adds a child to this node. If possible will merge, and will perform a deep copy of the child
   * tree.
   *
   * @param newChild the new child to add (will be cloned)
   * @param addingTo the tree that this node belongs to
   */
  public final void addChild(Splitter newChild, ADTree addingTo) {

    // search for an equivalent child
    Splitter oldEqual = null;
    for (Enumeration<Splitter> e = children(); e.hasMoreElements(); ) {
      Splitter split = e.nextElement();
      if (newChild.equalTo(split)) {
        oldEqual = split;
        break;
      }
    }
    if (oldEqual == null) { // didn't find one so just add
      Splitter addChild = (Splitter) newChild.clone();
      setOrderAddedSubtree(addChild, addingTo);
      children.add(addChild);
    } else { // found one, so do a merge
      for (int i = 0; i < newChild.getNumOfBranches(); i++) {
        PredictionNode oldPred = oldEqual.getChildForBranch(i);
        PredictionNode newPred = newChild.getChildForBranch(i);
        if (oldPred != null && newPred != null) {
          oldPred.merge(newPred, addingTo);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Sets the order added values of the subtree rooted at this splitter node.
   *
   * @param addChild the root of the subtree
   * @param addingTo the tree that this node will belong to
   */
  private final void setOrderAddedSubtree(Splitter addChild, ADTree addingTo) {

    addChild.orderAdded = addingTo.nextSplitAddedOrder();
    for (int i = 0; i < addChild.getNumOfBranches(); i++) {
      PredictionNode node = addChild.getChildForBranch(i);
      if (node != null) {
        for (Enumeration<Splitter> e = node.children(); e.hasMoreElements(); ) {
          setOrderAddedSubtree(e.nextElement(), addingTo);
        }
      }
    }
  }