Exemplo n.º 1
0
        public ICollection <T> Find(K2 key)
        {
            if (orderedCollectionByKey2.ContainsKey(key))
            {
                return(orderedCollectionByKey2[key]);
            }

            return(null);
        }
        public static void Main()
        {
            var reader = new StreamReader("../../Students.txt");

            var dictionary = new OrderedMultiDictionary<string, Student>(true);

            string line = reader.ReadLine();

            while (line != null)
            {
                string[] splitedLine = line.Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries).Select(word => word.Trim()).ToArray();

                Student student = new Student(splitedLine[0], splitedLine[1]);
                if(!dictionary.ContainsKey(splitedLine[2]))
                {
                    dictionary.Add(splitedLine[2], student);
                }
                else
                {
                    dictionary[splitedLine[2]].Add(student);
                }

                line = reader.ReadLine();
            }

            foreach (var pair in dictionary)
            {
                Console.Write(pair.Key + " : ");

                var orderedList = pair.Value.OrderBy(v => v.LastName).ThenBy(v => v.FirstName).ToList();

                Console.WriteLine(string.Join(", ", orderedList.Select(s => s.FirstName + " " + s.LastName)));
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            var allStudentsText = new StreamReader("students.txt");

            var dict = new OrderedMultiDictionary <string, Tuple <string, string> >(true);

            var line = allStudentsText.ReadLine();

            while (line != null)
            {
                var tokens = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();

                if (!dict.ContainsKey(tokens[2]))
                {
                    dict.Add(tokens[2], new Tuple <string, string>(tokens[0], tokens[1]));
                }
                else
                {
                    dict[tokens[2]].Add(new Tuple <string, string>(tokens[0], tokens[1]));
                }

                line = allStudentsText.ReadLine();
            }

            foreach (var kv in dict)
            {
                Console.Write(kv.Key + ": ");
                Console.WriteLine(string.Join(", ", kv.Value.OrderBy(x => x.Item2).ThenBy(x => x.Item1).Select(x => x.Item1 + " " + x.Item2)));
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            int productsNumber = int.Parse(Console.ReadLine());
            var productsOrderedByPrice = new OrderedMultiDictionary<float, string>(true);

            for (int i = 0; i < productsNumber; i++)
            {
                string name = Console.ReadLine();
                float price = float.Parse(Console.ReadLine());

                if (!productsOrderedByPrice.ContainsKey(price))
                {
                    productsOrderedByPrice.Add(price, name);
                }
                else
                {
                    productsOrderedByPrice[price].Add(name);
                }
            }

            var startPrice = float.Parse(Console.ReadLine());
            var endPrice = float.Parse(Console.ReadLine());

            var range = productsOrderedByPrice.Range(startPrice, true, endPrice, true).Take(20);

            foreach (var keyValuePair in range)
            {
                Console.WriteLine("{0} -> {1}", keyValuePair.Key, keyValuePair.Value);
            }
        }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        OrderedMultiDictionary <decimal, Article> priceArticles =
            new OrderedMultiDictionary <decimal, Article>(true);

        decimal minPrice = 7;
        decimal maxPrice = 8;

        Random randomGen = new Random();

        for (int i = 0; i < 1000; i++)
        {
            Article article = new Article("Barcode" + (i + 1), "Vendor" + (i + 1), "Article" + (i + 1),
                                          randomGen.Next(1, 11));
            if (!priceArticles.ContainsKey(article.Price))
            {
                priceArticles.Add(article.Price, article);
            }
            else
            {
                priceArticles[article.Price].Add(article);
            }
        }

        PrintArticles(priceArticles, minPrice, maxPrice);
    }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            Random randGen = new Random();
            OrderedMultiDictionary<Article, int> articles = new OrderedMultiDictionary<Article, int>(false);

            for (int i = 0; i < 100; i++)
            {
                Article myArticle = new Article(randGen.Next(10000, 99999), "Vendor" + i, "Title" + i, randGen.Next(1000, 9999));

                if (!articles.ContainsKey(myArticle))
                {
                    articles.Add(myArticle, 1);
                }
            }

            Console.WriteLine("Enter bottom price:");
            int startPrice = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter top price:");
            int endPrice = int.Parse(Console.ReadLine());

            OrderedMultiDictionary<Article, int>.View neededArticles = articles.Range(
                new Article(0, string.Empty, string.Empty, 2000),
                true,
                new Article(0, string.Empty, string.Empty, 4000),
                true);

            foreach (var item in neededArticles)
            {
                Console.WriteLine(item.Key);
            }
        }
