Example #1
0
        /// <inheritdoc/>
        public IEnumerable <string> GetCommitHistory(IEnumerable <string> oids)
        {
            Deque <string>   oidQueue = new Deque <string>(oids);
            HashSet <string> visited  = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            while (oidQueue.Count > 0)
            {
                string oid = oidQueue.RemoveFromFront();
                if (string.IsNullOrWhiteSpace(oid) || visited.Contains(oid))
                {
                    continue;
                }

                visited.Add(oid);
                yield return(oid);

                var commit = this.GetCommit(oid);
                oidQueue.AddToFront(commit.Parents.FirstOrDefault());
                if (commit.Parents.Count > 1)
                {
                    commit.Parents.TakeLast(commit.Parents.Count - 1)
                    .ToList()
                    .ForEach(id => oidQueue.AddToBack(id));
                }
            }
        }
        public static int PeekFirst(this Deque <int> collection)
        {
            var value = collection.RemoveFromFront();

            collection.AddToFront(value);

            return(value);
        }
        static void DequeExample()
        {
            Console.WriteLine("Wintellect.PowerCollections.Deque<T> example:");
            Console.WriteLine("Elements will retain their insertion order. Elements can be added at both ends of the deque.");
            Deque <string> list = new Deque <string>();

            list.AddToBack("programming");
            list.AddToBack("C#");
            list.AddToFront("Visual Studio");
            list.AddToBack("dotnet");
            list.AddToFront("C#"); // Duplicates are allowed (at different index)
            list.AddToBack("C#");  // Duplicates are allowed (at different index)
            Console.WriteLine("Elements: {0}", list);
            Console.WriteLine("Removed element from front: {0}", list.RemoveFromFront());
            Console.WriteLine("Removed element from back: {0}", list.RemoveFromBack());
            Console.WriteLine("Elements: {0}", list);
        }
Example #4
0
        public void SerializeStrings()
        {
            Deque <string> d = new Deque <string>();

            d.AddToFront("foo");
            d.AddToBack("world");
            d.AddToFront("hello");
            d.AddToBack("elvis");
            d.AddToFront("elvis");
            d.AddToBack(null);
            d.AddToFront("cool");
            d.AddManyToFront(new string[] { "1", "2", "3", "4", "5", "6" });
            d.AddManyToBack(new string[] { "7", "8", "9", "10", "11", "12" });

            Deque <string> result = (Deque <string>)InterfaceTests.SerializeRoundTrip(d);

            InterfaceTests.TestReadWriteListGeneric((IList <string>)result, new string[] { "1", "2", "3", "4", "5", "6", "cool", "elvis", "hello", "foo", "world", "elvis", null, "7", "8", "9", "10", "11", "12" });
        }
Example #5
0
        public void RemoveAt_RemovesElementAtIndex()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            deque.RemoveAt(1);
            Assert.AreEqual(new[] { 0, 2 }, deque);
        }
Example #6
0
        public void Insert_AtIndex0_IsSameAsAddToFront()
        {
            var deque1 = new Deque <int>(new[] { 1, 2 });
            var deque2 = new Deque <int>(new[] { 1, 2 });

            deque1.Insert(0, 0);
            deque2.AddToFront(0);
            Assert.AreEqual(deque1, deque2);
        }
        public void RemoveAt_RemovesElementAtIndex()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            deque.RemoveAt(1);
            deque.ShouldBe(new[] { 0, 2 });
        }
        public void Insert_AtIndex0_IsSameAsAddToFront()
        {
            var deque1 = new Deque <int>(new[] { 1, 2 });
            var deque2 = new Deque <int>(new[] { 1, 2 });

            deque1.Insert(0, 0);
            deque2.AddToFront(0);
            deque2.ShouldBe(deque1);
        }
