示例#1
0
        /// <summary>
        /// Constructs a new BinaryHeapNode
        /// </summary>
        /// <param name="pages">A list of pointers to pages</param>
        /// <param name="pageIndex">The index of the page in pages</param>
        /// <param name="pageSize">The number of values per page</param>
        /// <param name="index">The index inside the page, must be less than pageSize</param>
        public BTreeNode(IPageAccessor <BTreeNode <TKey, TValue> .Data> pages, IBTreeValue <TKey, TValue>?parent, int arity, ulong index)
        {
            if (arity < 2)
            {
                throw new ArgumentOutOfRangeException(nameof(arity), arity, "Arity must be greater or equal to two");
            }

            if (index == 0)
            {
                throw new ArgumentNullException(nameof(index), "The node's index may not be 0");
            }

            this.pages  = pages;
            this.parent = parent;
            this.index  = index;
            this.arity  = arity;
        }
示例#2
0
        private IBTreeValue <TKey, TValue>?FindValue(TKey key, out IBTreeValue <TKey, TValue> parent)
        {
            var node = RootNode;

            parent = RootNode.Values[0];

            int d = 0;

            while (parent.Key.CompareTo(key) != 0 && node != null && node.Follow(key, out parent))
            {
                if (node.Equals(parent.LesserNode))
                {
                    throw new Exception("Infinite Loop");
                }

                node = parent.LesserNode;
                d++;
            }

            // Console.WriteLine($"Depth {d}");

            return(parent.IsAvailable && parent.Key.CompareTo(key) == 0 ? parent : null);
        }