Example #1
0
 public void Find()
 {
     Assert.IsFalse(list.Find(pred, out int i));
     list.AddAll(new int[] { 4, 22, 67, 37 });
     Assert.IsFalse(list.Find(pred, out i));
     list.AddAll(new int[] { 45, 122, 675, 137 });
     Assert.IsTrue(list.Find(pred, out i));
     Assert.AreEqual(45, i);
 }
        public void ClearShouldRemoveElement()
        {
            var hashtable = new HashSet <int>();

            hashtable.Add(10);

            Assert.IsTrue(hashtable.Find(10));

            hashtable.Clear();

            Assert.IsFalse(hashtable.Find(10));
        }
        public void RemoveShouldWorkProperly()
        {
            var hashtable = new HashSet <int>();

            hashtable.Add(10);

            Assert.IsTrue(hashtable.Find(10));

            hashtable.Remove(10);

            Assert.IsFalse(hashtable.Find(10));
        }
        public void ClearShouldRemoveElement()
        {
            var hashtable = new HashSet<int>();

            hashtable.Add(10);

            Assert.IsTrue(hashtable.Find(10));

            hashtable.Clear();

            Assert.IsFalse(hashtable.Find(10));
        }
        public void HashSetShouldFindElementsCorrectly()
        {
            var set = new HashSet<int>();
            set.Add(0);
            set.Add(1);
            set.Add(2);
            set.Add(3);

            Assert.IsTrue(set.Find(0));
            Assert.IsTrue(set.Find(1));
            Assert.IsTrue(set.Find(2));
            Assert.IsTrue(set.Find(3));
            Assert.IsFalse(set.Find(4));
        }
        public void HashSetShouldFindElementsCorrectly()
        {
            var set = new HashSet <int>();

            set.Add(0);
            set.Add(1);
            set.Add(2);
            set.Add(3);

            Assert.IsTrue(set.Find(0));
            Assert.IsTrue(set.Find(1));
            Assert.IsTrue(set.Find(2));
            Assert.IsTrue(set.Find(3));
            Assert.IsFalse(set.Find(4));
        }
Example #7
0
        public virtual bool Find(ref T item)
        {
            KeyValuePair <T, int> p = new KeyValuePair <T, int>(item, 0);

            if (dict.Find(ref p))
            {
                item = p.Key;
                return(true);
            }

            return(false);
        }
        public void FindShouldReturnTrueForAddedElement()
        {
            var hashtable = new HashSet<string>();

            hashtable.Add("aaa");

            Assert.IsTrue(hashtable.Find("aaa"));
        }
        public void FindShouldReturnTrueForAddedElement()
        {
            var hashtable = new HashSet <string>();

            hashtable.Add("aaa");

            Assert.IsTrue(hashtable.Find("aaa"));
        }
        public void HashSetShouldRemoveElementCorrectly()
        {
            var set = new HashSet<int>();
            set.Add(0);
            set.Remove(0);

            Assert.IsFalse(set.Find(0));
            Assert.AreEqual(0, set.Count);
        }
        public void HashSetShouldClearElementCorrectly()
        {
            var set = new HashSet <int>();

            set.Add(0);
            set.Clear();

            Assert.IsFalse(set.Find(0));
            Assert.AreEqual(0, set.Count);
        }
Example #12
0
        public static void AddToLibrary(IInterpreterFunction f)
        {
            //если функция с таким именем есть - заменяем
            var oldFunc = AdditionalLibrary.Find(curF => curF.Name == f.Name);

            if (oldFunc != null)
            {
                AdditionalLibrary.Remove(oldFunc);
            }

            AdditionalLibrary.Add(f);
        }
