public static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Presenting the functionality of the data structure 'BiDictionary' - allows");
            Console.WriteLine("adding values by two keys, searching by a single key or by both keys and");
            Console.WriteLine("removing values by both keys***");
            Console.Write(decorationLine);

            BiDictionary<string, string, Person> peopleDictionary =
                new BiDictionary<string, string, Person>();

            Console.WriteLine("---Test add operation---");
            foreach (Person person in people)
            {
                peopleDictionary.Add(person.FirstName, person.LastName, person);
            }

            Console.WriteLine("Count after addition: {0}", peopleDictionary.Count);
            Console.WriteLine();

            Console.WriteLine("---Test get values by first key---");
            string firstName = "Gosho";
            Console.WriteLine("All people with first name '{0}' are:", firstName);
            PrintPeopleOnConsole(peopleDictionary.GetByFirstKey(firstName));
            Console.WriteLine();

            Console.WriteLine("---Test get values by second key---");
            string lastName = "Peshov";
            Console.WriteLine("All people with last name '{0}' are:", lastName);
            PrintPeopleOnConsole(peopleDictionary.GetBySecondKey(lastName));
            Console.WriteLine();

            Console.WriteLine("---Test get values by first key and second key---");
            string firstKey = "Gosho";
            string secondKey = "Goshov";
            Console.WriteLine("All people with first name '{0}' and last name '{1}' are:",
                firstKey,
                secondKey);
            PrintPeopleOnConsole(peopleDictionary.GetByBothKeys(firstKey, secondKey));
            Console.WriteLine();

            Console.WriteLine("---Test remove operation---");
            Console.WriteLine("Removing all people with first key '{0}' and second key '{1}'",
                firstKey,
                secondKey);
            peopleDictionary.Remove(firstKey, secondKey);
            Console.WriteLine("Count of people after removal: {0}", peopleDictionary.Count);
            Console.WriteLine("Count of people with first name '{0}' after removal: {1}",
                firstKey,
                peopleDictionary.GetByFirstKey(firstKey).Count);
            Console.WriteLine("Count of people with last name '{0}' after removal: {1}",
                secondKey,
                peopleDictionary.GetBySecondKey(secondKey).Count);
            Console.WriteLine();

            Console.WriteLine("---Test clear operation---");
            peopleDictionary.Clear();
            Console.WriteLine("Count of people after clearing the dictionary: {0}", peopleDictionary.Count);
        }
Пример #2
0
        static void Main()
        {
            var bidict = new BiDictionary<string, int, string>(allowDuplicateValues: true);

            bidict.Add("pesho", 1, "JavaScript");
            bidict.Add("gosho", 2, "Java");
            bidict.Add("nakov", 3, "C#");
            bidict.Add("nakov", 3, "C#");
            bidict.Add("gosho", 3, "Coffee");
            bidict.Add("nakov", 1, "Python");

            Console.WriteLine(string.Join(" ", bidict.GetByFirstKey("nakov")));
            Console.WriteLine(string.Join(" ", bidict.GetBySecondKey(3)));
            Console.WriteLine(string.Join(" ", bidict.GetByFirstAndSecondKey("nakov", 3)));

            Console.WriteLine(bidict.Count);

            bidict.RemoveByFirstKey("gosho");
            Console.WriteLine(bidict.Count);

            bidict.RemoveBySecondKey(3);
            Console.WriteLine(bidict.Count);

            bidict.RemoveByFirstAndSecondKey("nakov", 1);
            Console.WriteLine(bidict.Count);


        }
Пример #3
0
    static void Main()
    {
        var bidictionary = new BiDictionary <string, int, string>(allowDuplicateValues: true);

        bidictionary.Add("pesho", 1, "JavaScript");
        bidictionary.Add("gosho", 2, "Java");
        bidictionary.Add("nakov", 3, "C#");
        bidictionary.Add("nakov", 3, "C#");
        bidictionary.Add("gosho", 3, "Coffee");
        bidictionary.Add("nakov", 1, "Python");

        Console.WriteLine(string.Join(" ", bidictionary.GetByFirstKey("nakov")));
        Console.WriteLine(string.Join(" ", bidictionary.GetBySecondKey(3)));
        Console.WriteLine(string.Join(" ", bidictionary.GetByFirstAndSecondKey("nakov", 3)));

        Console.WriteLine(bidictionary.Count);

        bidictionary.RemoveByFirstKey("gosho");
        Console.WriteLine(bidictionary.Count);

        bidictionary.RemoveBySecondKey(3);
        Console.WriteLine(bidictionary.Count);

        bidictionary.RemoveByFirstAndSecondKey("nakov", 1);
        Console.WriteLine(bidictionary.Count);
    }
Пример #4
0
        private static void Main()
        {
            var bidictionary = new BiDictionary<string, int, string>(true);

            bidictionary.Add("kircho", 1, "JavaScript");
            bidictionary.Add("mircho", 2, "Java");
            bidictionary.Add("svircho", 3, "C#");
            bidictionary.Add("shosho", 3, "C#");
            bidictionary.Add("gosho", 3, "Coffee");
            bidictionary.Add("tosho", 1, "Python");

            Console.WriteLine(string.Join(" ", bidictionary.GetByFirstKey("mircho")));
            Console.WriteLine(string.Join(" ", bidictionary.GetBySecondKey(3)));
            Console.WriteLine(string.Join(" ", bidictionary.GetByFirstAndSecondKey("svircho", 3)));

            Console.WriteLine(bidictionary.Count);

            bidictionary.RemoveByFirstKey("gosho");
            Console.WriteLine(bidictionary.Count);

            bidictionary.RemoveBySecondKey(3);
            Console.WriteLine(bidictionary.Count);

            bidictionary.RemoveByFirstAndSecondKey("tosho", 1);
            Console.WriteLine(bidictionary.Count);
        }
Пример #5
0
        public static void Main()
        {
            BiDictionary<string, int, string> biDictionary = new BiDictionary<string, int, string>(allowDuplicateValues: true);

            Random rand = new Random();
            for (int i = 0; i < 1000; i++)
            {
                biDictionary.Add("Item" + rand.Next(1, 30), rand.Next(10, 1000), "SecondItem" + rand.Next(40, 100));
            }

            Console.WriteLine("Test GET: ");
            Console.WriteLine(string.Join(" ", biDictionary.GetByFirstKey("Item3")));
            Console.WriteLine(string.Join(" ", biDictionary.GetBySecondKey(100)));
            Console.WriteLine(string.Join(" ", biDictionary.GetByFirstAndSecondKey("Item50", 300)));

            Console.Write("Dictionary Count: ");
            Console.WriteLine(biDictionary.Count);

            biDictionary.RemoveByFirstKey("Item10");
            Console.Write("Dictionary Count: ");
            Console.WriteLine(biDictionary.Count);

            biDictionary.RemoveBySecondKey(500);
            Console.Write("Dictionary Count: ");
            Console.WriteLine(biDictionary.Count);

            biDictionary.RemoveByFirstAndSecondKey("Item20", 200);
            Console.Write("Dictionary Count: ");
            Console.WriteLine(biDictionary.Count);
        }