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


C# Page.Search方法代码示例

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


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

示例1: Seek

		public bool Seek(Slice key)
		{
			Lazy<Cursor> lazy;
			_currentPage = _tree.FindPageFor(_tx, key, out lazy);
			_cursor = lazy.Value;
			_cursor.Pop();
			var node = _currentPage.Search(key, _cmp);
			if (node == null)
			{
				return false;
			}
			_currentKey.Set(node);
			return this.ValidateCurrentKey(Current, _cmp);
		}
开发者ID:randacc,项目名称:ravendb,代码行数:14,代码来源:TreeIterator.cs

示例2: Seek

		public bool Seek(Slice key)
		{
			Lazy<Cursor> lazy;
			_currentPage = _tree.FindPageFor(key, out lazy);
			_cursor = lazy.Value;
			_cursor.Pop();
			var node = _currentPage.Search(key);
		    if (node != null)
		    {
                _currentKey.Set(node);
                return this.ValidateCurrentKey(Current);
		    }
		    
            // The key is not found in the db, but we are Seek()ing for equals or starts with.
		    // We know that the exact value isn't there, but it is possible that the next page has values 
		    // that is actually greater than the key, so we need to check it as well.

		    _currentPage.LastSearchPosition = _currentPage.NumberOfEntries; // force next MoveNext to move to the next _page_.
		    return MoveNext();
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:20,代码来源:TreeIterator.cs

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

示例4: MultiDelete

		public void MultiDelete(Slice key, Slice value, ushort? version = null)
		{
			State.IsModified = true;
			Lazy<Cursor> lazy;
			var page = FindPageFor(key, out lazy);
			if (page == null || page.LastMatch != 0)
			{
				return; //nothing to delete - key not found
			}

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

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

			if (item->Flags == NodeFlags.MultiValuePageRef) //multi-value tree exists
			{
				var tree = OpenOrCreateMultiValueTree(_tx, key, item);

				tree.Delete(value, version);

				// previously, we would convert back to a simple model if we dropped to a single entry
				// however, it doesn't really make sense, once you got enough values to go to an actual nested 
				// tree, you are probably going to remain that way, or be removed completely.
				if (tree.State.EntriesCount != 0) 
					return;
				_tx.TryRemoveMultiValueTree(this, key);
				_tx.FreePage(tree.State.RootPageNumber);
				Delete(key);
			}
			else // we use a nested page here
			{
				var nestedPage = new Page(NodeHeader.DirectAccess(_tx, item), "multi tree", (ushort)NodeHeader.GetDataSize(_tx, item));
				var nestedItem = nestedPage.Search(value);
				if (nestedItem == null) // value not found
					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);
				}

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

				CheckConcurrency(key, value, version, nestedItem->Version, TreeActionType.Delete);
				nestedPage.RemoveNode(nestedPage.LastSearchPosition);
				if (nestedPage.NumberOfEntries == 0)
					Delete(key);
			}
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:58,代码来源:Tree.MultiTree.cs

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

示例6: TryUseRecentTransactionPage

        private bool TryUseRecentTransactionPage(MemorySlice key, out Lazy<Cursor> cursor, out Page page, out NodeHeader* node)
        {
            node = null;
            page = null;
            cursor = null;

            var recentPages = _tx.GetRecentlyFoundPages(this);

            if (recentPages == null)
                return false;

            var foundPage = recentPages.Find(key);

            if (foundPage == null)
                return false;

            var lastFoundPageNumber = foundPage.Number;
            page = _tx.GetReadOnlyPage(lastFoundPageNumber);

            if (page.IsLeaf == false)
                throw new DataException("Index points to a non leaf page");

            node = page.Search(key); // will set the LastSearchPosition

            var cursorPath = foundPage.CursorPath;
            var pageCopy = page;
            cursor = new Lazy<Cursor>(() =>
            {
                var c = new Cursor();
                foreach (var p in cursorPath)
                {
                    if (p == lastFoundPageNumber)
                        c.Push(pageCopy);
                    else
                    {
                        var cursorPage = _tx.GetReadOnlyPage(p);
                        if (key.Options == SliceOptions.BeforeAllKeys)
                        {
                            cursorPage.LastSearchPosition = 0;
                        }
                        else if (key.Options == SliceOptions.AfterAllKeys)
                        {
                            cursorPage.LastSearchPosition = (ushort)(cursorPage.NumberOfEntries - 1);
                        }
                        else if (cursorPage.Search(key) != null)
                        {
                            if (cursorPage.LastMatch != 0)
                            {
                                cursorPage.LastSearchPosition--;
                            }
                        }

                        c.Push(cursorPage);
                    }
                }

                return c;
            });

            return true;
        }
开发者ID:jesuslpm,项目名称:ravendb,代码行数:61,代码来源:Tree.cs

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


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