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


C# Index.Get方法代码示例

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


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

示例1: TestOneElement

 public void TestOneElement()
 {
     using(var map = new MemoryMapStream())
     {
         var index = new Index<string>(map);
         var id = index.Add("Ben");
         Assert.AreEqual("Ben", index.Get(id));
     }
 }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:9,代码来源:IndexTests.cs

示例2: TestTinyAccessors

        public void TestTinyAccessors()
        {
            using (var map = new MemoryMapStream())
            {
                using (var tempStream = new MemoryStream(new byte[1024]))
                {
                    var index = new Index<string>(map, 32);

                    var element = "Ben";
                    var id1 = index.Add(element);
                    Assert.AreEqual(0, id1);
                    var id2Ref = MemoryMapDelegates.WriteToString(tempStream, id1, ref element);

                    element = "Abelshausen";
                    var id2 = index.Add(element);
                    Assert.AreEqual(id2Ref, id2);
                    var id3Ref = MemoryMapDelegates.WriteToString(tempStream, id2, ref element) + id2;

                    element = "is";
                    var id3 = index.Add(element);
                    Assert.AreEqual(id3Ref, id3);
                    var id4Ref = MemoryMapDelegates.WriteToString(tempStream, id3, ref element) + id3;

                    element = "the";
                    var id4 = index.Add(element);
                    Assert.AreEqual(id4Ref, id4);
                    var id5Ref = MemoryMapDelegates.WriteToString(tempStream, id4, ref element) + id4;

                    element = "author";
                    var id5 = index.Add(element);
                    Assert.AreEqual(id5Ref, id5);
                    var id6Ref = MemoryMapDelegates.WriteToString(tempStream, id5, ref element) + id5;

                    element = "of";
                    var id6 = index.Add(element);
                    Assert.AreEqual(id6Ref, id6);
                    var id7Ref = MemoryMapDelegates.WriteToString(tempStream, id6, ref element) + id6;

                    element = "this";
                    var id7 = index.Add(element);
                    Assert.AreEqual(id7Ref, id7);
                    var id8Ref = MemoryMapDelegates.WriteToString(tempStream, id7, ref element) + id7;

                    element = "library";
                    var id8 = index.Add(element);
                    Assert.AreEqual(id8Ref, id8);
                    var id9Ref = MemoryMapDelegates.WriteToString(tempStream, id8, ref element) + id8;

                    element = "and";
                    var id9 = index.Add(element);
                    Assert.AreEqual(id9Ref, id9);
                    var id10Ref = MemoryMapDelegates.WriteToString(tempStream, id9, ref element) + id9;

                    element = "this";
                    var id10 = index.Add(element);
                    Assert.AreEqual(id10Ref, id10);
                    var id11Ref = MemoryMapDelegates.WriteToString(tempStream, id10, ref element) + id10;

                    element = "test!";
                    var id11 = index.Add("test!");
                    Assert.AreEqual(id11Ref, id11);
                    var id12Ref = MemoryMapDelegates.WriteToString(tempStream, id11, ref element) + id11;

                    Assert.AreEqual(id12Ref, index.SizeInBytes);

                    Assert.AreEqual("Ben", index.Get(id1));
                    Assert.AreEqual("Abelshausen", index.Get(id2));
                    Assert.AreEqual("is", index.Get(id3));
                    Assert.AreEqual("the", index.Get(id4));
                    Assert.AreEqual("author", index.Get(id5));
                    Assert.AreEqual("of", index.Get(id6));
                    Assert.AreEqual("this", index.Get(id7));
                    Assert.AreEqual("library", index.Get(id8));
                    Assert.AreEqual("and", index.Get(id9));
                    Assert.AreEqual("this", index.Get(id10));
                    Assert.AreEqual("test!", index.Get(id11));
                }
            }
        }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:79,代码来源:IndexTests.cs

示例3: TestCreateFromAndCopyTo

        /// <summary>
        /// Tests create from and copy to in a row.
        /// </summary>
        public void TestCreateFromAndCopyTo()
        {
            byte[] data = null;
            var indexDictionary = new System.Collections.Generic.Dictionary<long, string>();

            using (var indexStream = new MemoryStream())
            {
                using (var map = new MemoryMapStream())
                {
                    // write to index and to a stream.
                    var index = new Index<string>(map, 32);

                    var element = "Ben";
                    var id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "Abelshausen";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "is";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "the";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "author";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "of";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "this";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "library";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "and";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "this";
                    id = index.Add(element);
                    indexDictionary[id] = element;
                    element = "test!";
                    id = index.Add("test!");
                    indexDictionary[id] = element;

                    index.CopyToWithSize(indexStream);
                    data = indexStream.ToArray();
                }
            }

            using (var indexStream = new MemoryStream(data))
            {
                var index = Index<string>.CreateFromWithSize(indexStream);

                foreach (var refIndexElement in indexDictionary)
                {
                    var value = index.Get(refIndexElement.Key);
                    Assert.AreEqual(refIndexElement.Value, value);
                }

                using(var outputData = new MemoryStream())
                {
                    var size = index.CopyToWithSize(outputData);
                    Assert.AreEqual(data.Length, size);
                }
            }
        }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:71,代码来源:IndexTests.cs


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