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


C# MemorySlice.Compare方法代码示例

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


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

示例1: Find

        public FoundPage Find(MemorySlice key)
        {
            for (int i = 0; i < _cache.Length; i++)
            {
                var page = _cache[i];
                if (page == null)
                    continue;

                var first = page.FirstKey;
                var last = page.LastKey;
                
                switch (key.Options)
                {
                    case SliceOptions.BeforeAllKeys:
                        if (first.Options == SliceOptions.BeforeAllKeys)
                            return page;
                        break;
                    case SliceOptions.AfterAllKeys:
                        if (last.Options == SliceOptions.AfterAllKeys)
                            return page;
                        break;
                    case SliceOptions.Key:
                        if ((first.Options != SliceOptions.BeforeAllKeys && key.Compare(first) < 0))
                            continue;
                        if (last.Options != SliceOptions.AfterAllKeys && key.Compare(last) > 0)
                            continue;
                        return page;
                    default:
                        throw new ArgumentException(key.Options.ToString());
                }
            }

            return null;
        }
开发者ID:cocytus,项目名称:ravendb,代码行数:34,代码来源:RecentlyFoundPages.cs

示例2: Find

        public FoundPage Find(MemorySlice key)
        {
            int position = current;

            int itemsLeft = _cacheSize;
            while ( itemsLeft > 0 )
            {
                var page = _cache[position % _cacheSize];
                if (page == null)
                {
                    itemsLeft--;
                    position++;

                    continue;
                }

                var first = page.FirstKey;
                var last = page.LastKey;

                switch (key.Options)
                {
                    case SliceOptions.Key:
                        if ((first.Options != SliceOptions.BeforeAllKeys && key.Compare(first) < 0))
                            break;
                        if (last.Options != SliceOptions.AfterAllKeys && key.Compare(last) > 0)
                            break;
                        return page;
                    case SliceOptions.BeforeAllKeys:
                        if (first.Options == SliceOptions.BeforeAllKeys)
                            return page;
                        break;
                    case SliceOptions.AfterAllKeys:
                        if (last.Options == SliceOptions.AfterAllKeys)
                            return page;
                        break;
                    default:
                        throw new ArgumentException(key.Options.ToString());
                }

                itemsLeft--;
                position++;
            }

            return null;
        }
开发者ID:GorelH,项目名称:ravendb,代码行数:45,代码来源:RecentlyFoundPages.cs

示例3: SearchPrefixed

        private NodeHeader* SearchPrefixed( MemorySlice key )
        {
            key.PrepareForSearching();

            int numberOfEntries = NumberOfEntries;
            if (numberOfEntries == 0)
            {
                LastSearchPosition = 0;
                LastMatch = 1;
                return null;
            }

            switch (key.Options)
            {
                case SliceOptions.Key:
                    {
                        var pageKey = CreateNewEmptyKey();

                        if (numberOfEntries == 1)
                        {
                            var node = GetNode(0);

                            SetNodeKey(node, ref pageKey);
                            LastMatch = key.Compare(pageKey);
                            LastSearchPosition = LastMatch > 0 ? 1 : 0;
                            return LastSearchPosition == 0 ? node : null;
                        }

                        int low = IsLeaf ? 0 : 1;
                        int high = numberOfEntries - 1;
                        int position = 0;

                        while (low <= high)
                        {
                            position = (low + high) >> 1;

                            var node = (NodeHeader*)(_base + KeysOffsets[position]);

                            SetNodeKey(node, ref pageKey);

                            LastMatch = key.Compare(pageKey);
                            if (LastMatch == 0)
                                break;

                            if (LastMatch > 0)
                                low = position + 1;
                            else
                                high = position - 1;
                        }

                        if (LastMatch > 0) // found entry less than key
                        {
                            position++; // move to the smallest entry larger than the key
                        }

                        Debug.Assert(position < ushort.MaxValue);
                        LastSearchPosition = position;

                        if (position >= numberOfEntries)
                            return null;
                        return GetNode(position);
                    }
                case SliceOptions.BeforeAllKeys:
                    {
                        LastSearchPosition = 0;
                        LastMatch = 1;
                        return GetNode(0);
                    }
                case SliceOptions.AfterAllKeys:
                    {
                        LastMatch = -1;
                        LastSearchPosition = numberOfEntries - 1;
                        return GetNode(LastSearchPosition);
                    }
                default:
                    throw new NotSupportedException("This SliceOptions is not supported. Make sure you have updated this code when adding a new one.");
            }
        }
开发者ID:ricardobrandao,项目名称:ravendb,代码行数:78,代码来源:Page.cs

示例4: Search

		public NodeHeader* Search(MemorySlice key)
		{
			if(KeysPrefixed)
				key.PrepareForSearching();

			if (NumberOfEntries == 0)
			{
				LastSearchPosition = 0;
				LastMatch = 1;
				return null;
			}

			if (key.Options == SliceOptions.BeforeAllKeys)
			{
				LastSearchPosition = 0;
				LastMatch = 1;
				return GetNode(0);
			}

			if (key.Options == SliceOptions.AfterAllKeys)
			{
				LastMatch = -1;
				LastSearchPosition = NumberOfEntries - 1;
				return GetNode(LastSearchPosition);
			}

			var pageKey = CreateNewEmptyKey();

			if (NumberOfEntries == 1)
			{
				SetNodeKey(GetNode(0), ref pageKey);
				LastMatch = key.Compare(pageKey);
				LastSearchPosition = LastMatch > 0 ? 1 : 0;
				return LastSearchPosition == 0 ? GetNode(0) : null;
			}

			int low = IsLeaf ? 0 : 1;
			int high = NumberOfEntries - 1;
			int position = 0;

			while (low <= high)
			{
				position = (low + high) >> 1;

				var node = (NodeHeader*)(_base + KeysOffsets[position]);

				SetNodeKey(node, ref pageKey);

				LastMatch = key.Compare(pageKey);
				if (LastMatch == 0)
					break;

				if (LastMatch > 0)
					low = position + 1;
				else
					high = position - 1;
			}

			if (LastMatch > 0) // found entry less than key
			{
				position++; // move to the smallest entry larger than the key
			}

			Debug.Assert(position < ushort.MaxValue);
			LastSearchPosition = position;

			if (position >= NumberOfEntries)
				return null;
			return GetNode(position);
		}
开发者ID:cocytus,项目名称:ravendb,代码行数:70,代码来源:Page.cs


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