Ejemplo n.º 1
0
        public void CouldUseVec()
        {
            var arr  = new[] { 1, 2, 3 };
            var vecT = new Vec <int>(arr);
            var vec  = new Vec(arr);

            Assert.AreEqual(2, vecT[1]);
            Assert.AreEqual(2, vec[1]);

            vecT[1] = 42;

            vec[2] = (byte)123; // dynamic cast inside

            Assert.AreEqual(3, vecT.Length);
            Assert.AreEqual(3, vec.Length);

            Assert.AreEqual(42, vecT[1]);
            Assert.AreEqual(123, vecT[2]);

            Assert.AreEqual(42, vec[1]);
            Assert.AreEqual(123, vec[2]);

            Assert.Throws <IndexOutOfRangeException>(() => { vecT[3] = 42; });

            // TODO uncomment when NuGet is updated, GetRef did not have type check
            //Assert.Throws<IndexOutOfRangeException>(() => { vec.GetRef<int>(3) = 42; });
            //Assert.Throws<InvalidOperationException>(() => { vec.GetRef<long>(2) = 42; });

            Assert.Throws <IndexOutOfRangeException>(() => { Console.WriteLine(vec.Get <int>(3)); });
            Assert.Throws <InvalidOperationException>(() => { Console.WriteLine(vec.Get <long>(2)); });
        }
Ejemplo n.º 2
0
        private static long VecGetT_Loop(int count, int mult, long sum, Vec vec)
        {
            using (Benchmark.Run("Vec.Get<T>", count * mult))
            {
                for (int m = 0; m < mult; m++)
                {
                    for (int j = 0; j < count; j++)
                    {
                        sum += vec.Get <int>(j);
                    }
                }
            }

            return(sum);
        }
Ejemplo n.º 3
0
 public T GetItem(int index)
 {
     return(_vec.Get <T>(RingVecUtil.IndexToOffset(index, _head, _count)));
 }