Example #1
0
        private static EightTree BuildTree(List <int> Input)
        {
            //int nodeLength = 1 + metadataLength + subnodeLengths;
            int frontIndex = 0;
            int sum        = 0;

            EightNode root        = new EightNode(Input[frontIndex++], Input[frontIndex++]);
            EightNode currentNode = root;

            do
            {
                if (currentNode.ChildCount > 0 && currentNode.Children.Count != currentNode.ChildCount)
                {
                    // "recurse"
                    EightNode child = new EightNode(Input[frontIndex++], Input[frontIndex++]);
                    child.Parent = currentNode;
                    currentNode.Children.Add(child);
                    currentNode = child;
                }
                else if (currentNode.MetadataCount > 0 && currentNode.Metadata.Count != currentNode.MetadataCount)
                {
                    // read metadata
                    for (int i = 0; i < currentNode.MetadataCount; i++)
                    {
                        currentNode.Metadata.Add(Input[frontIndex++]);
                    }
                    sum        += currentNode.Metadata.Sum();
                    currentNode = currentNode.Parent;
                }
                else
                {
                    currentNode = currentNode.Parent;
                }
            }while (frontIndex < Input.Count);
            EightTree tree = new EightTree(root);

            tree.Sum = sum;
            return(tree);
        }
Example #2
0
 public EightTree(EightNode root)
 {
     Root = root;
 }