• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Slice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Slice的典型用法代码示例。如果您正苦于以下问题:C# Slice类的具体用法?C# Slice怎么用?C# Slice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Slice类属于命名空间,在下文中一共展示了Slice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestEmptySliceAtMid

        public void TestEmptySliceAtMid()
        {
            Slice<int> x = new Slice<int>(new[] { 1, 2, 3, 4 });
            x = x.Slc(1, 1);

            Assert.IsEmpty(x.ToArray());
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:7,代码来源:SliceTest.cs


示例2: Contains

		public bool Contains(string treeName, Slice key, out ushort? version, WriteBatch writeBatch = null)
		{
			if (writeBatch != null)
			{
				WriteBatch.BatchOperationType operationType;
				Stream stream;
				if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType))
				{
					switch (operationType)
					{
						case WriteBatch.BatchOperationType.Add:
							return true;
						case WriteBatch.BatchOperationType.Delete:
							return false;
						default:
							throw new ArgumentOutOfRangeException(operationType.ToString());
					}
				}
			}

			var tree = GetTree(treeName);
			var readVersion = tree.ReadVersion(key);

			var exists = readVersion > 0;

			version = exists ? (ushort?)readVersion : null;

			return exists;
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:29,代码来源:SnapshotReader.cs


示例3: TestCreateOverArray

    public bool TestCreateOverArray(Tester t)
    {
        for (int i = 0; i < 2; i++) {
            var ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            // Try out two ways of creating a slice:
            Slice<int> slice;
            if (i == 0) {
                slice = new Slice<int>(ints);
            }
            else {
                slice = ints.Slice();
            }
            t.AssertEqual(ints.Length, slice.Length);

            // Now try out two ways of walking the slice's contents:
            for (int j = 0; j < ints.Length; j++) {
                t.AssertEqual(ints[j], slice[j]);
            }
            {
                int j = 0;
                foreach (var x in slice) {
                    t.AssertEqual(ints[j], x);
                    j++;
                }
            }
        }
        return true;
    }
开发者ID:JeanSebTr,项目名称:slice.net,代码行数:29,代码来源:Tests.cs


示例4: FindShortestSeparator

        public override void FindShortestSeparator(ref string start, Slice limit)
        {
            // Find length of common prefix
            int minLength = Math.Min(start.Length, limit.Size);
            int diffIndex = 0;

            while ((diffIndex < minLength) && (start[diffIndex].Equals((char)limit[diffIndex])))
            {
                diffIndex++;
            }

            if (diffIndex >= minLength)
            {
                // Do not shorten if one string is a prefix of the other
            }
            else
            {
                byte diffByte = (byte)start[diffIndex];
                if (diffByte < 0xff &&
                    diffByte + 1 < limit[diffIndex])
                {
                    start = start.Set(diffIndex,(char) (start[diffIndex] + 1));

                    start = start.Resize(diffIndex + 1);

                    Debug.Assert(Compare(new Slice(start), limit) < 0);
                }
            }
        }
开发者ID:somdoron,项目名称:NetLevelDB,代码行数:29,代码来源:BytewiseComparator.cs


示例5: FdbWatch

		internal FdbWatch(FdbFuture<Slice> future, Slice key, Slice value)
		{
			Contract.Requires(future != null);
			m_future = future;
			m_key = key;
			m_value = value;
		}
开发者ID:rektide,项目名称:foundationdb-dotnet-client,代码行数:7,代码来源:FdbWatch.cs


示例6: Status

        private Status(CodeEnum code, Slice msg, Slice msg2)
        {
            Debug.Assert(code != CodeEnum.kOk);
            int len1 = msg.Size;

            int len2 = 0;

            if (msg2 != null)
            {
                len2 = msg2.Size;
            }

            int size = len1 + (len2 != 0 ? (2 + len2) : 0);
            byte[] result = new byte[size + 5];

            Buffer.BlockCopy(BitConverter.GetBytes(size), 0, result, 0, 4);

            result[4] = (byte) Code;

            msg.Data.CopyTo(result,5, len1);

            if (len2!=0)
            {
                result[5 + len1] = (byte)':';
                result[6 + len1] = (byte)' ';

                msg2.Data.CopyTo(result, 7 + len1, len2);
            }

            m_state = result;
        }