Example #9
0
        public void CloneContents()
        {
            Deque <MyInt> deque1 = new Deque <MyInt>();

            deque1.Add(new MyInt(143));
            deque1.Add(new MyInt(2));
            deque1.AddToFront(new MyInt(9));
            deque1.Add(null);
            deque1.AddToFront(new MyInt(2));
            deque1.Add(new MyInt(111));
            Deque <MyInt> deque2 = deque1.CloneContents();

            CompareClones(deque1, deque2);

            Deque <int> deque3 = new Deque <int>(new int[] { 144, 5, 23 });

            deque3.InsertRange(1, new int[] { 7, 5, 11, 109 });
            Deque <int> deque4 = deque3.CloneContents();

            CompareClones(deque3, deque4);

            Deque <UtilTests.CloneableStruct> deque5 = new Deque <UtilTests.CloneableStruct>();

            deque5.Add(new UtilTests.CloneableStruct(143));
            deque5.AddToFront(new UtilTests.CloneableStruct(5));
            deque5.Add(new UtilTests.CloneableStruct(23));
            deque5.AddToFront(new UtilTests.CloneableStruct(1));
            deque5.AddToFront(new UtilTests.CloneableStruct(8));
            Deque <UtilTests.CloneableStruct> deque6 = deque5.CloneContents();

            Assert.AreEqual(deque5.Count, deque6.Count);

            // Check that the deques are equal, but not identical (e.g., have been cloned via ICloneable).
            IEnumerator <UtilTests.CloneableStruct> e1 = deque5.GetEnumerator();
            IEnumerator <UtilTests.CloneableStruct> e2 = deque6.GetEnumerator();

            // Check that the deques are equal, but not reference equals (e.g., have been cloned).
            while (e1.MoveNext())
            {
                e2.MoveNext();
                Assert.IsTrue(e1.Current.Equals(e2.Current));
                Assert.IsFalse(e1.Current.Identical(e2.Current));
            }
        }
Example #10
0
        public void RemoveAtExceptions()
        {
            Deque <string> d = new Deque <string>();

            d.AddToFront("foo");
            d.AddToBack("world");
            d.AddToFront("hello");
            d.AddToBack("elvis");
            d.AddToFront("elvis");
            d.AddToBack(null);
            d.AddToFront("cool");

            try {
                d.RemoveAt(-1);
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }

            try {
                d.RemoveAt(7);
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }

            try {
                d.RemoveAt(int.MinValue);
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }

            try {
                d.RemoveAt(int.MaxValue);
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }
        }
Example #11
0
        public void IndexOf_ItemPresentAndSplit_ReturnsItemIndex()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            Assert.AreEqual(0, deque.IndexOf(0));
            Assert.AreEqual(1, deque.IndexOf(1));
            Assert.AreEqual(2, deque.IndexOf(2));
        }
        public void GetItem_Split_ReadsElements()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            deque[0].ShouldBe(0);
            deque[1].ShouldBe(1);
            deque[2].ShouldBe(2);
        }
        public void IndexOf_ItemPresentAndSplit_ReturnsItemIndex()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            deque.IndexOf(0).ShouldBe(0);
            deque.IndexOf(1).ShouldBe(1);
            deque.IndexOf(2).ShouldBe(2);
        }
Example #14
0
        public void GetItem_Split_ReadsElements()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            Assert.AreEqual(0, deque[0]);
            Assert.AreEqual(1, deque[1]);
            Assert.AreEqual(2, deque[2]);
        }
Example #15
0
        public void SetItem_Split_WritesElements()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            deque[0] = 7;
            deque[1] = 11;
            deque[2] = 13;
            Assert.AreEqual(new[] { 7, 11, 13 }, deque);
        }
        public void CreateHUDMessage(string message, Sprite icon)
        {
            lock (_HUDMessageLock)
            {
                if (_HUDMessages.Count == HUD_MESSAGE_MAX_COUNT)
                {
                    Destroy(_HUDMessages.RemoveFromFront().Self);


                    _lastHUDMessageIndex = HUD_MESSAGE_MAX_COUNT - 1;
                }
            }

            lock (_HUDMessageLock)
            {
                if (_HUDMessages.Any())
                {
                    GameObject existingMsg = _HUDMessages.First().Self;
                    if (existingMsg.GetComponentInChildren <Text>().text == message)
                    {
                        // Found identical message already existing. Do not duplicate, just identify that upcoming msg is the same
                        existingMsg.GetComponent <Shake>().ShakeIt();
                        return;
                    }
                }
            }

            GameObject HUDMessage = Instantiate(HUDMessagePrefab, new Vector3(0, 0, 0), Quaternion.identity,
                                                Canvas.transform);
            RectTransform rTransform = HUDMessage.GetComponent <RectTransform>();

            HUDMessage.GetComponentInChildren <Text>().text = message;
            rTransform.position = new Vector3(HUD_MESSAGE_INIT_X, HUD_MESSAGE_INIT_Y, rTransform.position.z);
            rTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom,
                                                     HUD_MESSAGE_INIT_Y + (_lastHUDMessageIndex * HUD_MESSAGE_SHIFT_Y), 0);

            Transform HUDMessageType = HUDMessage.transform.Find("HUDMessageType");

            HUDMessageType.gameObject.GetComponent <Image>().sprite = icon;

            lock (_HUDMessageLock)
            {
                _HUDMessages.AddToFront(new HUDMessage()
                {
                    Self = HUDMessage, TimeCreation = DateTime.Now
                });
            }

            if (_lastHUDMessageIndex + 1 < HUD_MESSAGE_MAX_COUNT)
            {
                _lastHUDMessageIndex++;
            }
        }
