Beispiel #1
0
        public void SetOrAddLeafChildNode(bool rightChild, T value)
        {
            Debug.Assert(TreeDepth == 1);

            if (rightChild)
            {
                var childNode = ChildNode1 as GMacBinaryTreeLeafNode <T>;

                if (!ReferenceEquals(childNode, null))
                {
                    childNode.Value = value;
                }
                else
                {
                    ChildNode1 = new GMacBinaryTreeLeafNode <T>(value);
                }
            }
            else
            {
                var childNode = ChildNode0 as GMacBinaryTreeLeafNode <T>;

                if (!ReferenceEquals(childNode, null))
                {
                    childNode.Value = value;
                }
                else
                {
                    ChildNode0 = new GMacBinaryTreeLeafNode <T>(value);
                }
            }
        }
Beispiel #2
0
        public GMacBinaryTreeLeafNode <T> ResetLeafChildNode1(T value)
        {
            Debug.Assert(TreeDepth == 1);

            var childNode = new GMacBinaryTreeLeafNode <T>(value);

            ChildNode1 = childNode;

            return(childNode);
        }
Beispiel #3
0
        public bool TryGetLeafNode(ulong index, out GMacBinaryTreeLeafNode <T> leafNode)
        {
            var   node = this;
            ulong bitPattern;

            for (var i = TreeDepth - 1; i > 0; i--)
            {
                bitPattern = (1ul << i) & index;
                node       = node.GetChildNode(bitPattern != 0) as GMacBinaryTree <T>;

                if (ReferenceEquals(node, null))
                {
                    leafNode = null;
                    return(false);
                }
            }

            bitPattern = 1ul & index;
            leafNode   = node.GetChildNode(bitPattern != 0) as GMacBinaryTreeLeafNode <T>;
            return(!ReferenceEquals(leafNode, null));
        }