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


C# Page.HasSpaceFor方法代码示例

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


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

示例1: MultiAdd

		public void MultiAdd(Slice key, Slice value, ushort? version = null)
		{
			if (value == null) throw new ArgumentNullException("value");
			int maxNodeSize = _tx.DataPager.MaxNodeSize;
			if (value.Size > maxNodeSize)
				throw new ArgumentException(
					"Cannot add a value to child tree that is over " + maxNodeSize + " bytes in size", "value");
			if (value.Size == 0)
				throw new ArgumentException("Cannot add empty value to child tree");

			State.IsModified = true;

			Lazy<Cursor> lazy;
			var page = FindPageFor(key, out lazy);
			if ((page == null || page.LastMatch != 0))
			{
				MultiAddOnNewValue(_tx, key, value, version, maxNodeSize);
				return;
			}

			page = _tx.ModifyPage(page.PageNumber, page);

			var item = page.GetNode(page.LastSearchPosition);

			// already was turned into a multi tree, not much to do here
			if (item->Flags == NodeFlags.MultiValuePageRef)
			{
				var existingTree = OpenOrCreateMultiValueTree(_tx, key, item);
				existingTree.DirectAdd(value, 0, version: version);
				return;
			}

			byte* nestedPagePtr;
			if (item->Flags == NodeFlags.PageRef)
			{
				var overFlowPage = _tx.ModifyPage(item->PageNumber, null);
				nestedPagePtr = overFlowPage.Base + Constants.PageHeaderSize;
			}
			else
			{
				nestedPagePtr = NodeHeader.DirectAccess(_tx, item);
			}

			var nestedPage = new Page(nestedPagePtr, "multi tree", (ushort)NodeHeader.GetDataSize(_tx, item));

			var existingItem = nestedPage.Search(value);
			if (nestedPage.LastMatch != 0)
				existingItem = null;// not an actual match, just greater than

			ushort previousNodeRevision = existingItem != null ?  existingItem->Version : (ushort)0;
			CheckConcurrency(key, value, version, previousNodeRevision, TreeActionType.Add);
			
			if (existingItem != null)
			{
				// maybe same value added twice?
				var tmpKey = new Slice(item);
				if (tmpKey.Compare(value) == 0)
					return; // already there, turning into a no-op
				nestedPage.RemoveNode(nestedPage.LastSearchPosition);
			}

			if (nestedPage.HasSpaceFor(_tx, value, 0))
			{
				// we are now working on top of the modified root page, we can just modify the memory directly
				nestedPage.AddDataNode(nestedPage.LastSearchPosition, value, 0, previousNodeRevision);
				return;
			}

			int pageSize = nestedPage.CalcSizeUsed() + Constants.PageHeaderSize;
			var newRequiredSize = pageSize + nestedPage.GetRequiredSpace(value, 0);
			if (newRequiredSize <= maxNodeSize)
			{
				// we can just expand the current value... no need to create a nested tree yet
				var actualPageSize = (ushort)Math.Min(Utils.NearestPowerOfTwo(newRequiredSize), maxNodeSize);
				ExpandMultiTreeNestedPageSize(_tx, key, value, nestedPagePtr, actualPageSize, item->DataSize);

				return;
			}
			// we now have to convert this into a tree instance, instead of just a nested page
			var tree = Create(_tx, TreeFlags.MultiValue);
			for (int i = 0; i < nestedPage.NumberOfEntries; i++)
			{
				var existingValue = nestedPage.GetNodeKey(i);
				tree.DirectAdd(existingValue, 0);
			}
			tree.DirectAdd(value, 0, version: version);
			_tx.AddMultiValueTree(this, key, tree);
			// we need to record that we switched to tree mode here, so the next call wouldn't also try to create the tree again
			DirectAdd(key, sizeof (TreeRootHeader), NodeFlags.MultiValuePageRef);
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:90,代码来源:Tree.MultiTree.cs

示例2: InsertNewKey

        private byte* InsertNewKey(Page p)
        {
            int pos = p.NodePositionFor(_newKey);

			var newKeyToInsert = p.PrepareKeyToInsert(_newKey, pos);

			if (p.HasSpaceFor(_tx, p.GetRequiredSpace(newKeyToInsert, _len)) == false)
			{
				_cursor.Push(p);

				var pageSplitter = new PageSplitter(_tx, _tree, _newKey, _len, _pageNumber, _nodeType, _nodeVersion, _cursor, _treeState);

				return pageSplitter.Execute();
			}

            byte* dataPos = AddNodeToPage(p, pos, newKeyToInsert);
            _cursor.Push(p);
            return dataPos;
        }
开发者ID:jrusbatch,项目名称:ravendb,代码行数:19,代码来源:PageSplitter.cs

示例3: AddSeparatorToParentPage

		private void AddSeparatorToParentPage(Page parentPage, long pageNumber, MemorySlice seperatorKey, int separatorKeyPosition)
		{
			var separatorKeyToInsert = parentPage.PrepareKeyToInsert(seperatorKey, separatorKeyPosition);

			if (parentPage.HasSpaceFor(_tx, SizeOf.BranchEntry(separatorKeyToInsert) + Constants.NodeOffsetSize + SizeOf.NewPrefix(separatorKeyToInsert)) == false)
			{
				var pageSplitter = new PageSplitter(_tx, _tree, seperatorKey, -1, pageNumber, NodeFlags.PageRef,
					0, _cursor, _tree.State);
				pageSplitter.Execute();
			}
			else
			{
				parentPage.AddPageRefNode(separatorKeyPosition, separatorKeyToInsert, pageNumber);
			}
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:15,代码来源:TreeRebalancer.cs

示例4: HasEnoughSpaceToCopyNodes

	    private bool HasEnoughSpaceToCopyNodes(Page left, Page right)
	    {
		    var actualSpaceNeeded = 0;
		    var previousSearchPosition = right.LastSearchPosition;
		    for (int i = 0; i < right.NumberOfEntries; i++)
		    {
			    right.LastSearchPosition = i;
			    var key = GetActualKey(right, right.LastSearchPositionOrLastEntry);
			    var node = right.GetNode(i);
			    actualSpaceNeeded += (SizeOf.NodeEntryWithAnotherKey(node, key) + Constants.NodeOffsetSize);
		    }

		    right.LastSearchPosition = previousSearchPosition; //previous position --> prevent mutation of parameter
	        return left.HasSpaceFor(_tx, actualSpaceNeeded);
	    }
开发者ID:randacc,项目名称:ravendb,代码行数:15,代码来源:TreeRebalancer.cs


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