Example #13
0
 static void Main(string[] args)
 {
     try
     {
         HashSet<int> set = new HashSet<int>();
         set.Add(13);
         set.Add(14);
         set.Add(15);
         set.Add(16);
         set.Add(17);
         Console.WriteLine(set.Find(14));
         Console.WriteLine("Count: {0}", set.Count);
         set.Remove(14);
         Console.WriteLine("Count: {0}", set.Count);
         Console.WriteLine(set.Find(14));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #14
0
        public static void Main()
        {
            try
            {
                HashSet<int> hashSet = new HashSet<int>();

                hashSet.Add(1);
                hashSet.Add(5);
                hashSet.Add(2);
                hashSet.Add(33);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                hashSet.Remove(2);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                Console.WriteLine(hashSet.Find(5));
                Console.WriteLine(hashSet.Contains(5));

                int[] numArray = new int[] { 5, 11, 33 };
                int[] array = numArray;
                hashSet.UnionWith(array);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                int[] numArray1 = new int[] { 5, 11, 22 };
                int[] array2 = numArray1;
                hashSet.Intersect(array2);
                Console.WriteLine("Count is : {0}", hashSet.Count);

                hashSet.Clear();
                Console.WriteLine("Count is : {0}", hashSet.Count);
                Console.WriteLine(hashSet.Find(5));
            }
            catch (ArgumentException aex)
            {
                Console.WriteLine(aex.Message);
            }
        }
        static void Main(string[] args)
        {
            HashSet<string> hashSet = new HashSet<string>();

            hashSet.Add("ooo");
            hashSet.Add("qqq");
            hashSet.Add("ppp");
            hashSet.Add("iii");

            foreach (var item in hashSet.Items)
            {
                Console.WriteLine(item);
            }

            hashSet.Remove("iii");
            Console.WriteLine("\nCount after removal: {0}", hashSet.Count);


            Console.WriteLine();
            Console.WriteLine(hashSet.Find("ppp"));


            HashSet<string> secondHashSet = new HashSet<string>();
            secondHashSet.Add("www");
            secondHashSet.Add("qqq");
            secondHashSet.Add("yyy");
            secondHashSet.Add("ooo");

            Console.WriteLine("\nUnion: ");
            HashSet<string> union = hashSet.Union(secondHashSet);
            foreach (var item in union.Items)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nIntersection: ");
            HashSet<string> intersection = hashSet.Intersect(secondHashSet);
            foreach (var item in intersection.Items)
            {
                Console.WriteLine(item);
            }
        }
Example #16
0
            public void Contains()
            {
                Assert.IsFalse(hashset.Contains(5));
                hashset.Add(5);
                Assert.IsTrue(hashset.Contains(5));
                Assert.IsFalse(hashset.Contains(7));
                hashset.Add(8);
                hashset.Add(10);
                Assert.IsTrue(hashset.Contains(5));
                Assert.IsFalse(hashset.Contains(7));
                Assert.IsTrue(hashset.Contains(8));
                Assert.IsTrue(hashset.Contains(10));
                hashset.Remove(8);
                Assert.IsTrue(hashset.Contains(5));
                Assert.IsFalse(hashset.Contains(7));
                Assert.IsFalse(hashset.Contains(8));
                Assert.IsTrue(hashset.Contains(10));
                hashset.Add(0);
                hashset.Add(16);
                hashset.Add(32);
                hashset.Add(48);
                hashset.Add(64);
                Assert.IsTrue(hashset.Contains(0));
                Assert.IsTrue(hashset.Contains(16));
                Assert.IsTrue(hashset.Contains(32));
                Assert.IsTrue(hashset.Contains(48));
                Assert.IsTrue(hashset.Contains(64));
                Assert.IsTrue(hashset.Check());

                int i = 0, j = i;

                Assert.IsTrue(hashset.Find(ref i));
                Assert.AreEqual(j, i);
                j = i = 16;
                Assert.IsTrue(hashset.Find(ref i));
                Assert.AreEqual(j, i);
                j = i = 32;
                Assert.IsTrue(hashset.Find(ref i));
                Assert.AreEqual(j, i);
                j = i = 48;
                Assert.IsTrue(hashset.Find(ref i));
                Assert.AreEqual(j, i);
                j = i = 64;
                Assert.IsTrue(hashset.Find(ref i));
                Assert.AreEqual(j, i);
                j = i = 80;
                Assert.IsFalse(hashset.Find(ref i));
                Assert.AreEqual(j, i);
            }
Example #17
0
        private static void Obj_AI_Base_OnTeleport(GameObject sender, Teleport.TeleportEventArgs args)
        {
            var unit = sender as AIHeroClient;

            if (unit == null || !unit.IsValid || unit.IsAlly)
            {
                return;
            }

            var ChampionInfoOne = ChampionInfoList.Find(x => x.Hero.NetworkId == sender.NetworkId);

            var recall = new RecallInf(unit.NetworkId, args.Status, args.Type, args.Duration, args.Start);

            if (recall.Type == TeleportType.Recall)
            {
                switch (recall.Status)
                {
                case TeleportStatus.Start:
                    ChampionInfoOne.StartRecallTime = Game.Time;
                    break;

                case TeleportStatus.Abort:
                    ChampionInfoOne.AbortRecallTime = Game.Time;
                    break;

                case TeleportStatus.Finish:
                    ChampionInfoOne.FinishRecallTime = Game.Time;
                    var spawnPos = ObjectManager.Get <Obj_SpawnPoint>().FirstOrDefault(x => x.IsEnemy).Position;
                    ChampionInfoOne.LastVisablePos  = spawnPos;
                    ChampionInfoOne.PredictedPos    = spawnPos;
                    ChampionInfoOne.LastWayPoint    = spawnPos;
                    ChampionInfoOne.LastVisableTime = Game.Time;
                    break;
                }
            }
        }
        public void RemoveShouldWorkProperly()
        {
            var hashtable = new HashSet<int>();

            hashtable.Add(10);

            Assert.IsTrue(hashtable.Find(10));

            hashtable.Remove(10);

            Assert.IsFalse(hashtable.Find(10));
        }
Example #19
0
        static void Main(string[] args)
        {
            IHashSet<int> sampleOne = new HashSet<int>();
           
            sampleOne.Add(1);
            sampleOne.Add(1);
            sampleOne.Add(2);
            sampleOne.Add(3);
            sampleOne.Add(4);
            sampleOne.Add(5);
            sampleOne.Add(6);
            sampleOne.Add(7);
            sampleOne.Add(8);
            sampleOne.Add(9);

             IHashSet<int> sampleTwo = new HashSet<int>();

            sampleTwo.Add(1);
            sampleTwo.Add(2);
            sampleTwo.Add(9);
            sampleTwo.Add(100);


            Console.WriteLine("sampleOne:");
            foreach (var item in sampleOne)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("sampleTwo:");
            foreach (var item in sampleTwo)
            {
                Console.WriteLine(item);
            }


            IHashSet<int> intersected = sampleOne.Intersect(sampleTwo);

            Console.WriteLine("Intesected of sampleOne and sampleTwo:");
            foreach (var item in intersected)
            {
                Console.WriteLine(item);
            }

            IHashSet<int> union = sampleOne.Union(sampleTwo);

            Console.WriteLine("Union of sampleOne and sampleTwo:");
            foreach (var item in union)
            {
                Console.WriteLine(item);
            }

            int founded = sampleOne.Find(1);
            Console.WriteLine("Look for '1':" + founded);

            Console.WriteLine("Count:" + sampleOne.Count);
            sampleOne.Remove(3);
            sampleOne.Clear();
            Console.WriteLine("Count after clear:" + sampleOne.Count);

        }
        public void FindShouldReturnFalseIfKeyIsNotAdded()
        {
            var hashtable = new HashSet <string>();

            Assert.IsFalse(hashtable.Find("aaa"));
        }
        public void FindShouldReturnFalseIfKeyIsNotAdded()
        {
            var hashtable = new HashSet<string>();

            Assert.IsFalse(hashtable.Find("aaa"));
        }