Exemplo n.º 7
0
        public static void Main()
        {
            var products = new OrderedMultiDictionary <double, string>(false);

            int numberOfProducts = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfProducts; i++)
            {
                string[] productArgs = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   product     = productArgs[0];
                double   price       = double.Parse(productArgs[1]);
                if (!products.ContainsKey(price))
                {
                    products.Add(price, product);
                }
                else
                {
                    products[price].Add(product);
                }
            }

            string[] range = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            double   start = double.Parse(range[0]);
            double   end   = double.Parse(range[1]);

            var priceRange = products.Range(start, true, end, true);

            foreach (var price in priceRange.Keys)
            {
                foreach (var product in products[price])
                {
                    Console.WriteLine("{0:F2} {1}", price, product);
                }
            }
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            int productsNumber         = int.Parse(Console.ReadLine());
            var productsOrderedByPrice = new OrderedMultiDictionary <float, string>(true);

            for (int i = 0; i < productsNumber; i++)
            {
                string name  = Console.ReadLine();
                float  price = float.Parse(Console.ReadLine());

                if (!productsOrderedByPrice.ContainsKey(price))
                {
                    productsOrderedByPrice.Add(price, name);
                }
                else
                {
                    productsOrderedByPrice[price].Add(name);
                }
            }

            var startPrice = float.Parse(Console.ReadLine());
            var endPrice   = float.Parse(Console.ReadLine());

            var range = productsOrderedByPrice.Range(startPrice, true, endPrice, true).Take(20);

            foreach (var keyValuePair in range)
            {
                Console.WriteLine("{0} -> {1}", keyValuePair.Key, keyValuePair.Value);
            }
        }
Exemplo n.º 9
0
 private static void ExecuteFindProductsByProducerCommand(string token)
 {
     if (prodDict.ContainsKey(token))
     {
         foreach (var item in prodDict.Values)
         {
             if (item.Producer == token)
             {
                 output.Append(item.ToString());
                 output.Append(Environment.NewLine);
             }
         }
     }
     else
     {
         output.Append("No products found");
         output.Append(Environment.NewLine);
     }
 }
Exemplo n.º 10
0
 public void AddPlayer(string playerName, int playerScore)
 {
     if (!scoreBoard.ContainsKey(playerScore))
     {
         scoreBoard.Add(playerScore, playerName);
     }
     else
     {
         scoreBoard[playerScore].Add(playerName);
     }
 }
Exemplo n.º 11
0
        public ICollection <AssemblyName> this[string name]
        {
            get
            {
                OrderedMultiDictionary <String, AssemblyName> cache = _cache;

                if (cache.ContainsKey(name))
                {
                    return(cache[name]);
                }

                return(null);
            }
        }
Exemplo n.º 12
0
        private static void Main()
        {
            OrderedMultiDictionary <decimal, Article> articles = new OrderedMultiDictionary <decimal, Article>(true);

            //  To test with 1 500 000 mil Articles download 100mb file:
            //  http://www.4shared.com/rar/kBeJdHzA/data1500000.html
            //  http://www.filedropper.com/data1500000
            var sw = new Stopwatch();

            sw.Start();
            var reader = new StreamReader(@"..\..\data1500000.csv", Encoding.UTF8);

            using (reader)
            {
                string line = reader.ReadLine();
                while ((line = reader.ReadLine()) != null)
                {
                    var data    = line.Split(new char[] { ',', '"' }, StringSplitOptions.RemoveEmptyEntries);
                    var barcode = data[0];
                    var vendor  = data[1];
                    var title   = data[2];
                    var price   = decimal.Parse(data[3]);

                    var article = new Article(barcode, vendor, title, price);

                    if (!articles.ContainsKey(article.Price))
                    {
                        articles[article.Price].Add(article);
                    }
                    else
                    {
                        articles.Add(article.Price, article);
                    }
                }
            }
            sw.Stop();

            Console.WriteLine("Time elapsed to store 1 500 000 reci=ords: {0}", sw.Elapsed);

            sw.Reset();
            sw.Start();
            var filteredArticles = articles.Range(1000, true, 1000000, true);

            Console.WriteLine("Records found: {0}", filteredArticles.Count);
            sw.Stop();

            Console.WriteLine("Time elapsed for searching: {0}", sw.Elapsed);
        }