Example #17
0
        private bool is_unknown_separator(Deque <HtmlNode> rows)
        {
            var sep = rows.RemoveFromFront();

            if (sep.SelectSingleNode("td[@colspan]") != null && sep.SelectSingleNode("td[@class]") == null)
            {
                return(true);
            }

            rows.AddToFront(sep);
            return(false);
        }
        public new AtfAction Dequeue()
        {
            var previousCount = rleCounts.RemoveFromFront();

            if (previousCount == 0)
            {
                var toRemove = base.Dequeue();
                return(toRemove);
            }
            rleCounts.AddToFront(previousCount - 1);
            return(Peek());
        }
Example #19
0
        public void Contains_ItemPresentAndSplit_ReturnsTrue()
        {
            var deque = new Deque <int>(new[] { 1, 2, 3 });

            deque.RemoveFromBack();
            deque.AddToFront(0);
            var deq = deque as ICollection <int>;

            Assert.True(deq.Contains(0));
            Assert.True(deq.Contains(1));
            Assert.True(deq.Contains(2));
            Assert.False(deq.Contains(3));
        }
Example #20
0
        public void NongenericContains_ItemPresentAndSplit_ReturnsTrue()
        {
            var deque_ = new Deque <int>(new[] { 1, 2, 3 });

            deque_.RemoveFromBack();
            deque_.AddToFront(0);
            var deque = deque_ as IList;

            Assert.True(deque.Contains(0));
            Assert.True(deque.Contains(1));
            Assert.True(deque.Contains(2));
            Assert.False(deque.Contains(3));
        }
Example #21
0
        /// <summary>
        /// Deque<T>
        /// Double-ended queue (deque)
        /// </summary>
        private static void TestDeque()
        {
            Deque <Student> deque    = new Deque <Student>();
            var             student1 = new Student("First DUPLICATE", 21);
            var             student2 = new Student("Second", 21);
            var             student3 = new Student("Third", 22);
            var             student4 = new Student("Forth", 23);
            var             student5 = new Student("Fifth", 24);

            deque.AddToBack(student1);
            deque.AddToFront(student2);
            deque.AddToBack(student3);
            deque.AddToFront(student4);
            deque.AddToBack(student5);
            deque.AddToFront(student1);

            while (deque.Count != 0)
            {
                var student = deque.RemoveFromFront();
                Console.WriteLine(student);
            }
        }
Example #22
0
        public void Add(int damage)
        {
            _messages.AddToFront(new TextOverhead
            {
                RenderedText = RenderedText.Create(damage.ToString(), (ushort)(Parent == World.Player ? 0x0034 : 0x0021), 3, false),
                Time         = Time.Ticks + 1500
            });


            if (_messages.Count > 10)
            {
                _messages.RemoveFromBack()?.RenderedText?.Destroy();
            }
        }
Example #23
0
        public void Add(int damage)
        {
            TextObject text_obj = TextObject.Create();

            text_obj.RenderedText = RenderedText.Create(damage.ToString(), (ushort)(Parent == World.Player ? 0x0034 : 0x0021), 3, false);
            text_obj.Time         = Time.Ticks + 1500;

            _messages.AddToFront(text_obj);

            if (_messages.Count > 10)
            {
                _messages.RemoveFromBack()?.RenderedText?.Destroy();
            }
        }
