private bool m_InsertBranch(T2 child) { if (ContainBranch(child)) { return(false); } branches.Add(child.TreeNodeID, child); IBaseTreeNode _P = this as IBaseTreeNode; BaseTreeNode <T1, T2> _C = child as BaseTreeNode <T1, T2>; _C.SetParent((T2)_P); return(true); }
private bool m_SetBranch(int childIndex, T2 child) { if (ContainBranch(child)) { return(false); } if (childIndex < branches.Count) { T2 t2 = m_GetBranch(childIndex); BaseTreeNode <T1, T2> _T2 = t2 as BaseTreeNode <T1, T2>; _T2.DicConnectParent(); } branches[child.TreeNodeID] = child; IBaseTreeNode _P = this as IBaseTreeNode; BaseTreeNode <T1, T2> _C = child as BaseTreeNode <T1, T2>; _C.SetParent((T2)_P); return(true); }
private bool m_ContainBranch(T2 t) { if (branches.ContainsKey(t.TreeNodeID)) { return(true); } else { List <int> IDList = new List <int>(branches.Keys); for (int i = 0; i < IDList.Count; i++) { BaseTreeNode <T1, T2> node = branches[IDList[i]] as BaseTreeNode <T1, T2>; if (node.ContainBranch(t)) { return(true); } } } return(false); }
private int m_GetBranch(int depth, int childIndex, ref T2 t2) { if (depth == 0) { IBaseTreeNode _N = this; t2 = (T2)_N; return(0); } int currentIndex = 0; List <int> branchList = new List <int>(branches.Keys); for (int i = 0; i < branchList.Count; i++) { T2 node = branches[branchList[i]]; if (depth == 1) { if (childIndex == i) { t2 = node; currentIndex = 0; break; } currentIndex++; } else if (depth > 1) { BaseTreeNode <T1, T2> _C = node as BaseTreeNode <T1, T2>; int _cIndex = _C.m_GetBranch(depth - 1, childIndex - currentIndex, ref t2); if (_cIndex == 0) { currentIndex = 0; break; } currentIndex += _cIndex; } } return(currentIndex); }
private int m_GetBranchDepth() { int currentDepth = 0; if (branches.Count == 0) { return(0); } List <int> branchList = new List <int>(branches.Keys); for (int i = 0; i < branchList.Count; i++) { BaseTreeNode <T1, T2> _C = branches[branchList[i]] as BaseTreeNode <T1, T2>; int _curDepth = _C.GetBranchDepth() + 1; if (currentDepth < _curDepth) { currentDepth = _curDepth; } } return(currentDepth); }