/// <summary> /// Get parent node of given node /// </summary> /// <param name="node"></param> /// <returns></returns> public MemberNode GetParentNodeOf(MemberNode node) { if (node == null) throw new ArgumentNullException("Trying to get parent of non-existing node"); int parentIndex = this.GetParentIndex(node); return this.nodes[parentIndex]; }
/// <summary> /// Create the chain with initialized root and defined height /// </summary> /// <param name="height">The height of the chain from one as the root</param> public MemberChain(MemberNode root, int height) : this(height) { this.Height = height; this.SetRoot(root); }
private void SetRoot(MemberNode root) { this.root = this.nodes[0] = root; }
/// <summary> /// Get parent index of the given node /// </summary> /// <param name="node"></param> /// <returns></returns> private int GetParentIndex(MemberNode node) { if (node == null) throw new ArgumentNullException("Trying to get parent index of non-existing node"); // zero based index return Convert.ToInt32(GetParentBinary(node), 2) - 1; }
/// <summary> /// Get the parent index binary representation of given node /// </summary> /// <param name="child"></param> /// <returns></returns> private string GetParentBinary(MemberNode child) { return this.GetParentBinary(GetBinary(child.BinaryString)); }
public void Insert(MemberNode node) { int index = this.GetIndex(node); this.nodes[index] = node; }
/// <summary> /// Get position of the node /// </summary> /// <param name="node"></param> /// <returns></returns> public MemberNode.NodePosition GetPosition(MemberNode node) { return this.GetPosition(GetIndex(node)); }