Example #24
0
        public void AddToFrontTestException()
        {
            IDeque deque = new Deque();

            try
            {
                deque.AddToFront("9999999999999");
            }
            catch (Exception ex)
            {
                StringAssert.Contains(ex.Message, "Input OutofRange");
                return;
            }
            Assert.Fail("No exception");
        }
        public void Ldeque(int startIndex, int toIndex)
        {
            watch.start();
            path.Add(toIndex);

            double      INF   = double.PositiveInfinity;
            Deque <int> deque = new Deque <int>();

            foreach (var pair in graph)
            {
                shortestDistances.Add(INF);
                predecessorVertex.Add(-1);
            }

            shortestDistances[startIndex] = 0;
            deque.AddToBack(startIndex);

            while (deque.Count != 0)
            {
                int u = deque.RemoveFromFront();
                foreach (var pair in graph[u])
                {
                    int v = pair.toIndex;
                    if (shortestDistances[v] > shortestDistances[u] + pair.cost)
                    {
                        if (!deque.Contains(v))
                        {
                            if (shortestDistances[v] == double.PositiveInfinity)
                            {
                                deque.AddToBack(v);
                            }
                            else
                            {
                                deque.AddToFront(v);
                            }
                        }
                        shortestDistances[v] = shortestDistances[u] + pair.cost;
                        predecessorVertex[v] = u;
                    }
                }
            }

            getPath(startIndex, toIndex);
            totalJarak    = shortestDistances[toIndex];
            elapsedTimeMs = watch.stop();
        }
Example #26
0
            public void Add(BlockHeader blockHeader)
            {
                bool DoesNotContainBlock() => _blocks.Count == 0 || _blocks[0].Number > blockHeader.Number || _blocks[^ 1].Number < blockHeader.Number;

                if (DoesNotContainBlock())
                {
                    if (_blocks.Count == 0 || _blocks[0].Number < blockHeader.Number)
                    {
                        _blocks.AddToFront(blockHeader);
                    }
                    else
                    {
                        _blocks.AddToBack(blockHeader);
                    }
                    int count = _validatorCount.TryGetValue(blockHeader.Beneficiary, out count) ? count + 1 : 1;
                    _validatorCount[blockHeader.Beneficiary] = count;
                }
            }
Example #27
0
        public void Deque_Add_Front(int count)
        {
            var deque = new Deque <TestDequeElement>();

            for (var i = 0; i < count; i++)
            {
                deque.AddToFront(new TestDequeElement
                {
                    Value = i
                });
            }
            Assert.True(deque.Count == count);
            Assert.True(deque.Capacity >= count);
            for (var index = 0; index < deque.Count; index++)
            {
                var element = deque[index];
                Assert.True(element.Value == deque.Count - 1 - index);
            }
        }
Example #28
0
        private List <Topic> ParseTopics(Deque <HtmlNode> rows)
        {
            List <Topic> topics = new List <Topic>();

            while (rows.Any())
            {
                var row = rows.RemoveFromFront();

                if (is_separator(row))
                {
                    rows.AddToFront(row);
                    break;
                }

                topics.Add(ParseTopic(row));
            }

            return(topics);
        }
Example #29
0
        public void Clone()
        {
            Deque <int> deque1, deque2, deque3, deque4;

            deque1 = new Deque <int>();
            deque2 = deque1.Clone();
            deque3 = (Deque <int>)(((ICloneable)deque1).Clone());
            deque4 = new Deque <int>(deque1);
            InterfaceTests.TestListGeneric <int>(deque2, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque3, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque4, new int[0], null);
            deque1.Add(5);
            InterfaceTests.TestListGeneric <int>(deque2, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque3, new int[0], null);
            InterfaceTests.TestListGeneric <int>(deque4, new int[0], null);

            int[] array = new int[100];
            for (int i = 0; i < 100; ++i)
            {
                array[i] = i;
            }
            deque1.Clear();
            for (int i = 63; i < 100; ++i)
            {
                deque1.AddToBack(i);
            }
            for (int i = 62; i >= 0; --i)
            {
                deque1.AddToFront(i);
            }
            deque2 = deque1.Clone();
            deque3 = (Deque <int>)(((ICloneable)deque1).Clone());
            deque4 = new Deque <int>(deque1);
            InterfaceTests.TestListGeneric <int>(deque2, array, null);
            InterfaceTests.TestListGeneric <int>(deque3, array, null);
            InterfaceTests.TestListGeneric <int>(deque4, array, null);
            deque4.Clear();
            InterfaceTests.TestListGeneric <int>(deque1, array, null);
            InterfaceTests.TestListGeneric <int>(deque2, array, null);
            InterfaceTests.TestListGeneric <int>(deque3, array, null);
        }
