public MNode <TVal> EnsureNodeExist(string nodeSequenceCode) { using (base.SmartRWLocker.Lock(AccessMode.Write)) { MNode <TVal> nodeByPath = base.GetNodeByPath(nodeSequenceCode, this.sequenceCodeSplitter); if (nodeByPath != null) { return(nodeByPath); } string[] uppers = nodeSequenceCode.Split(new char[] { this.sequenceCodeSplitter }); if ((uppers[0] != base.Root.TheValue.CurrentID) || (uppers.Length < 2)) { return(null); } return(this.AppendOffSprings(nodeSequenceCode, uppers)); } }
private void DoGetNodesOnDepthIndex(ref IList <MNode <TVal> > list, MNode <TVal> curNode, int curDepthIndex, int targetDepthIndex) { if (curDepthIndex == (targetDepthIndex - 1)) { foreach (MNode <TVal> node in curNode.Children) { list.Add(node); } } else { foreach (MNode <TVal> node in curNode.Children) { this.DoGetNodesOnDepthIndex(ref list, node, curDepthIndex + 1, targetDepthIndex); } } }
private MNode <TVal> DoGetNode(MNode <TVal> curNode, string ValID) { foreach (MNode <TVal> node in curNode.Children) { if (node.TheValue.CurrentID == ValID) { return(node); } } foreach (MNode <TVal> node in curNode.Children) { MNode <TVal> node2 = this.DoGetNode(node, ValID); if (node2 != null) { return(node2); } } return(null); }
public virtual void Initialize(TVal rootVal, IList <TVal> members) { if ((rootVal == null) || (members == null)) { throw new Exception("Root must not be null!"); } this.root = new MNode <TVal>(rootVal, null); if (this.root.TheValue.DepthIndex != 0) { this.FillChildren(this.root, members); } else { IDictionary <int, IList <TVal> > dictionary = new Dictionary <int, IList <TVal> >(); foreach (TVal local in members) { if (local.DepthIndex < 0) { throw new Exception("Not all DepthIndex is Valid !"); } if (!dictionary.ContainsKey(local.DepthIndex)) { dictionary.Add(local.DepthIndex, new List <TVal>()); } dictionary[local.DepthIndex].Add(local); } IList <TVal>[] memberLayerAry = new IList <TVal> [dictionary.Count]; if (!dictionary.ContainsKey(0)) { dictionary.Add(0, new List <TVal>()); dictionary[0].Add(this.root.TheValue); } for (int i = 0; i < dictionary.Count; i++) { if (!dictionary.ContainsKey(i)) { throw new Exception("DepthIndex are not continuous !"); } memberLayerAry[i] = dictionary[i]; } this.InitializeFromLayer(memberLayerAry); } }
public IList <MNode <TVal> > GetNodesOnDepthIndex(string idPath, char separator, int depthIndex) { using (this.SmartRWLocker.Lock(AccessMode.Read)) { int num = idPath.Split(new char[] { separator }).Length - 1; if (num > depthIndex) { return(null); } MNode <TVal> nodeByPath = this.GetNodeByPath(idPath, separator); if (nodeByPath == null) { return(null); } MultiTree <TVal> tree = new MultiTree <TVal>(); tree.Initialize(nodeByPath); return(tree.GetNodesOnDepthIndex(depthIndex - num)); } }
private MNode <TVal> AppendOffSprings(string nodeSequenceCode, string[] uppers) { MNode <TVal> nodeByPath = base.GetNodeByPath(nodeSequenceCode, this.sequenceCodeSplitter); if (nodeByPath != null) { return(nodeByPath); } string idPath = uppers[0]; MNode <TVal> root = base.Root; for (int i = 1; i < uppers.Length; i++) { idPath = idPath + this.sequenceCodeSplitter + uppers[i]; MNode <TVal> node3 = base.GetNodeByPath(idPath, this.sequenceCodeSplitter); if (node3 == null) { return(this.DOAppendOffSprings(root, uppers, i)); } root = node3; } return(root); }
public virtual void Initialize(MNode <TVal> _rootNode) { this.root = _rootNode; }