开发者ID:somdoron,项目名称:NetLevelDB,代码行数:31,代码来源:Status.cs


示例7: OnData

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public override void OnData(Slice data)
        {
            // MARKET ORDERS

            MarketOrders();

            // LIMIT ORDERS

            LimitOrders();

            // STOP MARKET ORDERS

            StopMarketOrders();

            // STOP LIMIT ORDERS

            StopLimitOrders();

            // MARKET ON OPEN ORDERS

            MarketOnOpenOrders();

            // MARKET ON CLOSE ORDERS

            MarketOnCloseOrders();
        }
开发者ID:skyfyl,项目名称:Lean,代码行数:30,代码来源:OrderTicketDemoAlgorithm.cs


示例8: CreateOrOpenAsync

		/// <summary>Opens the directory with the given <paramref name="path"/>.
		/// If the directory does not exist, it is created (creating parent directories if necessary).
		/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
		/// </summary>
		public static Task<FdbDirectorySubspace> CreateOrOpenAsync(this IFdbDirectory directory, IFdbTransactional db, IEnumerable<string> path, Slice layer, CancellationToken cancellationToken)
		{
			if (directory == null) throw new ArgumentNullException("directory");
			if (db == null) throw new ArgumentNullException("db");
			if (path == null) throw new ArgumentNullException("path");
			return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), cancellationToken);
		}
开发者ID:Rustemt,项目名称:foundationdb-dotnet-client,代码行数:11,代码来源:FdbDirectoryTransactionals.cs


示例9: Seek

		public bool Seek(Slice key)
		{
			if (this.ValidateCurrentKey(Current, _cmp) == false)
				return false;
			CurrentKey = NodeHeader.GetData(_tx, _item);
			return true;
		}
开发者ID:randacc,项目名称:ravendb,代码行数:7,代码来源:SingleEntryIterator.cs


示例10: DecodeFrom

        public Status DecodeFrom(ref Slice input)
        {
            ByteArrayPointer magicPtr = input.Data + (kEncodedLength - 8);

            UInt32 magicLo = Coding.DecodeFixed32(magicPtr);
            UInt32 magicHi = Coding.DecodeFixed32(magicPtr + 4);

            UInt64 magic = (((UInt64)(magicHi) << 32) | ((UInt64)(magicLo)));

            if (magic != FormatHelper.kTableMagicNumber)
            {
                return Status.InvalidArgument("not an sstable (bad magic number)");
            }

            Status result = MetaindexHandle.DecodeFrom(ref input);
            if (result.IsOk)
            {
                result = IndexHandle.DecodeFrom(ref input);
            }
            if (result.IsOk)
            {
                // We skip over any leftover data (just padding for now) in "input"
                ByteArrayPointer end = magicPtr + 8;
                input = new Slice(end, input.Data + input.Size - end);
            }

            return result;
        }
开发者ID:somdoron,项目名称:NetLevelDB,代码行数:28,代码来源:Footer.cs


示例11: ActivityEntry

 public ActivityEntry(DebugActionType actionType, Slice key, string treeName, object value)
 {
     ActionType = actionType;
     Key = key;
     TreeName = treeName;
     Value = value;
 }
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:7,代码来源:DebugJournal.cs


示例12: Store

		private unsafe USlice Store(Slice data)
		{
			uint size = checked((uint)data.Count);
			var buffer = m_keys.AllocateAligned(size);
			UnmanagedHelpers.CopyUnsafe(buffer, data);
			return new USlice(buffer, size);
		}
开发者ID:rektide,项目名称:foundationdb-dotnet-client,代码行数:7,代码来源:TransactionWindow.cs


