Пример #1
0
        static void Main()
        {
            var biDictionary =
                new BiDictionary<int, string, DateTime>(
                    new MultiDictionary<int, Triple<int, string, DateTime>>(true),
                    new MultiDictionary<string, Triple<int, string, DateTime>>(true),
                    new MultiDictionary<CompositeKey<int, string>, Triple<int, string, DateTime>>(true));

            biDictionary.AddByFirstKey(1, new Triple<int, string, DateTime>(1, "one", DateTime.Today));
            biDictionary.AddBySecondKey("two", new Triple<int, string, DateTime>(2, "two", DateTime.Today));
            biDictionary.AddByCompositeKey(new CompositeKey<int, string>(3, "three"), new Triple<int, string, DateTime>(3, "three", DateTime.Today));

            Console.WriteLine("Elements: " + biDictionary.Count);
            Console.WriteLine("T1 keys: " + string.Join(", ", biDictionary.KeysT1));
            Console.WriteLine("T2 keys: " + string.Join(", ", biDictionary.KeysT2));
            Console.WriteLine("Composite keys: " + string.Join(", ", biDictionary.KeysComposite));

            foreach (var key in biDictionary)
            {
                foreach (var triple in key.Value)
                {
                    Console.WriteLine($"Triple: K1: {triple.FirstKey}; K2: {triple.SecondKey}; V: {triple.Value}");
                }
            }
        }
Пример #2
0
        public static void Main()
        {
            BiDictionary<string, string, string> phonebook = new BiDictionary<string, string, string>(true);

            using (StreamReader inputReader = new StreamReader(@"../../phone.txt"))
            {
                string line = inputReader.ReadLine();

                while (line != null)
                {
                    string[] splitedLine = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    phonebook.AddByBothKeys(splitedLine[0].Trim(), splitedLine[1].Trim(), splitedLine[2].Trim());

                    phonebook.AddByFirstKey(splitedLine[0].Trim(), splitedLine[2].Trim());
                    phonebook.AddBySecondKey(splitedLine[1].Trim(), splitedLine[2].Trim());

                    line = inputReader.ReadLine();
                }
            }

            // command parser
            using (StreamReader inputReader = new StreamReader(@"../../commands.txt"))
            {
                string line = inputReader.ReadLine();

                while (line != null)
                {
                    Console.WriteLine(line);
                    string[] splitedLine = line.Split(new char[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);

                    if (splitedLine.Length == 2)
                    {
                        var result = phonebook.FindByFirstKey(splitedLine[1]);
                        foreach (var element in result)
                        {
                            Console.WriteLine(element);
                        }
                    }
                    else
                    {
                        var result = phonebook.FindByFirstAndSecondKey(splitedLine[1].Trim(), splitedLine[2].Trim());
                        foreach (var element in result)
                        {
                            Console.WriteLine(element);
                        }
                    }

                    line = inputReader.ReadLine();
                }
            }
        }