Exemplo n.º 13
0
        static void Main()
        {
            OrderedMultiDictionary <double, Article> articles = new OrderedMultiDictionary <double, Article>(true);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            string line;

            using (StreamReader reader = new StreamReader(@"..\..\data1500000.csv"))
            {
                line = reader.ReadLine();
                while ((line = reader.ReadLine()) != null)
                {
                    string[] content = line.Split(new char[] { ',', '"' }, StringSplitOptions.RemoveEmptyEntries);
                    Article  article = new Article(content[0], content[1], content[2], double.Parse(content[3]));
                    if (articles.ContainsKey(article.Price))
                    {
                        articles[article.Price].Add(article);
                    }
                    else
                    {
                        articles.Add(article.Price, article);
                    }
                }
            }

            stopwatch.Stop();
            Console.WriteLine("Create and add 15k Articles: {0}", stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Restart();
            var result = articles.Range(14556.0, true, 4665542.0, true);

            stopwatch.Stop();
            Console.WriteLine("Search: {0}", stopwatch.Elapsed);
            Console.WriteLine(result.Count);

            //To test with 1 500 000 mil Articles download 100mb file:
            //http://www.4shared.com/rar/kBeJdHzA/data1500000.html
            //http://www.filedropper.com/data1500000
            //Create and add 1 500 000 mil Articles: 00:00:19.8488240
            //Search: 00:00:00.0015390
            //1394252
            //Press any key to continue . . .
        }
Exemplo n.º 14
0
        static void Main()
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            string line;
            using (StreamReader reader = new StreamReader(@"..\..\data1500000.csv"))
            {
                line = reader.ReadLine();
                while ((line = reader.ReadLine()) != null)
                {
                    string[] content = line.Split(new char[] { ',', '"' }, StringSplitOptions.RemoveEmptyEntries);
                    Article article = new Article(content[0], content[1], content[2], double.Parse(content[3]));
                    if (articles.ContainsKey(article.Price))
                    {
                        articles[article.Price].Add(article);
                    }
                    else
                    {
                        articles.Add(article.Price, article);
                    }
                }
            }

            stopwatch.Stop();
            Console.WriteLine("Create and add 15k Articles: {0}", stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Restart();
            var result = articles.Range(14556.0, true, 4665542.0, true);
            stopwatch.Stop();
            Console.WriteLine("Search: {0}", stopwatch.Elapsed);
            Console.WriteLine(result.Count);

            //To test with 1 500 000 mil Articles download 100mb file:
            //http://www.4shared.com/rar/kBeJdHzA/data1500000.html
            //http://www.filedropper.com/data1500000
            //Create and add 1 500 000 mil Articles: 00:00:19.8488240
            //Search: 00:00:00.0015390
            //1394252
            //Press any key to continue . . .
        }
Exemplo n.º 15
0
        static void Main()
        {
            OrderedMultiDictionary <double, Article> articles = new OrderedMultiDictionary <double, Article>(true);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            string line;

            using (StreamReader reader = new StreamReader(@".../../data.csv"))
            {
                line = reader.ReadLine();
                while ((line = reader.ReadLine()) != null)
                {
                    string[] content        = line.Split(new char[] { ',', '"' }, StringSplitOptions.RemoveEmptyEntries);
                    string   barcode        = content[0];
                    string   vendor         = content[1];
                    string   title          = content[2];
                    double   price          = Double.Parse(content[3]);
                    Article  currentArticle = new Article(barcode, vendor, title, price);
                    if (articles.ContainsKey(currentArticle.Price))
                    {
                        articles[currentArticle.Price].Add(currentArticle);
                    }
                    else
                    {
                        articles.Add(currentArticle.Price, currentArticle);
                    }
                }
            }

            stopwatch.Stop();
            Console.WriteLine("Create and Add 15 000 Articles: {0}", stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Restart();

            var result = articles.Range(1234.0, true, 13456.0, true);

            stopwatch.Stop();
            Console.WriteLine("Search: {0}", stopwatch.Elapsed);
            Console.WriteLine(result.Count);
        }
Exemplo n.º 16
0
        public string FindItems(string searchString, int count)
        {
            if (!itemsByTitle.ContainsKey(searchString))
            {
                return("No items found\r\n");
            }
            else
            {
                var           itemsToReturn = itemsByTitle[searchString].Take(count);
                StringBuilder result        = new StringBuilder();

                foreach (var item in itemsToReturn)
                {
                    result.AppendLine(item.ToString());
                }

                return(result.ToString());
            }
        }
Exemplo n.º 17
0
    void InitDemand()
    {
        currentDemand    = new OrderedMultiDictionary <float, ProductItem>(false, new DescendingComparer <float>(Comparer <float> .Default));
        demandThresholds = new Dictionary <ProductItem, float>();

        int rand = Random.Range(0, 100);

        foreach (ProductItem temp in desiredItems)
        {
            while (currentDemand.ContainsKey(rand))
            {
                rand = Random.Range(0, 100);
            }

            currentDemand.Add(rand, temp);
            demandThresholds.Add(temp, 100 - (weights[temp] * 100));             // create specific thresholds for each item. Difference between weighted % of 100
            Debug.Log(temp.itemName + " CurrentDemand: " + rand);
            Debug.Log(temp.itemName + " Threshold: " + demandThresholds[temp]);
        }
    }
Exemplo n.º 18
0
        /// <summary>
        /// Adds a player to the score list.
        /// </summary>
        /// <param name="playerName">The player name</param>
        /// <param name="playerScore">The player current score</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="playerName"/> is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when <paramref name="playerScore"/> less than zerol.</exception>
        public void AddPlayer(string playerName, int playerScore)
        {
            if (playerName == null)
            {
                throw new ArgumentNullException("playerName", "The player name cannot be null.");
            }
            if (playerScore < 0)
            {
                throw new ArgumentException("playerScore", "The player score cannot ness than zero.");
            }

            if (!scoreBoard.ContainsKey(playerScore))
            {
                scoreBoard.Add(playerScore, playerName);
            }
            else
            {
                scoreBoard[playerScore].Add(playerName);
            }
        }
        public static void Main()
        {
            var events         = new OrderedMultiDictionary <DateTime, string>(true);
            int numberOfEvents = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfEvents; i++)
            {
                string[] eventArgs = Console.ReadLine().Split('|');
                DateTime date      = DateTime.Parse(eventArgs[1].Trim());
                string   @event    = eventArgs[0].Trim();

                if (!events.ContainsKey(date))
                {
                    events.Add(date, @event);
                }
                else
                {
                    events[date].Add(@event);
                }
            }

            int numberOfDates = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfDates; i++)
            {
                string[] rangeArgs = Console.ReadLine().Split('|');
                DateTime start     = DateTime.Parse(rangeArgs[0].Trim());
                DateTime end       = DateTime.Parse(rangeArgs[1].Trim());

                var range = events.Range(start, true, end, true);
                Console.WriteLine(range.Values.Count);
                foreach (var date in range.Keys)
                {
                    foreach (var @event in range[date])
                    {
                        Console.WriteLine("{0} | {1}", @event, date.ToString());
                    }
                }
            }
        }
