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


C# Page.GetNode方法代码示例

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


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

示例1: MoveNext

		public bool MoveNext()
		{

			while (_currentPage != null)
			{
				_currentPage.LastSearchPosition++;
				if (_currentPage.LastSearchPosition < _currentPage.NumberOfEntries)
				{
					// run out of entries, need to select the next page...
					while (_currentPage.IsBranch)
					{
						_cursor.Push(_currentPage);
						var node = _currentPage.GetNode(_currentPage.LastSearchPosition);
						_currentPage = _tx.GetReadOnlyPage(node->PageNumber);

						_currentPage.LastSearchPosition = 0;
					}
					var current = _currentPage.GetNode(_currentPage.LastSearchPosition);
					if (this.ValidateCurrentKey(current, _currentPage) == false)
						return false;

					_currentPage.SetNodeKey(current, ref _currentInternalKey);
					_currentKey = _currentInternalKey.ToSlice();
					return true;// there is another entry in this page
				}
				if (_cursor.PageCount == 0)
					break;
				_currentPage = _cursor.Pop();
			}
			_currentPage = null;
			
			return false;
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:33,代码来源:TreeIterator.cs

示例2: RemoveBranchWithOneEntry

		private void RemoveBranchWithOneEntry(Page page, Page parentPage)
		{
			var pageRefNumber = page.GetNode(0)->PageNumber;

			NodeHeader* nodeHeader = null;

			for (int i = 0; i < parentPage.NumberOfEntries; i++)
			{
				nodeHeader = parentPage.GetNode(i);

				if (nodeHeader->PageNumber == page.PageNumber)
					break;
			}

			Debug.Assert(nodeHeader->PageNumber == page.PageNumber);

			nodeHeader->PageNumber = pageRefNumber;

			_tx.FreePage(page.PageNumber);
		}
开发者ID:VPashkov,项目名称:ravendb,代码行数:20,代码来源:TreeRebalancer.cs

示例3: EnsureValidLastSearchPosition

 private static void EnsureValidLastSearchPosition(Page page, long referencedPageNumber, int originalLastSearchPosition)
 {
     if (page.NumberOfEntries <= originalLastSearchPosition || page.GetNode(originalLastSearchPosition)->PageNumber != referencedPageNumber)
         page.LastSearchPosition = page.NodePositionReferencing(referencedPageNumber);
     else
         page.LastSearchPosition = originalLastSearchPosition;
 }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:7,代码来源:ParentPageAction.cs

示例4: RemoveLeafNode

		private void RemoveLeafNode(Transaction tx, Page page, out ushort nodeVersion)
		{
			var node = page.GetNode(page.LastSearchPosition);
			nodeVersion = node->Version;
			if (node->Flags == (NodeFlags.PageRef)) // this is an overflow pointer
			{
				var overflowPage = tx.GetReadOnlyPage(node->PageNumber);
				var numberOfPages = tx.DataPager.GetNumberOfOverflowPages(overflowPage.OverflowSize);
				for (int i = 0; i < numberOfPages; i++)
				{
					tx.FreePage(overflowPage.PageNumber + i);
				}

				State.OverflowPages -= numberOfPages;
				State.PageCount -= numberOfPages;
			}
			page.RemoveNode(page.LastSearchPosition);
		}
开发者ID:paulcbetts,项目名称:ravendb,代码行数:18,代码来源:Tree.cs

示例5: GetActualKey

        private MemorySlice GetActualKey(Page page, int pos, out NodeHeader* node)
        {
            node = page.GetNode(pos);
			var key = page.GetNodeKey(node);
			while (key.KeyLength == 0)
            {
                Debug.Assert(page.IsBranch);
                page = _tx.GetReadOnlyPage(node->PageNumber);
                node = page.GetNode(0);
				key = page.GetNodeKey(node);
            }

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

示例6: ExpandMultiTreeNestedPageSize

		private void ExpandMultiTreeNestedPageSize(Transaction tx, Slice key, Slice value, byte* nestedPagePtr, ushort newSize, int currentSize)
		{
			Debug.Assert(newSize > currentSize);
			TemporaryPage tmp;
			using (tx.Environment.GetTemporaryPage(tx, out tmp))
			{
				var tempPagePointer = tmp.TempPagePointer;
				NativeMethods.memcpy(tempPagePointer, nestedPagePtr, currentSize);
				Delete(key); // release our current page
				Page nestedPage = new Page(tempPagePointer, "multi tree", (ushort)currentSize);

				var ptr = DirectAdd(key, newSize);

				var newNestedPage = new Page(ptr, "multi tree", newSize)
				{
					Lower = (ushort)Constants.PageHeaderSize,
					Upper = newSize,
					Flags = PageFlags.Leaf,
					PageNumber = -1L // mark as invalid page number
				};

				Slice nodeKey = new Slice(SliceOptions.Key);
				for (int i = 0; i < nestedPage.NumberOfEntries; i++)
				{
					var nodeHeader = nestedPage.GetNode(i);
					nodeKey.Set(nodeHeader);
					newNestedPage.AddDataNode(i, nodeKey, 0,
						(ushort)(nodeHeader->Version - 1)); // we dec by one because AdddataNode will inc by one, and we don't want to change those values
				}

				newNestedPage.Search(value);
				newNestedPage.AddDataNode(newNestedPage.LastSearchPosition, value, 0, 0);
			}
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:34,代码来源:Tree.MultiTree.cs

示例7: AdjustSplitPosition

        /// <summary>
        ///     For leaf pages, check the split point based on what
        ///     fits where, since otherwise adding the node can fail.
        ///     This check is only needed when the data items are
        ///     relatively large, such that being off by one will
        ///     make the difference between success or failure.
        ///     It's also relevant if a page happens to be laid out
        ///     such that one half of its nodes are all "small" and
        ///     the other half of its nodes are "large." If the new
        ///     item is also "large" and falls on the half with
        ///     "large" nodes, it also may not fit.
        /// </summary>
        private int AdjustSplitPosition(Slice key, int len, Page page, int currentIndex, int splitIndex,
            ref bool newPosition)
        {
            int nodeSize = SizeOf.NodeEntry(AbstractPager.PageMaxSpace, key, len) + Constants.NodeOffsetSize;
            if (page.NumberOfEntries >= 20 && nodeSize <= AbstractPager.PageMaxSpace/16)
            {
                return splitIndex;
            }

            int pageSize = nodeSize;
            if (currentIndex <= splitIndex)
            {
                newPosition = false;
                for (int i = 0; i < splitIndex; i++)
                {
                    NodeHeader* node = page.GetNode(i);
                    pageSize += node->GetNodeSize();
                    pageSize += pageSize & 1;
                    if (pageSize > AbstractPager.PageMaxSpace)
                    {
                        if (i <= currentIndex)
                        {
                            if (i < currentIndex)
                                newPosition = true;
                            return currentIndex;
                        }
                        return (ushort) i;
                    }
                }
            }
            else
            {
                for (int i = page.NumberOfEntries - 1; i >= splitIndex; i--)
                {
                    NodeHeader* node = page.GetNode(i);
                    pageSize += node->GetNodeSize();
                    pageSize += pageSize & 1;
                    if (pageSize > AbstractPager.PageMaxSpace)
                    {
                        if (i >= currentIndex)
                        {
                            newPosition = false;
                            return currentIndex;
                        }
                        return (ushort) (i + 1);
                    }
                }
            }
            return splitIndex;
        }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:62,代码来源:PageSplitter.cs

示例8: MoveLeafNode

        private void MoveLeafNode(Page parentPage, Page from, Page to)
        {
            Debug.Assert(from.IsBranch == false);
            var originalFromKeyStart = GetActualKey(from, from.LastSearchPositionOrLastEntry);

            var fromNode = from.GetNode(from.LastSearchPosition);
			byte* val = @from.Base + @from.KeysOffsets[@from.LastSearchPosition] + Constants.NodeHeaderSize + originalFromKeyStart.Size;

			var nodeVersion = fromNode->Version; // every time new node is allocated the version is increased, but in this case we do not want to increase it
			if (nodeVersion > 0)
				nodeVersion -= 1;

	        var prefixedOriginalFromKey = to.PrepareKeyToInsert(originalFromKeyStart, to.LastSearchPosition);

	        byte* dataPos;
	        var fromDataSize = fromNode->DataSize;
	        switch (fromNode->Flags)
	        {
				case NodeFlags.PageRef:
					to.EnsureHasSpaceFor(_tx, prefixedOriginalFromKey, -1);
					dataPos = to.AddPageRefNode(to.LastSearchPosition, prefixedOriginalFromKey, fromNode->PageNumber);
					break;
				case NodeFlags.Data:
					to.EnsureHasSpaceFor(_tx, prefixedOriginalFromKey, fromDataSize);
					dataPos = to.AddDataNode(to.LastSearchPosition, prefixedOriginalFromKey, fromDataSize, nodeVersion);
					break;
				case NodeFlags.MultiValuePageRef:
					to.EnsureHasSpaceFor(_tx, prefixedOriginalFromKey, fromDataSize);
					dataPos = to.AddMultiValueNode(to.LastSearchPosition, prefixedOriginalFromKey, fromDataSize, nodeVersion);
					break;
				default:
			        throw new NotSupportedException("Invalid node type to move: " + fromNode->Flags);
	        }
			
			if(dataPos != null && fromDataSize > 0)
                Memory.Copy(dataPos, val, fromDataSize);
            
            from.RemoveNode(from.LastSearchPositionOrLastEntry);

            var pos = parentPage.LastSearchPositionOrLastEntry;
            parentPage.RemoveNode(pos);

            var newSeparatorKey = GetActualKey(to, 0); // get the next smallest key it has now
            var pageNumber = to.PageNumber;
            if (parentPage.GetNode(0)->PageNumber == to.PageNumber)
            {
                pageNumber = from.PageNumber;
                newSeparatorKey = GetActualKey(from, 0);
            }

			AddSeparatorToParentPage(parentPage, pageNumber, newSeparatorKey, pos);
        }
开发者ID:VPashkov,项目名称:ravendb,代码行数:52,代码来源:TreeRebalancer.cs

示例9: GetActualKey

 private Slice GetActualKey(Page page, int pos)
 {
     var node = page.GetNode(pos);
     var key = new Slice(node);
     while (key.Size == 0)
     {
         Debug.Assert(page.IsBranch);
         page = _tx.GetReadOnlyPage(node->PageNumber);
         node = page.GetNode(0);
         key.Set(node);
     }
     return key;
 }
开发者ID:randacc,项目名称:ravendb,代码行数:13,代码来源:TreeRebalancer.cs

示例10: 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

示例11: MoveBranchNode

        private void MoveBranchNode(Page parentPage, Page from, Page to)
        {
            Debug.Assert(from.IsBranch);
            var originalFromKeyStart = GetActualKey(from, from.LastSearchPositionOrLastEntry);

            to.EnsureHasSpaceFor(_tx, originalFromKeyStart, -1);

            var fromNode = from.GetNode(from.LastSearchPosition);
            long pageNum = fromNode->PageNumber;

            if (to.LastSearchPosition == 0)
            {
                // cannot add to left implicit side, adjust by moving the left node
                // to the right by one, then adding the new one as the left

                var implicitLeftKey = GetActualKey(to, 0);
                var leftPageNumber = to.GetNode(0)->PageNumber;
                to.AddPageRefNode(1, implicitLeftKey, leftPageNumber);
                to.AddPageRefNode(0, Slice.BeforeAllKeys, pageNum);
                to.RemoveNode(1);
            }
            else
            {
				to.AddPageRefNode(to.LastSearchPosition, originalFromKeyStart, pageNum);
            }

            if (from.LastSearchPositionOrLastEntry == 0)
            {
                // cannot just remove the left node, need to adjust those
                var rightPageNumber = from.GetNode(1)->PageNumber;
                from.RemoveNode(0); // remove the original implicit node
                from.RemoveNode(0); // remove the next node that we now turned into implicit
                from.EnsureHasSpaceFor(_tx, Slice.BeforeAllKeys, -1);
                from.AddPageRefNode(0, Slice.BeforeAllKeys, rightPageNumber);
                Debug.Assert(from.NumberOfEntries >= 2);
            }
            else
            {
                from.RemoveNode(from.LastSearchPositionOrLastEntry);
            }

            var pos = parentPage.LastSearchPositionOrLastEntry;
            parentPage.RemoveNode(pos);
            var newKey = GetActualKey(to, 0); // get the next smallest key it has now
            var pageNumber = to.PageNumber;
            if (parentPage.GetNode(0)->PageNumber == to.PageNumber)
            {
                pageNumber = from.PageNumber;
                newKey = GetActualKey(from, 0);
            }
            parentPage.EnsureHasSpaceFor(_tx, newKey, -1);
			parentPage.AddPageRefNode(pos, newKey, pageNumber);
        }
开发者ID:randacc,项目名称:ravendb,代码行数:53,代码来源:TreeRebalancer.cs

示例12: MergePages

        private void MergePages(Page parentPage, Page left, Page right)
        {
            for (int i = 0; i < right.NumberOfEntries; i++)
            {
                right.LastSearchPosition = i;
                var key = GetActualKey(right, right.LastSearchPositionOrLastEntry);
                var node = right.GetNode(i);

                left.CopyNodeDataToEndOfPage(node, key);
            }

            parentPage.RemoveNode(parentPage.LastSearchPositionOrLastEntry); // unlink the right sibling
            _tx.FreePage(right.PageNumber);
        }
开发者ID:randacc,项目名称:ravendb,代码行数:14,代码来源:TreeRebalancer.cs

示例13: ExpandMultiTreeNestedPageSize

		private void ExpandMultiTreeNestedPageSize(Transaction tx, Slice key, Slice value, byte* nestedPagePtr, ushort newSize, int currentSize)
		{
			Debug.Assert(newSize > currentSize);
			TemporaryPage tmp;
			using (tx.Environment.GetTemporaryPage(tx, out tmp))
			{
				var tempPagePointer = tmp.TempPagePointer;
                Memory.Copy(tempPagePointer, nestedPagePtr, currentSize);
				Delete(key); // release our current page
				Page nestedPage = new Page(tempPagePointer, "multi tree", (ushort)currentSize);

				var ptr = DirectAdd(key, newSize);

				var newNestedPage = new Page(ptr, "multi tree", newSize)
				{
					Lower = (ushort)Constants.PageHeaderSize,
					Upper = KeysPrefixing ? (ushort) (newSize - Constants.PrefixInfoSectionSize) : newSize,
					Flags = KeysPrefixing ? PageFlags.Leaf | PageFlags.KeysPrefixed : PageFlags.Leaf,
					PageNumber = -1L // mark as invalid page number
				};

				newNestedPage.ClearPrefixInfo();

				MemorySlice nodeKey = nestedPage.CreateNewEmptyKey();
				for (int i = 0; i < nestedPage.NumberOfEntries; i++)
				{
					var nodeHeader = nestedPage.GetNode(i);
					nestedPage.SetNodeKey(nodeHeader, ref nodeKey);
					nodeKey = newNestedPage.PrepareKeyToInsert(nodeKey, i);
					newNestedPage.AddDataNode(i, nodeKey, 0,
						(ushort)(nodeHeader->Version - 1)); // we dec by one because AdddataNode will inc by one, and we don't want to change those values
				}

				newNestedPage.Search(value);
				newNestedPage.AddDataNode(newNestedPage.LastSearchPosition, newNestedPage.PrepareKeyToInsert(value, newNestedPage.LastSearchPosition), 0, 0);
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:37,代码来源:Tree.MultiTree.cs

示例14: TryMergePages

		private bool TryMergePages(Page parentPage, Page left, Page right)
		{
			TemporaryPage tmp;
			using (_tx.Environment.GetTemporaryPage(_tx, out tmp))
			{
				var mergedPage = tmp.GetTempPage(left.KeysPrefixed);
                Memory.Copy(mergedPage.Base, left.Base, left.PageSize);

				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);

					var prefixedKey = mergedPage.PrepareKeyToInsert(key, mergedPage.NumberOfEntries);

					if (mergedPage.HasSpaceFor(_tx, SizeOf.NodeEntryWithAnotherKey(node, prefixedKey) + Constants.NodeOffsetSize + SizeOf.NewPrefix(prefixedKey)) == false)
					{
						right.LastSearchPosition = previousSearchPosition; //previous position --> prevent mutation of parameter
						return false;
					}

					mergedPage.CopyNodeDataToEndOfPage(node, prefixedKey);
				}

                Memory.Copy(left.Base, mergedPage.Base, left.PageSize);
			}

			parentPage.RemoveNode(parentPage.LastSearchPositionOrLastEntry); // unlink the right sibling
			_tx.FreePage(right.PageNumber);

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

示例15: RenderPage

        private static unsafe void RenderPage(Transaction tx, Page page, TextWriter sw, string text, bool open)
        {
            sw.WriteLine(
               "<ul><li><input type='checkbox' id='page-{0}' {3} /><label for='page-{0}'>{4}: Page {0:#,#;;0} - {1} - {2:#,#;;0} entries</label><ul>",
               page.PageNumber, page.IsLeaf ? "Leaf" : "Branch", page.NumberOfEntries, open ? "checked" : "", text);

            for (int i = 0; i < page.NumberOfEntries; i++)
            {
                var nodeHeader = page.GetNode(i);
                if (page.IsLeaf)
                {
                    var key = new Slice(nodeHeader).ToString();
                    sw.Write("<li>{0} {1} - size: {2:#,#}</li>", key, nodeHeader->Flags, NodeHeader.GetDataSize(tx, nodeHeader));
                }
                else
                {
                    var key = new Slice(nodeHeader).ToString();

                    var pageNum = nodeHeader->PageNumber;

                    if (i == 0)
                        key = "[smallest]";

                    RenderPage(tx, tx.GetReadOnlyPage(pageNum), sw, key, false);
                }
            }

            sw.WriteLine("</ul></li></ul>");
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:29,代码来源:DebugStuff.cs


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