public void AddChild(TreeGraph node) { children.Add(node); }
public TreeGraph CreateGraph() { CheckErrorState(); // Create the header node TreeGraph headerGraph = new TreeGraph("header", headerId); // Get the header area IArea headerArea = store.GetArea(headerId); headerArea.Position = 8; // Read the versions list, long versionListRef = headerArea.ReadInt8(); // Create the version node TreeGraph versions_node = new TreeGraph("versions_list", versionListRef); // Set this as a child to the header headerGraph.AddChild(versions_node); // Read the versions list area // magic(int), versions count(int), list of version id objects. IArea versArea = store.GetArea(versionListRef); if (versArea.ReadInt4() != 0x01433) throw new IOException("Incorrect magic value 0x01433"); int vers_count = versArea.ReadInt4(); // For each id from the versions area, read in the associated VersionInfo // object into the 'vers' array. for (int i = 0; i < vers_count; ++i) { long vInfoRef = versArea.ReadInt8(); // Set up the information in our node TreeGraph vInfoGraph = new TreeGraph("version", vInfoRef); // Read in the version information node IArea vInfoArea = store.GetArea(vInfoRef); int magic = vInfoArea.ReadInt4(); int ver = vInfoArea.ReadInt4(); long versionId = vInfoArea.ReadInt8(); long rootNodeRef = vInfoArea.ReadInt8(); vInfoGraph.SetProperty("magic", magic); vInfoGraph.SetProperty("ver", ver); vInfoGraph.SetProperty("version_id", versionId); // Make the deleted area list into a property int deleted_area_count = vInfoArea.ReadInt4(); if (deleted_area_count > 0) { for (int n = 0; n < deleted_area_count; ++n) { long delNodeRef = vInfoArea.ReadInt8(); vInfoGraph.AddChild(new TreeGraph("delete", delNodeRef)); } } // Add the child node (the root node of the version graph). vInfoGraph.AddChild(CreateRootGraph(Key.Head, rootNodeRef)); // Add this to the version list node versions_node.AddChild(vInfoGraph); } // Return the header node return headerGraph; }
private TreeGraph CreateRootGraph(Key leftKey, long reference) { // The node being returned TreeGraph graph; // Open the area IArea area = store.GetArea(reference); // What type of node is this? short nodeType = area.ReadInt2(); // The version short ver = area.ReadInt2(); if (nodeType == LeafType) { // Read the reference count, long refCount = area.ReadInt4(); // The number of bytes in the leaf int leafSize = area.ReadInt4(); // Set up the leaf node object graph = new TreeGraph("leaf", reference); graph.SetProperty("ver", ver); graph.SetProperty("key", leftKey.ToString()); graph.SetProperty("reference_count", refCount); graph.SetProperty("leaf_size", leafSize); } else if (nodeType == BranchType) { // The data size area containing the children information int childDataSize = area.ReadInt4(); long[] data = new long[childDataSize]; for (int i = 0; i < childDataSize; ++i) { data[i] = area.ReadInt8(); } // Create the TreeBranch object to query it TreeBranch branch = new TreeBranch(reference, data, childDataSize); // Set up the branch node object graph = new TreeGraph("branch", reference); graph.SetProperty("ver", ver); graph.SetProperty("key", leftKey.ToString()); graph.SetProperty("branch_size", branch.ChildCount); // Recursively add each child into the tree for (int i = 0; i < branch.ChildCount; ++i) { long child_ref = branch.GetChild(i); // If the ref is a special node, skip it if ((child_ref & 0x01000000000000000L) != 0) { // Should we record special nodes? } else { Key newLeftKey = (i > 0) ? branch.GetKey(i) : leftKey; TreeGraph bn = new TreeGraph("child_meta", reference); bn.SetProperty("extent", branch.GetChildLeafElementCount(i)); graph.AddChild(bn); graph.AddChild(CreateRootGraph(newLeftKey, child_ref)); } } } else { throw new IOException("Unknown node type: " + nodeType); } return graph; }