Exemplo n.º 20
0
        static void Main()
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            string line;
            using (StreamReader reader = new StreamReader(@".../../data.csv"))
            {
                line = reader.ReadLine();
                while ((line = reader.ReadLine()) != null)
                {
                    string[] content = line.Split(new char[] {',','"'}, StringSplitOptions.RemoveEmptyEntries);
                    string barcode = content[0];
                    string vendor = content[1];
                    string title = content[2];
                    double price = Double.Parse(content[3]);
                    Article currentArticle = new Article(barcode, vendor, title, price);
                    if (articles.ContainsKey(currentArticle.Price))
                    {
                        articles[currentArticle.Price].Add(currentArticle);
                    }
                    else
                    {
                        articles.Add(currentArticle.Price, currentArticle);
                    }
                }
            }

            stopwatch.Stop();
            Console.WriteLine("Create and Add 15 000 Articles: {0}", stopwatch.Elapsed);

            stopwatch.Reset();
            stopwatch.Restart();

            var result = articles.Range(1234.0, true, 13456.0, true);
            stopwatch.Stop();
            Console.WriteLine("Search: {0}", stopwatch.Elapsed);
            Console.WriteLine(result.Count);
        }
Exemplo n.º 21
0
        static void Main()
        {
            int eventCount = int.Parse(Console.ReadLine());

            OrderedMultiDictionary <DateTime, string> eventsByDate = new OrderedMultiDictionary <DateTime, string>(true);

            for (int i = 0; i < eventCount; i++)
            {
                string[] eventAndDate = Console.ReadLine().Split('|');
                string   eventName    = eventAndDate[0];
                //DateTime date = DateTime.ParseExact(eventAndDate[1], "dd-MMM-yyyy hh:mm", CultureInfo.InvariantCulture);
                DateTime date = DateTime.Parse(eventAndDate[1]);
                if (!eventsByDate.ContainsKey(date))
                {
                    eventsByDate.Add(date, eventName);
                }
                else
                {
                    eventsByDate[date].Add(eventName);
                }
            }

            int rangeCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < rangeCount; i++)
            {
                string[] dateRange = Console.ReadLine().Split('|');
                DateTime fromDate  = DateTime.Parse(dateRange[0]);
                DateTime toDate    = DateTime.Parse(dateRange[1]);
                var      range     = eventsByDate.Range(fromDate, true, toDate, true);
                foreach (var item in range)
                {
                    foreach (var innerItem in range[item.Key])
                    {
                        Console.WriteLine("{0} | {1:dd-MMM-yyyy}", innerItem, item.Key);
                    }
                }
            }
        }
        public static void Main()
        {
            var priceRangeMin = 10;
            var priceRangeMax = 20;
            int numberOfProducts = 100000;

            var products = new OrderedMultiDictionary<decimal, Product>(true);

            for (var i = 0; i < numberOfProducts; i++)
            {
                var product = new Product()
                {
                    Price = i%1000,
                    Barcode = string.Format("B{0}{1}", i, i),
                    Vendor = string.Format("Company #" + i),
                    Title = string.Format("Product #" + i)
                };

                if (!products.ContainsKey(product.Price))
                {
                    products.Add(product.Price, product);
                }
                else
                {
                    products[product.Price].Add(product);
                }
            }

            var productsInRange = products.Range(priceRangeMin, true, priceRangeMax, true);

            foreach (var item in productsInRange)
            {
                Console.WriteLine("Products with price: " + item.Key);
                Console.WriteLine(string.Join(Environment.NewLine, item.Value.Select(v => string.Join(Environment.NewLine, "   " + v.ToString()))));
            }
        }
Exemplo n.º 23
0
        private static void ReadInputFile()
        {
            string[] text = File.ReadAllLines(ArticlesFile);

            for (int i = 0; i < text.Length; i++)
            {
                string   line          = text[i];
                string[] tokens        = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                string   barcode       = tokens[0].Trim();
                string   vendor        = tokens[1].Trim();
                string   title         = tokens[2].Trim();
                decimal  price         = decimal.Parse(tokens[3].Trim());
                Article  curentArticle = new Article(barcode, vendor, title, price);

                if (storage.ContainsKey(price))
                {
                    storage[price].Add(curentArticle);
                }
                else
                {
                    storage.Add(price, curentArticle);
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Finds the command process.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        private static void FindCommandProcess(string line)
        {
            string[] tokens = line.Split(';');
            string   title  = tokens[0].Trim();
            int      count  = int.Parse(tokens[1]);

            if (contents.ContainsKey(title))
            {
                var list =
                    from content
                    in contents[title]
                    select content;
                var firstElements = list.Take(count);

                foreach (var item in firstElements)
                {
                    sb.AppendLine(item.ToString());
                }
            }
            else
            {
                sb.AppendLine("No items found");
            }
        }