@@ -0,0 +1,2985 @@
+package com.stapleslabs.tree;%0A%0Aimport java.nio.ByteBuffer;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0A/**%0A * Created by timbrooks on 4/28/15.%0A */%0Apublic class Forest2 implements Forest%3CInteger, double%5B%5D%3E %7B%0A%0A    private final ByteBuffer newForest;%0A    private final int%5B%5D roots;%0A    private final SpecializedCondition condition;%0A%0A    public Forest2(ByteBuffer newForest, int%5B%5D roots, SpecializedCondition condition) %7B%0A        this.newForest = newForest;%0A        this.roots = roots;%0A        this.condition = condition;%0A    %7D%0A%0A%0A    @Override%0A    public double%5B%5D reduceToValues(double%5B%5D features) %7B%0A        double%5B%5D values = new double%5Broots.length%5D;%0A        for (int i = 0; i %3C roots.length; i++) %7B%0A            values%5Bi%5D = traverseSingleTree(roots%5Bi%5D, features);%0A        %7D%0A        return values;%0A    %7D%0A%0A    @Override%0A    public Forest%3CInteger, double%5B%5D%3E reduceToForest(double%5B%5D features, Set%3CInteger%3E missingFeatures) %7B%0A        throw new UnsupportedOperationException(%22Not allowed%22);%0A    %7D%0A%0A    @Override%0A    public double%5B%5D%5B%5D optimizedReduceToValues(List%3Cdouble%5B%5D%3E features, Set%3CInteger%3E differingFeatures) %7B%0A        throw new UnsupportedOperationException(%22Not allowed%22);%0A    %7D%0A%0A    @Override%0A    public int%5B%5D getRoots() %7B%0A        return roots;%0A    %7D%0A%0A    @Override%0A    public Node%3CInteger, double%5B%5D%3E%5B%5D getNodes() %7B%0A        throw new UnsupportedOperationException(%22Not allowed%22);%0A    %7D%0A%0A    public static %3CC%3E Forest2 createFromForest(Forest%3CInteger, C%3E forest, double%5B%5D cutPoints) %7B%0A        Node%3CInteger, C%3E%5B%5D nodes = forest.getNodes();%0A        int maxChildren = 2;%0A%0A        int nodeSize =  2 + 4 + 8 + (maxChildren * 4) + 8;%0A        ByteBuffer newForest = ByteBuffer.allocate(nodeSize * nodes.length);%0A%0A        int%5B%5D roots = forest.getRoots();%0A        int i = 0;%0A        for (Node%3CInteger, C%3E node : nodes) %7B%0A            int offset = i * 22;%0A            short isLeaf = 1;%0A            short isNotLeaf = 0;%0A            newForest.putShort(node.isLeaf ? isLeaf : isNotLeaf);%0A            newForest.putInt(node.feature);%0A            newForest.putDouble(cutPoints%5Bi%5D);%0A            int%5B%5D childOffsets = node.childOffsets;%0A            for (int childOffset : childOffsets) %7B%0A                newForest.putInt(childOffset);%0A            %7D%0A            newForest.putDouble(node.value);%0A            ++i;%0A        %7D%0A        return new Forest2(newForest, roots, new SpecializedCondition());%0A    %7D%0A%0A    private double traverseSingleTree(int root, double%5B%5D features) %7B%0A        int nodeOffset = root * 30;%0A        while (newForest.getShort(nodeOffset) != 1) %7B%0A            int feature = newForest.getInt(nodeOffset + 2);%0A            double cutPoint = newForest.getDouble(nodeOffset + 6);%0A            int childOffset = condition.childOffset(cutPoint, feature, features);%0A            int offset = (childOffset == 0) ? newForest.getInt(nodeOffset + 14) : newForest.getInt(nodeOffset + 18);%0A            nodeOffset = root + (offset * 30);%0A        %7D%0A        return newForest.getDouble(nodeOffset + 22);%0A    %7D%0A%7D%0A

Add byte buffer version