// Path: src/main/java/org/extratrees/data/Row.java
// public interface Row {
// 	public double get(int col);
// }


import java.io.Serializable;
import java.util.Set;
import org.extratrees.data.Row;
package org.extratrees;



/**
 * All subclasses should have their generic argument equal to itself, 
 * i.e. X extends AbstractBinaryTree<X>.
 * Otherwise getItself() will break. 
 * 
 * @author Jaak Simm
 *
 * @param <T> class that extends ABT
 * @param <D> class of value
 */
public abstract class AbstractBinaryTree <T extends AbstractBinaryTree<T, D>, D> implements Serializable {
	private static final long serialVersionUID = 5530548509407016040L;
	
	/** tree for elements below threshold.
	 * if left==null, it is a leaf node
     * if left!=null, not a leaf
	 *  */
	public T left;
	/** tree for elements equal or above threshold. */
	public T right;

	/** number of elements in the tree */
	public int    nSuccessors;
	/** feature ID used for cutting */
	public int    column=-1;
	/** threshold of cutting */
	public double threshold;
	/** value of the node (estimated by its samples).
	 *  Non-leaf nodes (may) also store value, allowing to change size of final nodes on-the-fly. */
	public D      value;

	/** tasks that are active in this thread */
	Set<Integer> tasks;
	
	public abstract D getNA();
	
	/** @return value of current node */
	public D getValue() {
		return value;
	}
	
	/**
	 * @param input the vector of input values
	 * @return the leaf node (BinaryTree) for the input
	 */
// Path: src/main/java/org/extratrees/data/Row.java
// public interface Row {
// 	public double get(int col);
// }


// Path: src/main/java/org/extratrees/AbstractBinaryTree.java
import java.io.Serializable;
import java.util.Set;
import org.extratrees.data.Row;

package org.extratrees;



/**
 * All subclasses should have their generic argument equal to itself, 
 * i.e. X extends AbstractBinaryTree<X>.
 * Otherwise getItself() will break. 
 * 
 * @author Jaak Simm
 *
 * @param <T> class that extends ABT
 * @param <D> class of value
 */
public abstract class AbstractBinaryTree <T extends AbstractBinaryTree<T, D>, D> implements Serializable {
	private static final long serialVersionUID = 5530548509407016040L;
	
	/** tree for elements below threshold.
	 * if left==null, it is a leaf node
     * if left!=null, not a leaf
	 *  */
	public T left;
	/** tree for elements equal or above threshold. */
	public T right;

	/** number of elements in the tree */
	public int    nSuccessors;
	/** feature ID used for cutting */
	public int    column=-1;
	/** threshold of cutting */
	public double threshold;
	/** value of the node (estimated by its samples).
	 *  Non-leaf nodes (may) also store value, allowing to change size of final nodes on-the-fly. */
	public D      value;

	/** tasks that are active in this thread */
	Set<Integer> tasks;
	
	public abstract D getNA();
	
	/** @return value of current node */
	public D getValue() {
		return value;
	}
	
	/**
	 * @param input the vector of input values
	 * @return the leaf node (BinaryTree) for the input
	 */
	public T getLeaf(Row input) {