Example #30
0
        public static void AddToQueue(OutputMessage msg, bool pushFront = false)
        {
            bool sendSignal;

            lock (_waitingQueueLock)
            {
                sendSignal = (_waitingMessageQueue.Count == 0);

                if (pushFront)
                {
                    _waitingMessageQueue.AddToFront(msg);
                }
                else
                {
                    _waitingMessageQueue.AddToBack(msg);
                }
            }

            if (sendSignal)
            {
                Signaler.Set();
            }
        }
    static void Main()
    {
        Console.Write("Bag of Integers: ");
        var bagOfInts = new Bag<int>();
        bagOfInts.Add(3);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(5);
        bagOfInts.Add(10);
        bagOfInts.Add(20);
        bagOfInts.Add(20);
        bagOfInts.Remove(5);
        bagOfInts.RemoveAllCopies(20);
        bagOfInts.UnionWith(new Bag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(bagOfInts);

        Console.Write("OrderedBag of Integers: ");
        var orderedBagOfInts = new OrderedBag<int>();
        orderedBagOfInts.Add(3);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(5);
        orderedBagOfInts.Add(10);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Add(20);
        orderedBagOfInts.Remove(5);
        orderedBagOfInts.RemoveAllCopies(20);
        orderedBagOfInts.UnionWith(new OrderedBag<int>() { 3, 3, 4, 4, 5, 5 });
        Console.WriteLine(orderedBagOfInts);
        Console.WriteLine("Sub-range [5...10]: " +
            orderedBagOfInts.Range(5, true, 10, true));
        
        Console.Write("Set of Integers: ");
        var setOfInts = new Set<int>();
        setOfInts.Add(3);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(5);
        setOfInts.Add(10);
        setOfInts.Add(20);
        setOfInts.Add(20);
        setOfInts.Remove(5);
        setOfInts.UnionWith(new Set<int>() { 3, 4, 5 });
        Console.WriteLine(setOfInts);

        Console.Write("OrderedSet of Integers: ");
        var orderedSetOfInts = new OrderedSet<int>();
        orderedSetOfInts.Add(3);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(5);
        orderedSetOfInts.Add(10);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Add(20);
        orderedSetOfInts.Remove(5);
        orderedSetOfInts.UnionWith(new OrderedSet<int>() { 3, 4, 5 });
        Console.WriteLine(orderedSetOfInts);
        Console.WriteLine("Sub-range [5...20): " +
            orderedSetOfInts.Range(5, true, 20, false));

        Console.Write("MultiDictionary<string,int>: ");
        var studentGrades = new MultiDictionary<string, int>(true);
        studentGrades.Add("Peter", 3);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Peter", 4);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Stanka", 5);
        studentGrades.Add("Stanka", 6);
        studentGrades.Add("Tanya", 6);
        studentGrades.Add("Tanya", 4);
        Console.WriteLine(studentGrades);

        Console.WriteLine("OrderedMultiDictionary<string,int>:");
        var distancesFromSofia = new OrderedMultiDictionary<int, string>(true);
        distancesFromSofia.Add(149, "Plovdiv");
        distancesFromSofia.Add(505, "Varna");
        distancesFromSofia.Add(394, "Bourgas");
        distancesFromSofia.Add(310, "Rousse");
        distancesFromSofia.Add(163, "Pleven");
        distancesFromSofia.Add(163, "Troyan");
        foreach (var distanceTowns in distancesFromSofia)
        {
            Console.WriteLine("\t" + distanceTowns);
        }

        Console.Write("Deque<string>: ");
        var people = new Deque<string>();
        people.AddToBack("Kiro");
        people.AddToBack("Maria");
        people.AddToFront("Steve");
        people.AddManyToBack(new string[] { "Ivan", "Veronika" });
        Console.WriteLine(people);

        Console.Write("BigList<int>: ");
        var ints = new BigList<int>();
        // var ints = new List<int>();
        for (int i = 0; i < 1000000; i++)
        {
            ints.Add(i);
        }
        for (int i = 0; i < 50000; i++)
        {
            ints.Insert(i, i);
        }
        Console.WriteLine(ints.Count);
    }
Example #32
0
        /// <summary>
        /// Deque<T>
        /// Double-ended queue (deque)
        /// </summary>
        private static void TestDeque()
        {
            Deque<Student> deque = new Deque<Student>();
            var student1 = new Student("First DUPLICATE", 21);
            var student2 = new Student("Second", 21);
            var student3 = new Student("Third", 22);
            var student4 = new Student("Forth", 23);
            var student5 = new Student("Fifth", 24);
            deque.AddToBack(student1);
            deque.AddToFront(student2);
            deque.AddToBack(student3);
            deque.AddToFront(student4);
            deque.AddToBack(student5);
            deque.AddToFront(student1);

            while (deque.Count != 0)
            {
                var student = deque.RemoveFromFront();
                Console.WriteLine(student);
            }
        }