private DictHeadNode <Dictionary <string, object> > BuildFromDictionary(Dictionary <string, object> dict, PathSet paths) { var pathElem = paths.GetPathLeafOrElseAnyCurrentPathElement(); var keys = new List <string>(dict.Keys); if (keys.Count == 0) { return(new DictHeadNode <Dictionary <string, object> >(new EmptyLeaf(), new EmptyLeaf(), dict, 0, pathElem)); } keys.Sort(); var leafArray = this.BuildLeafElementFromDict(keys, dict, paths); var result = this.BuildHigherLayer(1, leafArray); var orgRoot = result[0]; if (orgRoot is Node) { var nodeRoot = (Node)orgRoot; return(new DictHeadNode <Dictionary <string, object> >(nodeRoot.Left, nodeRoot.Right, dict, keys.Count, pathElem)); } else { throw new System.Exception("Should not find element of this type here"); } }
private ArrayHeadNode <object[]> BuildFromArray(object[] array, PathSet paths) { var pathElem = paths.GetPathLeafOrElseAnyCurrentPathElement(); if (array.Length == 0) { return(new ArrayHeadNode <object[]>(new EmptyLeaf(), new EmptyLeaf(), array, 0, pathElem)); } var leafArray = this.BuildLeafElements(array, paths); var result = this.BuildHigherLayer(1, leafArray); var orgRoot = result[0]; if (orgRoot is Node) { var nodeRoot = (Node)orgRoot; return(new ArrayHeadNode <object[]>(nodeRoot.Left, nodeRoot.Right, array, array.Length, pathElem)); } if (orgRoot is Leaf) { return(this.BuildFromOneLeaf(array, orgRoot, pathElem)); } else { throw new System.Exception("Should not find element of this type here"); } }
private BinaryTreeElement HandlePrimitiveLeaf(object leaf, PathSet paths) { var pathElem = paths.GetPathLeafOrElseAnyCurrentPathElement(); if (pathElem != null && !(pathElem is PathLeafElement)) { throw new System.Exception("Path does not match the tree structure. We are at a leaf " + leaf + " but found path element " + pathElem); } return(new Leaf(leaf, pathElem)); }