Example #1
0
    static void Main()
    {
        BiDictionary <string, string, string> dictionary = new BiDictionary <string, string, string>();

        dictionary.Add("Sofia", "man", "Ivo Ivanov");
        dictionary.Add("Sofia", "woman", "Maria Ivanova");
        dictionary.Add("Plovdiv", "man", "Peter Petrov");
        dictionary.Add("Plovdiv", "woman", "Lili Georgieva");


        var fromSofia = dictionary.FindByFistKey("Sofia");

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

        var manGender = dictionary.FindBySecondKey("man");

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

        var manFromPlovdiv = dictionary.FindByBothKeys("Plovdiv", "man");

        foreach (var item in manFromPlovdiv)
        {
            Console.WriteLine(item);
        }
    }
Example #2
0
        public static void Main()
        {
            var multi = new BiDictionary<int, string, string>();

            multi.Add(1, "one", "firstElement");

            multi.Add(1, "two", "mixed");

            multi.Add(2, "two", "secondElement");

            Console.WriteLine("first key :");
            var result1 = multi.FindByFirstKey(1);
            foreach (var item in result1)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("second key :");
            var result2 = multi.FindBySecondKey("two");
            foreach (var item in result2)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("both keys :");
            var result3 = multi.FindByBothKeys(1, "two");
            foreach (var item in result3)
            {
                Console.WriteLine(item);
            }
        }
        public static void Main()
        {
            var biDict = new BiDictionary<string, string, List<int>>();

            biDict.Add("Ivan", "DSA", new List<int>() { 100, 20, 30 });
            biDict.Add("Pesho", "HQC", new List<int>() { 10, 40, 25 });
            biDict.Add("Gosho", "DSA", new List<int>() { 55, 66, 77 });
            biDict.Add("Gosho", "HQC", new List<int>() { 5, 6, 7 });

            Console.WriteLine("Searching Pesho's scores");
            var result1 = biDict.FindByFirstKey("Pesho");
            foreach (var item in result1)
            {
                Console.WriteLine(string.Join(", ", item));
            }

            Console.WriteLine("--------------------------------");
            Console.WriteLine("Searching for all scores in DSA");
            var result2 = biDict.FindBySecondKey("DSA");
            foreach (var item in result2)
            {
                Console.WriteLine(string.Join(", ", item));
            }

            Console.WriteLine("--------------------------------");
            Console.WriteLine("Searching for DSA's scores of Gosho");
            var result3 = biDict.FindByBothKeys("Gosho", "DSA");
            foreach (var item in result3)
            {
                Console.WriteLine(string.Join(", ", item));
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            BiDictionary<string, string, string> dictionary = new BiDictionary<string, string, string>();
            dictionary.Add("Sofia", "man", "Ivo Ivanov");
            dictionary.Add("Sofia", "woman", "Maria Ivanova");
            dictionary.Add("Plovdiv", "man", "Peter Petrov");
            dictionary.Add("Plovdiv", "woman", "Lili Georgieva");
            
            Console.WriteLine("\nAll from Sofia");
            var fromSofia = dictionary.FindByFistKey("Sofia");
            foreach (var item in fromSofia)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nAll man");
            var manGender = dictionary.FindBySecondKey("man");
            foreach (var item in manGender)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nAll Plovdiv and man");
            var manFromPlovdiv = dictionary.FindByBothKeys("Plovdiv", "man");
            foreach (var item in manFromPlovdiv)
            {
                Console.WriteLine(item);
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            var biDict = new BiDictionary<int, string, string>();

            for (int i = 0; i < 20; i++)
            {
                var name = "Pesho" + i;
                var result = "Result" + i;
                biDict.Add(i, name, result);
            }

            var firstTry = biDict.FindByFirstKey(1);
            foreach (var item in firstTry)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("----------");

            var secondTry = biDict.FindBySecondKey("Pesho2");
            foreach (var item in secondTry)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("----------");

            var thirdTry = biDict.FindByTwoKeys(2, "Pesho2");
            foreach (var item in thirdTry)
            {
                Console.WriteLine(item);
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            BiDictionary<string, string, string> dictionary = new BiDictionary<string, string, string>();
            dictionary.Add("Lovech", "man", "Georgi Georgiev");
            dictionary.Add("Lovech", "woman", "Nina Todorova");
            dictionary.Add("Lovech", "woman", "Martina Nikolova");
            dictionary.Add("Sofia", "woman", "Elizabet Sokolova");
            dictionary.Add("Lovech", "man", "Tosho Kyltyrista");

            Console.WriteLine("People from Lovech:");
            foreach (var item in dictionary.FindByFistKey("Lovech"))
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();
            Console.WriteLine("Girls:");
            var girls = dictionary.FindBySecondKey("woman");
            foreach (var girl in girls)
            {
                Console.WriteLine(girl);
            }

            Console.WriteLine();
            Console.WriteLine("Me and Tosho");
            foreach (var person in dictionary.FindByBothKeys("Lovech", "man"))
            {
                Console.WriteLine(person);
            }
        }
        static void Main(string[] args)
        {
            BiDictionary<string, string, string> dictionary = new BiDictionary<string, string, string>();
            dictionary.Add("Ivko", "mivko", "Ivko Mivko");
            dictionary.Add("Telerik", "Academy", "Telerik aka");
            dictionary.Add("Telerik", "asdf", "Peter Petrov");
            dictionary.Add("asdf", "Academy", "Dancho Danchev");


            var fromSofia = dictionary.FindByFistKey("Ivko");
            foreach (var item in fromSofia)
            {
                Console.WriteLine(item);
            }

            var manGender = dictionary.FindBySecondKey("asdf");
            foreach (var item in manGender)
            {
                Console.WriteLine(item);
            }

            var manFromPlovdiv = dictionary.FindByBothKeys("Telerik", "Academy");
            foreach (var item in manFromPlovdiv)
            {
                Console.WriteLine(item);
            }
        }
        public static void Main()
        {
            var biDictionary = new BiDictionary<bool, int, string>();

            biDictionary.Add(true, 18, "Ivan Petrov");
            biDictionary.Add(false, 18, "Gergana Mihova");
            biDictionary.Add(true, 30, "Petkan Iliev");
            biDictionary.Add(false, 25, "Ani Petrova");
            biDictionary.Add(true, 45, "Georgi Ivanov");
            biDictionary.Add(true, 45, "Pesho Goshov");
            biDictionary.Add(true, 45, "Miho Mihov");
            biDictionary.Add(false, 28, "Petranka Petrova");
            biDictionary.Add(false, 28, "Ivanka Ivanova");
            biDictionary.Add(false, 28, "Pepa Petrova");

            // all men
            Console.WriteLine(biDictionary.FindByFirstKey(true));

            // all 45 years old
            Console.WriteLine(biDictionary.FindBySecondKey(45));

            // all women 28 years old
            Console.WriteLine(biDictionary.FindByBothKeys(false, 28));

            // all 50 years old men
            Console.WriteLine(biDictionary.FindByBothKeys(true, 50)); // empty collection !!!
        }
        public static void Main()
        {
            BiDictionary<string, string, Student> students = new BiDictionary<string, string, Student>();
            List<string> firstKeysTest = new List<string>();
            List<string> secondKeysTest = new List<string>();
            List<string> bothKeysTest = new List<string>();
            Random random = new Random();
            for (int i = 0; i < 10; i++)
            {
                var lengthFirstName = random.Next(2, 20);
                string firstName = GetRandomString(lengthFirstName, random);
                var lengthLastName = random.Next(2, 20);
                string lastName = GetRandomString(lengthLastName, random);
                Student student1 = new Student(firstName, lastName);
                students.Add(student1.FirstName, student1.LastName, student1);
                firstKeysTest.Add(student1.FirstName);
                secondKeysTest.Add(student1.LastName);
                bothKeysTest.Add(student1.FirstName + student1.LastName);
                if (i % 2 == 0)
                {
                    Student student2 = new Student(firstName, lastName);
                    students.Add(student2.FirstName, student2.LastName, student2);
                    firstKeysTest.Add(student2.FirstName);
                    secondKeysTest.Add(student2.LastName);
                    bothKeysTest.Add(student2.FirstName + student2.LastName);
                }
            }

            for (int i = 0; i < 10; i++)
            {
                var searchedFirstNameIndex = random.Next(0, firstKeysTest.Count);
                var studentsByFirstName = students.FindByFirstKey(firstKeysTest[searchedFirstNameIndex]);
                Console.WriteLine("New Search");
                Console.WriteLine("Students searched by first name:");
                foreach (var st in studentsByFirstName)
                {
                    Console.WriteLine("Student:" + st.FirstName + " " + st.LastName);
                }

                var searchedLastNameIndex = random.Next(0, secondKeysTest.Count);
                var studentsByLastName = students.FindBySecondKey(secondKeysTest[searchedLastNameIndex]);
                Console.WriteLine("Students searched by last name:");
                foreach (var st in studentsByLastName)
                {
                    Console.WriteLine("Student:" + st.FirstName + " " + st.LastName);
                }

                var studentsByBothNames = students.FindByBothKeys(firstKeysTest[i], secondKeysTest[i]);
                Console.WriteLine("Students searched by both names:");
                foreach (var st in studentsByBothNames)
                {
                    Console.WriteLine("Student: " + st.FirstName + " " + st.LastName);
                }

                Console.WriteLine();
            }
        }
 public static void Main()
 {
     var distances = new BiDictionary<string, string, int>();
     distances.Add("Sofia", "Varna", 443);
     distances.Add("Sofia", "Varna", 468);
     distances.Add("Sofia", "Varna", 490);
     distances.Add("Sofia", "Plovdiv", 145);
     distances.Add("Sofia", "Bourgas", 383);
     distances.Add("Plovdiv", "Bourgas", 253);
     distances.Add("Plovdiv", "Bourgas", 292);
     var distancesFromSofia = distances.FindByFirstKey("Sofia"); // [443, 468, 490, 145, 383]
     var distancesToBourgas = distances.FindBySecondKey("Bourgas"); // [383, 253, 292]
     var distancesPlovdivBourgas = distances.Find("Plovdiv", "Bourgas"); // [253, 292]
     var distancesRousseVarna = distances.Find("Rousse", "Varna"); // []
     var distancesSofiaVarna = distances.Find("Sofia", "Varna"); // [443, 468, 490]
     distances.Remove("Sofia", "Varna"); // true
     var distancesFromSofiaAgain = distances.FindByFirstKey("Sofia"); // [145, 383]
     var distancesToVarna = distances.FindBySecondKey("Varna"); // []
     var distancesSofiaVarnaAgain = distances.Find("Sofia", "Varna"); // []
 }
Example #11
0
        public static void Main()
        {
            var dictionary = new BiDictionary<int, string, string>(true);
            dictionary.Add(1, "1", "value 1");
            dictionary.Add(2, "2", "value 2");
            dictionary.Add(3, "3", "value 3");
            dictionary.Add(3, "3", "value 3.1");

            Console.WriteLine(string.Join(", ", dictionary.FindByFirstKey(1)));
            Console.WriteLine(string.Join(", ", dictionary.FindBySecondKey("2")));
            Console.WriteLine(string.Join(", ", dictionary.FindByBothKeys(3, "3")));
        }
Example #12
0
        public static void Main()
        {
            BiDictionary<decimal, int, int> biDictionary = new BiDictionary<decimal, int, int>();
            for (int i = 0; i < 500; i++)
            {
                decimal key1 = RandomNumber(1, 6);
                int key2 = RandomNumber(1, 6);
                int value = Random.Next(1, 1000);
                biDictionary.Add(key1, key2, value);
            }

            var firstKeyResults = biDictionary.FindByFirstKey(2);
            var secondKeyResults = biDictionary.FindBySecondKey(4);
            var twoKeysResult = biDictionary.FindByTwoKeys(2, 4);
        }
Example #13
0
        static void Main(string[] args)
        {
            BiDictionary<string, int, string> collection = new BiDictionary<string, int, string>();
            collection.Add("Pesho", 1, "Zagorka");
            collection.Add("Mincho", 2, "Astika");
            collection.Add("Minka", 2, "Grozde");
            collection.Add("Gosho", 1, "Heineken");
            collection.Add("Pesho", 3, "HB");
            collection.Add("Doncho", 1, "Dubel");

            var find = collection.FindBySecondKey(1);
            foreach (var item in find)
            {
                Console.WriteLine(item);
            }
        }
Example #14
0
        static void Main()
        {
            var dictionary = new BiDictionary<int, double, string>();

            dictionary.Add(1, 1.5, "mariq");
            dictionary.Add(3, 3.01, "GANCHO");
            dictionary.Add(1, 1.5, "pesho");
            dictionary.Add(2, 50.9, "gosho");
            dictionary.Add(2, 50.9, "drago");
            dictionary.Add(2, 50.9, "dragan");

            var byFirstKey = dictionary.FindByFirstKey(1);
            Console.WriteLine("search by first key: {0}", string.Join(", ", byFirstKey));

            var bySecondKey = dictionary.FindBySecondKey(3.01);
            Console.WriteLine("search by second key: {0}", string.Join(", ", bySecondKey));

            var byBothKeys = dictionary.FindByBothKeys(2, 50.9);
            Console.WriteLine("search by both keys: {0}", string.Join(", ", byBothKeys));
        }
Example #15
0
        public static void Main()
        {
            var dict = new BiDictionary<int, int, string>(true);

            dict.Add(1, 2, "Pesho");
            dict.Add(1, 2, "Gosho");
            dict.Add(1, 3, "Mimi");
            dict.Add(1, 3, "Gimi");
            dict.Add(2, 3, "Dimi");
            dict.Remove(1, 3, "Gimi");

            for (int i = 0; i < 1000000; i++)
            {
                dict.Add(i+1, i+2, "Pesho"+i);
            }

            Console.WriteLine("Find by first key");
            dict.FindByFirstKey(1).ForEach(x => Console.WriteLine(x));
            Console.WriteLine("Find by second key");
            dict.FindBySecondKey(4).ForEach(x => Console.WriteLine(x));
            Console.WriteLine("Find by both keys");
            dict.FindByBothKeys(1, 3).ForEach(x => Console.WriteLine(x));
        }
    public static void Main()
    {
        BiDictionary<int, double, string> biDictionary = new BiDictionary<int, double, string>(true);
        biDictionary.Add(1, 1.1, "a");
        biDictionary.AddMany(2, 2.4, new string[] { "c", "d", "e" });
        biDictionary.Add(3, 3.3, "z");
        var firstFound = biDictionary.FindByFirstKey(2);
        foreach (var item in firstFound)
        {
            Console.WriteLine("{0} key {1} value", item.Key, item.Value);
        }

        var secondFound = biDictionary.FindBySecondKey(1.1);
        foreach (var item in secondFound)
        {
            Console.WriteLine("{0} key {1} value", item.Key, item.Value);
        }

        var bothFound = biDictionary.FindByBothKeys(3, 3.3);
        foreach (var item in bothFound)
        {
            Console.WriteLine("{0} key {1} value", item.Key, item.Value);
        }
    }