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


C# Page.CalcSizeLeft方法代码示例

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


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

示例1: SplitPageInHalf

        private byte* SplitPageInHalf(Page rightPage)
        {
            int currentIndex = _page.LastSearchPosition;
            bool newPosition = true;
            int splitIndex = _page.NumberOfEntries/2;
            if (currentIndex < splitIndex)
                newPosition = false;

	        PrefixNode[] prefixes = null;

	        if (_tree.KeysPrefixing && _page.HasPrefixes)
	        {
		        prefixes = _page.GetPrefixes();
	        }

	        if (_page.IsLeaf || prefixes != null)
            {
                splitIndex = AdjustSplitPosition(currentIndex, splitIndex, prefixes, ref newPosition);
            }

	        var currentKey = _page.GetNodeKey(splitIndex);

            // here the current key is the separator key and can go either way, so 
            // use newPosition to decide if it stays on the left node or moves to the right
            MemorySlice seperatorKey;
            if (currentIndex == splitIndex && newPosition)
            {
                seperatorKey = currentKey.Compare(_newKey) < 0 ? currentKey : _newKey;
            }
            else
            {
                seperatorKey = currentKey;
            }

            AddSeparatorToParentPage(rightPage.PageNumber, seperatorKey);

	        MemorySlice instance = _page.CreateNewEmptyKey();

	        if (prefixes != null)
	        {
				for (int i = 0; i < prefixes.Length; i++)
				{
					var prefix = prefixes[i];

					rightPage.WritePrefix(new Slice(prefix.ValuePtr, prefix.PrefixLength), i);
				}
	        }

	        // move the actual entries from page to right page
            ushort nKeys = _page.NumberOfEntries;
            for (int i = splitIndex; i < nKeys; i++)
            {
                NodeHeader* node = _page.GetNode(i);
                if (_page.IsBranch && rightPage.NumberOfEntries == 0)
                {
                    rightPage.CopyNodeDataToEndOfPage(node, _tree.KeysPrefixing ? (MemorySlice) PrefixedSlice.BeforeAllKeys : Slice.BeforeAllKeys);
                }
                else
                {
	                _page.SetNodeKey(node, ref instance);
	                var key = rightPage.PrepareKeyToInsert(instance, rightPage.NumberOfEntries);

					rightPage.CopyNodeDataToEndOfPage(node, key);
                }
            }
            _page.Truncate(_tx, splitIndex);

            // actually insert the new key
			try
			{
				return (currentIndex > splitIndex || newPosition && currentIndex == splitIndex)
					? InsertNewKey(rightPage)
					: InsertNewKey(_page);
			}
			catch (InvalidOperationException e)
			{
				if (e.Message.StartsWith("The page is full and cannot add an entry"))
				{
					var debugInfo = new StringBuilder();

					debugInfo.AppendFormat("\r\n_tree.Name: {0}\r\n", _tree.Name);
					debugInfo.AppendFormat("_newKey: {0}, _len: {1}, needed space: {2}\r\n", _newKey, _len, _page.GetRequiredSpace(_newKey, _len));
					debugInfo.AppendFormat("currentKey: {0}, seperatorKey: {1}\r\n", currentKey, seperatorKey);
					debugInfo.AppendFormat("currentIndex: {0}\r\n", currentIndex);
					debugInfo.AppendFormat("splitIndex: {0}\r\n", splitIndex);
					debugInfo.AppendFormat("newPosition: {0}\r\n", newPosition);

					debugInfo.AppendFormat("_page info: flags - {0}, # of entries {1}, size left: {2}, calculated size left: {3}\r\n", _page.Flags, _page.NumberOfEntries, _page.SizeLeft, _page.CalcSizeLeft());

					for (int i = 0; i < _page.NumberOfEntries; i++)
					{
						var node = _page.GetNode(i);
						var key = _page.GetNodeKey(node);
						debugInfo.AppendFormat("{0} - {2} {1}\r\n", key,
							node->DataSize, node->Flags == NodeFlags.Data ? "Size" : "Page");
					}

					debugInfo.AppendFormat("rightPage info: flags - {0}, # of entries {1}, size left: {2}, calculated size left: {3}\r\n", rightPage.Flags, rightPage.NumberOfEntries, rightPage.SizeLeft, rightPage.CalcSizeLeft());

					for (int i = 0; i < rightPage.NumberOfEntries; i++)
//.........这里部分代码省略.........
开发者ID:jrusbatch,项目名称:ravendb,代码行数:101,代码来源:PageSplitter.cs

示例2: GatherDetailedDebugInfo

		private string GatherDetailedDebugInfo(Page rightPage, MemorySlice currentKey, MemorySlice seperatorKey, int currentIndex, int splitIndex, bool toRight)
		{
			var debugInfo = new StringBuilder();

			debugInfo.AppendFormat("\r\n_tree.Name: {0}\r\n", _tree.Name);
			debugInfo.AppendFormat("_newKey: {0}, _len: {1}, needed space: {2}\r\n", _newKey, _len, _page.GetRequiredSpace(_newKey, _len));
			debugInfo.AppendFormat("key at LastSearchPosition: {0}, current key: {1}, seperatorKey: {2}\r\n", _page.GetNodeKey(_page.LastSearchPosition), currentKey, seperatorKey);
			debugInfo.AppendFormat("currentIndex: {0}\r\n", currentIndex);
			debugInfo.AppendFormat("splitIndex: {0}\r\n", splitIndex);
			debugInfo.AppendFormat("toRight: {0}\r\n", toRight);

			debugInfo.AppendFormat("_page info: flags - {0}, # of entries {1}, size left: {2}, calculated size left: {3}\r\n", _page.Flags, _page.NumberOfEntries, _page.SizeLeft, _page.CalcSizeLeft());

			for (int i = 0; i < _page.NumberOfEntries; i++)
			{
				var node = _page.GetNode(i);
				var key = _page.GetNodeKey(node);
				debugInfo.AppendFormat("{0} - {2} {1}\r\n", key,
					node->DataSize, node->Flags == NodeFlags.Data ? "Size" : "Page");
			}

			debugInfo.AppendFormat("rightPage info: flags - {0}, # of entries {1}, size left: {2}, calculated size left: {3}\r\n", rightPage.Flags, rightPage.NumberOfEntries, rightPage.SizeLeft, rightPage.CalcSizeLeft());

			for (int i = 0; i < rightPage.NumberOfEntries; i++)
			{
				var node = rightPage.GetNode(i);
				var key = rightPage.GetNodeKey(node);
				debugInfo.AppendFormat("{0} - {2} {1}\r\n", key,
					node->DataSize, node->Flags == NodeFlags.Data ? "Size" : "Page");
			}
			return debugInfo.ToString();
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:32,代码来源:PageSplitter.cs


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