示例13: TestEmptySliceAtZero

        public void TestEmptySliceAtZero()
        {
            Slice<char> x = new Slice<char>("test!");
            x = x.Slc(0, 0);

            Assert.AreEqual("", x.ToString());
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:7,代码来源:SliceTest.cs


示例14: Indexing_ThrowsIfOutOfRange

        public void Indexing_ThrowsIfOutOfRange()
        {
            var inner = new[] { 1, 2, 3, 4, 5 };
            var subject = new Slice<int>(inner, 1, 2);

            Check.ThatCode(() => subject[3]).Throws<IndexOutOfRangeException>();
        }
开发者ID:akatakritos,项目名称:PygmentSharp,代码行数:7,代码来源:SliceTests.cs


示例15: Match

        public bool Match(Slice slice)
        {
            MemoryAccess acc = slice.Expression as MemoryAccess;
            if (acc == null)
                return false;

            b = acc.EffectiveAddress;
            Constant offset = Constant.Create(b.DataType, 0);
            BinaryOperator op = Operator.IAdd;
            BinaryExpression ea = b as BinaryExpression;
            if (ea != null)
            {
                Constant c= ea.Right as Constant;
                if (c != null)
                {
                    offset = c;
                    b = ea.Left;
                }
            }
            else
            {
                b = acc.EffectiveAddress;
            }
            int bitBegin = slice.Offset;
            int bitEnd = bitBegin + slice.DataType.BitSize;
            if (0 <= bitBegin && bitEnd <= acc.DataType.BitSize)
            {
                offset = op.ApplyConstants(offset, Constant.Create(acc.EffectiveAddress.DataType, slice.Offset / 8));
                b = new MemoryAccess(acc.MemoryId, new BinaryExpression(op, offset.DataType, b, offset), slice.DataType);
                return true;
            }
            return false;
        }
开发者ID:nemerle,项目名称:reko,代码行数:33,代码来源:SliceMem_Rule.cs


示例16: OnData

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public override void OnData(Slice data)
        {
            if (Transactions.OrdersCount == 0)
            {
                MarketOrder("SPY", 100);
            }

            foreach (var kvp in data.Delistings)
            {
                _delistedSymbols.Add(kvp.Key);
            }

            if (_changes != null && _changes.AddedSecurities.All(x => data.Bars.ContainsKey(x.Symbol)))
            {
                foreach (var security in _changes.AddedSecurities)
                {
                    Log(Time + ": Added Security: " + security.Symbol.ID);
                    MarketOnOpenOrder(security.Symbol, 100);
                }
                foreach (var security in _changes.RemovedSecurities)
                {
                    Log(Time + ": Removed Security: " + security.Symbol.ID);
                    if (!_delistedSymbols.Contains(security.Symbol))
                    {
                        MarketOnOpenOrder(security.Symbol, -100);
                    }
                }
                _changes = null;
            }
        }
开发者ID:AlexCatarino,项目名称:Lean,代码行数:34,代码来源:UniverseSelectionRegressionAlgorithm.cs


示例17: PageSplitter

 public PageSplitter(Transaction tx,
     Tree tree,
     SliceComparer cmp,
     Slice newKey,
     int len,
     long pageNumber,
     NodeFlags nodeType,
     ushort nodeVersion,
     Cursor cursor,
     TreeMutableState treeState)
 {
     _tx = tx;
     _tree = tree;
     _cmp = cmp;
     _newKey = newKey;
     _len = len;
     _pageNumber = pageNumber;
     _nodeType = nodeType;
     _nodeVersion = nodeVersion;
     _cursor = cursor;
     _treeState = treeState;
     Page page = _cursor.Pages.First.Value;
     _page = tx.ModifyPage(page.PageNumber, page);
     _cursor.Pop();
 }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:25,代码来源:PageSplitter.cs


示例18: DumpHumanReadable

	    public static void DumpHumanReadable(Transaction tx, string path, Page start)
	    {
		    using (var writer = File.CreateText(path))
		    {
                var stack = new Stack<Page>();
                stack.Push(start);
				writer.WriteLine("Root page #{0}",start.PageNumber);
			    while (stack.Count > 0)
			    {
					var currentPage = stack.Pop();
				    if (currentPage.IsLeaf)
				    {						
						writer.WriteLine();
						writer.WriteLine("Page #{0}, NumberOfEntries = {1}, Flags = {2} (Leaf), Used: {3} : {4}", currentPage.PageNumber,currentPage.NumberOfEntries,currentPage.Flags, currentPage.SizeUsed, currentPage.CalcSizeUsed());
						if(currentPage.NumberOfEntries <= 0)
							writer.WriteLine("Empty page (tree corrupted?)");
					    
						
					    for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries;nodeIndex++)
					    {
						    var node = currentPage.GetNode(nodeIndex);
						    var key = currentPage.GetNodeKey(node);

							writer.WriteLine("Node #{0}, Flags = {1}, {4} = {2}, Key = {3}, Entry Size: {5}", nodeIndex, node->Flags, node->DataSize, MaxString(key.ToString(), 25), node->Flags == NodeFlags.Data ? "Size" : "Page",
                                SizeOf.NodeEntry(node));
					    }
						writer.WriteLine();
				    }
				    else if(currentPage.IsBranch) 
				    {
						writer.WriteLine();
						writer.WriteLine("Page #{0}, NumberOfEntries = {1}, Flags = {2} (Branch), Used: {3} : {4}", currentPage.PageNumber, currentPage.NumberOfEntries, currentPage.Flags, currentPage.SizeUsed, currentPage.SizeUsed);

						var key = new Slice(SliceOptions.Key);
						for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
						{
							var node = currentPage.GetNode(nodeIndex);
							writer.WriteLine("Node #{2}, {0}  / to page #{1}, Entry Size: {3}", GetBranchNodeString(nodeIndex, key, currentPage, node), node->PageNumber, nodeIndex,
                                SizeOf.NodeEntry(node));
						}

						for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
						{
							var node = currentPage.GetNode(nodeIndex);
							if (node->PageNumber < 0 || node->PageNumber > tx.State.NextPageNumber)
							{
								writer.Write("Found invalid reference to page #{0}", currentPage.PageNumber);
								stack.Clear();
								break;
							}

							var child = tx.GetReadOnlyPage(node->PageNumber);
							stack.Push(child);
						}
						
						writer.WriteLine();
					}
			    }
		    }
	    }
