/* Task 3: 
     * Implement a class BiDictionary<K1,K2,T> that allows adding triples {key1, key2, value} and 
     * fast search by key1, key2 or by both key1 and key2. Note: multiple values can be stored for given key.
     */

    //Note: since removing of keys is not requested I have not implemented it. 

    static void Main(string[] args)
    {
        var biDictionary = new BiDictionary<string, int, int>();

        biDictionary.Add("Pesho", 4);
        biDictionary.Add("Pesho", 5);
        biDictionary.Add("Pesho", 3);
        biDictionary.Add(23, 6);
        biDictionary.Add("Maria", 13, 5);
        biDictionary.Add("Maria", 13, 2);
        biDictionary.Add("Maria", 13, 4);
        biDictionary.Add("Maria", 13, 6);

        foreach (var item in biDictionary.GetValueByFirstKey("Pesho"))
        {
            Console.WriteLine(item);
        }

        foreach (var item in biDictionary.GetValueBySecondKey(23))
        {
            Console.WriteLine(item);
        }

        foreach (var item in biDictionary.GetValueByBothKeys("Maria", 13))
        {
            Console.WriteLine(item);
        }
    }
Ejemplo n.º 2
0
 public static void Main()
 {
     BiDictionary<string, string, int> myBiDictionary = new BiDictionary<string, string, int>();
     myBiDictionary.Add("Petyr", "Petrov", 30);
     Console.WriteLine(string.Join(", ", myBiDictionary.GetValueByFirstKey("Petyr")));
     Console.WriteLine(string.Join(", ", myBiDictionary.GetValueBySecondKey("Petrov")));
     Console.WriteLine(string.Join(", ", myBiDictionary.GetValueByBothKeys("Petyr", "Petrov")));
 }
        private static void Main()
        {
            var dict = new BiDictionary<string, int, string>(true);

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

            Console.WriteLine(string.Join(" ", dict.GetValueByFirstKey("nakov")));
            Console.WriteLine(string.Join(" ", dict.GetValueBySecondKey(3)));
            Console.WriteLine(string.Join(" ", dict.GetValueByBothKeys("nakov", 3)));
        }