当前位置: 首页>>代码示例>>C#>>正文


C# Page.UseMoreSizeThan方法代码示例

本文整理汇总了C#中Voron.Trees.Page.UseMoreSizeThan方法的典型用法代码示例。如果您正苦于以下问题:C# Page.UseMoreSizeThan方法的具体用法?C# Page.UseMoreSizeThan怎么用?C# Page.UseMoreSizeThan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Voron.Trees.Page的用法示例。


在下文中一共展示了Page.UseMoreSizeThan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public Page Execute(Page page)
        {
			_tree.ClearRecentFoundPages();
            if (_cursor.PageCount <= 1) // the root page
            {
                RebalanceRoot(page);
                return null;
            }

			var parentPage = _tx.ModifyPage(_cursor.ParentPage.PageNumber, _tree, _cursor.ParentPage);
			_cursor.Update(_cursor.Pages.First.Next, parentPage);

            if (page.NumberOfEntries == 0) // empty page, just delete it and fixup parent
            {
				// need to change the implicit left page
				if (parentPage.LastSearchPosition == 0 && parentPage.NumberOfEntries > 2)
				{
					var newImplicit = parentPage.GetNode(1)->PageNumber;
					parentPage.RemoveNode(0);
					parentPage.ChangeImplicitRefPageNode(newImplicit);
				}
                else // will be set to rights by the next rebalance call
                {
                    parentPage.RemoveNode(parentPage.LastSearchPositionOrLastEntry);
                }
				
				_tx.FreePage(page.PageNumber);
                _cursor.Pop();

                return parentPage;
            }

			if (page.IsBranch && page.NumberOfEntries == 1)
			{
				RemoveBranchWithOneEntry(page, parentPage);
				_cursor.Pop();

				return parentPage;
			}

            var minKeys = page.IsBranch ? 2 : 1;
            if ((page.UseMoreSizeThan(_tx.DataPager.PageMinSpace)) &&
                page.NumberOfEntries >= minKeys)
                return null; // above space/keys thresholds

            Debug.Assert(parentPage.NumberOfEntries >= 2); // if we have less than 2 entries in the parent, the tree is invalid

            var sibling = SetupMoveOrMerge(page, parentPage);
            Debug.Assert(sibling.PageNumber != page.PageNumber);

	        if (page.Flags != sibling.Flags)
		        return null;

            minKeys = sibling.IsBranch ? 2 : 1; // branch must have at least 2 keys
            if (sibling.UseMoreSizeThan(_tx.DataPager.PageMinSpace) &&
                sibling.NumberOfEntries > minKeys)
            {
				_cursor.Pop();

                // neighbor is over the min size and has enough key, can move just one key to  the current page
	            if (page.IsBranch)
		            MoveBranchNode(parentPage, sibling, page);
	            else
		            MoveLeafNode(parentPage, sibling, page);

                return parentPage;
            }

			if (page.LastSearchPosition == 0) // this is the right page, merge left
			{
				if (TryMergePages(parentPage, sibling, page) == false)
					return null;
            }
            else // this is the left page, merge right
            {
				if (TryMergePages(parentPage, page, sibling) == false)
					return null;
            }

            _cursor.Pop();			

            return parentPage;
        }
开发者ID:VPashkov,项目名称:ravendb,代码行数:83,代码来源:TreeRebalancer.cs


注:本文中的Voron.Trees.Page.UseMoreSizeThan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。