开发者ID:cocytus,项目名称:ravendb,代码行数:60,代码来源:TreeDumper.cs


示例19: Find

        public FoundPage Find(Slice 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:ReginaBricker,项目名称:ravendb,代码行数:34,代码来源:RecentlyFoundPages.cs


示例20: OnData

        /// <summary>
        /// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
        /// </summary>
        /// <param name="slice">The current slice of data keyed by symbol string</param>
        public override void OnData(Slice slice)
        {
            if (!Portfolio.Invested)
            {
                OptionChain chain;
                if (slice.OptionChains.TryGetValue(OptionSymbol, out chain))
                {
                    // find the second call strike under market price expiring today
                    var contract = (
                        from optionContract in chain.OrderByDescending(x => x.Strike)
                        where optionContract.Right == OptionRight.Call
                        where optionContract.Expiry == Time.Date
                        where optionContract.Strike < chain.Underlying.Price
                        select optionContract
                        ).Skip(2).FirstOrDefault();

                    if (contract != null)
                    {
                        var quantity = CalculateOrderQuantity(contract.Symbol, -1m);
                        MarketOrder(contract.Symbol, quantity);
                        MarketOnCloseOrder(contract.Symbol, -quantity);
                    }
                }
            }
        }
开发者ID:AlexCatarino,项目名称:Lean,代码行数:29,代码来源:BasicTemplateOptionsAlgorithm.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Slide类代码示例发布时间:2022-05-24
下一篇:
C# SlayerName类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap