Example #1
0
        /// <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];
        }
Example #2
0
 /// <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);
 }
Example #3
0
 private void SetRoot(MemberNode root)
 {
     this.root = this.nodes[0] = root;
 }
Example #4
0
        /// <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;
        }
Example #5
0
 /// <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));
 }
Example #6
0
 public void Insert(MemberNode node)
 {
     int index = this.GetIndex(node);
     this.nodes[index] = node;
 }
Example #7
0
 /// <summary>
 /// Get position of the node
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public MemberNode.NodePosition GetPosition(MemberNode node)
 {
     return this.GetPosition(GetIndex(node));
 }