示例#1
0
        public bool MoveFirst()
        {
            var moved = false;

            Array.Clear(_movedKeysFlags, 0, _movedKeysFlags.Length);
            _movedKeys.Clear();
            for (int i = 0; i < _cursors.Length; i++)
            {
                var c      = _cursors[i];
                var movedX = c.MoveFirst();
                if (movedX)
                {
                    _movedKeysFlags[i] = true;
                    _movedKeys.Add(new KeyValuePair <TKey, int>(c.CurrentKey, i));
                }
                moved = moved || movedX;
            }
            if (moved)
            {
                CurrentKey = _movedKeys.First.Key;
                // keep navigating state unchanged
                if (moved && State == CursorState.Initialized)
                {
                    State = CursorState.Moving;
                }
                State = CursorState.Moving;
                return(true);
            }
            return(false);
        }
示例#2
0
        public void CouldAddRemoveWithFixedSize()
        {
            var sd = new SortedDeque <int>();

            for (int i = 0; i < 4; i++)
            {
                sd.Add(i);
            }

            for (int i = 4; i < 100; i++)
            {
                sd.RemoveFirst();
                sd.Add(i);
                Assert.AreEqual(i - 3, sd.First);
                Assert.AreEqual(i, sd.Last);
            }
        }
示例#3
0
        public void CouldRemoveFirstAddInTheMiddle()
        {
            var sd = new SortedDeque <int>();

            sd.Add(1);
            sd.Add(3);
            sd.Add(5);
            sd.Add(7);

            Assert.AreEqual(sd.First, 1);
            Assert.AreEqual(sd.Last, 7);

            var fst = sd.RemoveFirst();

            Assert.AreEqual(sd.First, 3);
            sd.Add(4);
            Assert.AreEqual(1, sd.ToList().IndexOf(4));
            Assert.AreEqual(2, sd.ToList().IndexOf(5));
            Assert.AreEqual(3, sd.ToList().IndexOf(7));

            var last = sd.RemoveLast();

            sd.Add(8);
            Assert.AreEqual(1, sd.ToList().IndexOf(4));
            Assert.AreEqual(2, sd.ToList().IndexOf(5));
            Assert.AreEqual(3, sd.ToList().IndexOf(8));

            sd.Add(6);
            Assert.AreEqual(1, sd.ToList().IndexOf(4));
            Assert.AreEqual(2, sd.ToList().IndexOf(5));
            Assert.AreEqual(3, sd.ToList().IndexOf(6));
            Assert.AreEqual(4, sd.ToList().IndexOf(8));
        }
示例#4
0
        public void CouldAddRemoveIncreasing()
        {
            var sd = new SortedDeque <int>();

            for (int i = 0; i < 4; i++)
            {
                sd.Add(i);
            }

            for (int i = 4; i < 100; i++)
            {
                if (i % 2 == 0)
                {
                    sd.RemoveFirst();
                }
                sd.Add(i);
                //Assert.AreEqual(i - 3, sd.First);
                Assert.AreEqual(i, sd.Last);
            }
        }
示例#5
0
        public void CouldAddBeyondInitialCapacity()
        {
            var sd = new SortedDeque <int>();

            for (int i = 0; i < 4; i++)
            {
                sd.Add(i);
            }

            for (int i = 0; i < 4; i++)
            {
                Assert.AreEqual(i, sd.ToList().IndexOf(i));
            }
        }
示例#6
0
        public void CouldAddKVsWithSimilarKey()
        {
            var sd = new SortedDeque <int, int>(2, new KVPComparer <int, int>(KeyComparer <int> .Default, KeyComparer <int> .Default));

            for (int i = 0; i < 3; i++)
            {
                sd.Add(new KeyValuePair <int, int>(1, i));
            }
            var expected = 1 * 3;

            int[] values = new int[3];
            foreach (var item in sd)
            {
                values[item.Value] = item.Key;
            }
            var actual = values.Sum();

            Console.WriteLine(actual);
            Assert.AreEqual(expected, actual);
        }
示例#7
0
        public void CouldAddKVsWithSimilarKey()
        {
            var sd = new SortedDeque <KV <int, int> >(new ZipNComparer <int>(Comparer <int> .Default), 3);

            for (int i = 0; i < 3; i++)
            {
                sd.Add(new KV <int, int>(999999, i));
            }
            var expected = 999999 * 3;

            int[] values = new int[3];
            foreach (var item in sd)
            {
                values[item.Value] = item.Key;
            }
            var actual = values.Sum();

            Console.WriteLine(actual);
            Assert.AreEqual(expected, actual);
        }
示例#8
0
        public void AddDatesTest()
        {
            var      sd = new SortedDeque <DateTime>();
            DateTime dt;

            dt = DateTime.Parse("10 / 2 / 2015 10:29:00 PM");
            sd.Add(dt);
            dt = DateTime.Parse("10 / 2 / 2015 2:06:00 PM");
            sd.Add(dt);
            dt = DateTime.Parse("10 / 1 / 2015 11:30:00 PM");
            sd.Add(dt);
            dt = DateTime.Parse("10 / 2 / 2015 10:30:00 PM");
            sd.Add(dt);
            dt = DateTime.Parse("10 / 1 / 2015 11:31:00 PM");
            sd.Add(dt);
            dt = DateTime.Parse("10 / 2 / 2015 2:07:00 PM");
            sd.Add(dt);
            Assert.AreEqual(6, sd.Count);
        }