public ArticleDictionary(Comparison <decimal> priceComparison, bool readOnly)
        {
            this.data = new OrderedMultiDictionary <decimal, Article>(
                allowDuplicateValues: true, keyComparison: priceComparison);

            this.IsReadOnly = readOnly;
        }
Пример #2
0
        static void Main()
        {
            var products = new OrderedMultiDictionary<decimal, Product>(true);

            Console.Write("Creating and adding products");
            for (int i = 0; i < 1000000; i++)
            {
                products.Add(
                    (i + 1) % 50 + (decimal)i / 100,
                    new Product(
                    "Product #" + (i + 1),
                    ((i + 1) % 50 + (decimal)i / 100),
                    "Vendor#" + i % 50000,
                    null));
                if (i % 1000 == 0)
                {
                    Console.Write(".");
                }
            }

            Console.WriteLine();

            var productsInPricerangeFrom10To11 = products.Range(10M, true, 11M, true);
            var productsInPricerangeFrom15To25 = products.Range(15M, true, 25M, true);
            var productsInPricerangeFrom30To35 = products.Range(30M, true, 35M, true);

            Console.WriteLine("Products with price between 10 and 11: " + productsInPricerangeFrom10To11.Count);
            Console.WriteLine("Products with price between 15 and 25: " + productsInPricerangeFrom15To25.Count);
            Console.WriteLine("Products with price between 30 and 35: " + productsInPricerangeFrom30To35.Count);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var eventCount = int.Parse(Console.ReadLine());
            var datesAndEvents = new OrderedMultiDictionary<DateTime, string>(true);
            for (int i = 0; i < eventCount; i++)
            {
                var currentEvent = Console.ReadLine();
                var token = currentEvent.Split('|');
                var date = DateTime.Parse(token[1].Trim());
                var name = token[0].Trim();
                datesAndEvents.Add(date, name);
            }

            var queryNumber = int.Parse(Console.ReadLine());
            for (int i = 0; i < queryNumber; i++)
            {
                var query = Console.ReadLine().Split('|');
                var startDate = DateTime.Parse(query[0].Trim());
                var endDate = DateTime.Parse(query[1].Trim());
                var queryData = datesAndEvents.Range(startDate, true, endDate, true);
                Console.WriteLine(queryData.KeyValuePairs.Count);
                foreach (var e in queryData)
                {
                    foreach (var name in e.Value)
                    {
                        Console.WriteLine("{0} | {1:dd-MMM-yyyy}", name, e.Key);
                    }
                }
            }
        }
Пример #4
0
 public ShoppingCenter()
 {
     productsByName     = new MultiDictionary <string, Product>(true);
     nameAndProducer    = new MultiDictionary <string, Product>(true);
     productsByPrice    = new OrderedMultiDictionary <decimal, Product>(true);
     productsByProducer = new MultiDictionary <string, Product>(true);
 }
        static void Main()
        {
            var mDict = new OrderedMultiDictionary<decimal, Product>(true);
            string[] productNames =
            {
                "Toy", "Food", "Car", "TV", "Computer", "Refrigerator", 
                "Bicylce", "Skateboard", "Bag", "EReader", "Phone", "Guitar", 
            };
            var rand = new Random();
            for (int i = 0; i < 500000; i++)
            {
                decimal price = rand.Next(1, 10000);
                string name = productNames[rand.Next(0, productNames.Length)];
                mDict.Add(price, new Product(name, price));
            }

            var productsInRange = mDict.Range(25, true, 30, true);
            Console.WriteLine("Total products in price range: {0}", productsInRange.KeyValuePairs.Count);
            Console.WriteLine("==================================");
            foreach (var products in productsInRange)
            {
                Console.WriteLine("Price: {0}, Count: {1}", products.Key, productsInRange[products.Key].Count);
                Console.WriteLine("Products: {0}", string.Join(", ", products.Value));
                Console.WriteLine("==================================");
            }
        }
Пример #6
0
        public void Refresh()
        {
            // FIXED: added value comparer (was throwing on x64)
            var cache = new OrderedMultiDictionary <String, AssemblyName>(
                false,
                StringComparer.CurrentCultureIgnoreCase,
                _assemblyNameComparer);

            int i = 0;

            foreach (AssemblyName name in Fusion.GetAssemblies(_type))
            {
                ++i;

                if (i % 5 == 0)
                {
                    WriteProgress(name.Name);
                }

                cache.Add(name.Name, name);
            }

            WriteProgressCompleted();
            _cache = cache;
        }
        public static void Main()
        {
            var streamReader = new StreamReader("../../students.txt");
            var multiDiuctionary = new OrderedMultiDictionary<Course, Student>(true);

            using (streamReader)
            {
                string line = streamReader.ReadLine();
                while (line != null)
                {
                    string[] parameters = line.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);

                    string courseName = parameters[2];
                    var course = new Course(courseName);

                    string firstName = parameters[0];
                    string lastName = parameters[1];
                    var student = new Student(firstName, lastName);

                    multiDiuctionary.Add(course, student);

                    line = streamReader.ReadLine();
                }
            }

            PrintCourses(multiDiuctionary);
        }
Пример #8
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var products = new OrderedMultiDictionary<double, string>(true);
            int numberOfLines = int.Parse(Console.ReadLine());
            string line = string.Empty;
            string productName = string.Empty;
            double productPrice = 0;

            for (int i = 0; i < numberOfLines; i++)
            {
                line = Console.ReadLine();

                var parts = line.Split(' ');

                productName = parts[0].Trim();
                productPrice = double.Parse(parts[1].Trim());

                products.Add(productPrice, productName);
            }

            var limits = Console.ReadLine().Split(' ');
            double lowerLimit = double.Parse(limits[0].Trim());
            double upperLimit = double.Parse(limits[1].Trim());
            var productsInRange = products.Range(lowerLimit, true, upperLimit, true);

            foreach (var productInRange in productsInRange)
            {
                Console.WriteLine("{0} {1}", productInRange.Key, productInRange.Value);
            }
        }
 public ShoppingCenter()
 {
     this.names             = new MultiDictionary <string, Product>(true);
     this.producers         = new MultiDictionary <string, Product>(true);
     this.namesAndProducers = new MultiDictionary <string, Product>(true);
     this.prices            = new OrderedMultiDictionary <decimal, Product>(true);
 }
Пример #10
0
        private static void ReadStudentsAndCoursesInput()
        {
            // using OrderedMultiDictionary because courses names can repeat
            // in SortedDictionary this is not possible

            // for every course we add the students which attend this course
            // and they are sorted by last name and then by first name (look at the Student class)
            courses = new OrderedMultiDictionary <string, Student>(true);

            StreamReader reader = new StreamReader("students.txt");

            using (reader)
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    var splitted = line.Split('|');

                    string studentFN  = splitted[0].Trim();
                    string studentLN  = splitted[1].Trim();
                    string courseName = splitted[2].Trim();

                    courses.Add(courseName, new Student(studentFN, studentLN));

                    line = reader.ReadLine();
                }
            }
        }
Пример #11
0
        public static void Main(string[] args)
        {
            OrderedMultiDictionary <double, Article> articles = new OrderedMultiDictionary <double, Article>(true);
            Random randomNumberGenerator = new Random();
            double randomNumber;

            for (int i = 0; i < 2000000; i++)
            {
                randomNumber = randomNumberGenerator.NextDouble() * MaxValue;
                Article article = new Article("barcode" + i, "vendor" + i, "article" + i, randomNumber);
                articles.Add(article.Price, article);
            }

            Console.Write("from = ");
            double from = double.Parse(Console.ReadLine());

            Console.Write("to = ");
            double to = double.Parse(Console.ReadLine());
            var    articlesInRange = articles.Range(from, true, to, true);

            foreach (var pair in articlesInRange)
            {
                foreach (var article in pair.Value)
                {
                    Console.WriteLine("{0} => {1}", Math.Round(article.Price, 2), article);
                }
            }
        }
Пример #12
0
        public static void Main(string[] args)
        {
            Random randomGenerator  = new Random();
            var    articles         = new OrderedMultiDictionary <double, Article>(false);
            int    numberOfArticles = 50;

            for (int i = 0; i < numberOfArticles; i++)
            {
                double randomPrice = randomGenerator.NextDouble() * 100;
                articles.Add(randomPrice, new Article("A", "B", "C", randomPrice));
            }

            Console.WriteLine("Select a range for price of the articles:");
            Console.Write("From: ");
            double from = double.Parse(Console.ReadLine());

            Console.Write("To: ");
            double to = double.Parse(Console.ReadLine());

            // Find the articles in the given range
            var articlesInTheGivenRange = articles.Range(from, true, to, true);

            // Print the articles in the given range
            foreach (var articleCollection in articlesInTheGivenRange)
            {
                foreach (var article in articleCollection.Value)
                {
                    Console.WriteLine(article);
                }
            }
        }
Пример #13
0
        static void Main()
        {

            List<string[]> inputs = ReadData();
            OrderedMultiDictionary<double, Article> byPrice = new OrderedMultiDictionary<double, Article>(true);
            foreach (var input in inputs)
            {
                Article article = new Article(input[0], input[1], input[2], Convert.ToDouble(input[3]));
                byPrice.Add(article.Price, article);
            }

            Console.WriteLine("Print all articles");
            foreach (var item in byPrice)
            {
                Console.WriteLine(item.ToString());
            }

            OrderedMultiDictionary<double, Article>.View priceInRange = GetPriceRange(40, 90, byPrice);
            Console.WriteLine();
            Console.WriteLine("Print articles in range [40, 90]");
            foreach (var item in priceInRange)
            {
                Console.WriteLine(item.ToString());
            }
        }
Пример #14
0
        public static void Main()
        {
            var dictionary = new OrderedMultiDictionary <decimal, Article>(true);

            GenerateArticles(dictionary);
            FindArticlesByPriceRange(dictionary);
        }
Пример #15
0
        public static void Main()
        {
            OrderedMultiDictionary <decimal, Article> articlesByPrice = new OrderedMultiDictionary <decimal, Article>(true);
            Random random = new Random();

            for (int i = 0; i < 1000000; i++)
            {
                var     barcode      = random.Next(111111, 999999);
                var     lengthTitle  = random.Next(2, 20);
                string  title        = GetRandomString(lengthTitle, random);
                var     lengthVendor = random.Next(2, 20);
                string  vendor       = GetRandomString(lengthVendor, random);
                var     price        = random.Next(1, 10000);
                Article article      = new Article(barcode, vendor, title, price);
                articlesByPrice.Add(article.Price, article);
            }

            for (int i = 0; i < 20; i++)
            {
                var lowerBound      = random.Next(1, 9950);
                var upperBound      = lowerBound + 50;
                var articlesInRange = articlesByPrice.Range(lowerBound, true, upperBound, true);
                Console.WriteLine("Articles in price range {0}- {1}: {2} articles", lowerBound, upperBound, articlesInRange.Values.Count);
            }
        }
        static void Main()
        {
            const bool areDublicationOfValuesAllawed = true;

            OrderedMultiDictionary<decimal, Articule> articules =
                new OrderedMultiDictionary<decimal, Articule>(areDublicationOfValuesAllawed);

            PopulateArticules(articules);
            
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var result = articules.Range(200m, true, 220m, true);
            sw.Stop();
            

            foreach (var record in result)
            {
                Console.BufferWidth = 160;
                foreach (var value in record.Value) 
                {
                    Console.WriteLine(value);
                }
            }

            Console.WriteLine("Elapsed time to find: {0}", sw.Elapsed);
        }
Пример #17
0
    static void Main()
    {
        int    productNameMaxLenghth = 30;
        double productMinPrice       = 1;
        double productMaxPrice       = 100;
        int    count         = 500000;
        int    priceSearches = 10000;

        Console.WriteLine("Generating random products with random prices...");
        OrderedMultiDictionary <double, string> products = GenerateRandomProducts(
            count, productNameMaxLenghth, productMinPrice, productMaxPrice);

        DateTime startTime = DateTime.Now;

        Console.WriteLine("\nStart finding: {0}", DateTime.Now);
        for (int i = 0; i < priceSearches; i++)
        {
            double minRangePrice   = GetRandomBetween(productMinPrice, productMaxPrice - 1);
            double maxRangePrice   = GetRandomBetween(minRangePrice, productMaxPrice);
            var    productsInRange = products.Range(minRangePrice, true, maxRangePrice, true).Take(20);
            // Warning!!! Printing is very slow operation.
            //Console.WriteLine("Produucts in range [{0}-{1}]: {2}", minRangePrice, maxRangePrice, string.Join("\n", productsInRange));
            //Console.WriteLine(new string('-',80));
        }
        Console.WriteLine("End finding: {0}", DateTime.Now);
        Console.WriteLine("Total finding time {0}", DateTime.Now - startTime);
    }
Пример #18
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var eventCount     = int.Parse(Console.ReadLine());
            var datesAndEvents = new OrderedMultiDictionary <DateTime, string>(true);

            for (int i = 0; i < eventCount; i++)
            {
                var currentEvent = Console.ReadLine();
                var token        = currentEvent.Split('|');
                var date         = DateTime.Parse(token[1].Trim());
                var name         = token[0].Trim();
                datesAndEvents.Add(date, name);
            }

            var queryNumber = int.Parse(Console.ReadLine());

            for (int i = 0; i < queryNumber; i++)
            {
                var query     = Console.ReadLine().Split('|');
                var startDate = DateTime.Parse(query[0].Trim());
                var endDate   = DateTime.Parse(query[1].Trim());
                var queryData = datesAndEvents.Range(startDate, true, endDate, true);
                Console.WriteLine(queryData.KeyValuePairs.Count);
                foreach (var e in queryData)
                {
                    foreach (var name in e.Value)
                    {
                        Console.WriteLine("{0} | {1:dd-MMM-yyyy}", name, e.Key);
                    }
                }
            }
        }
Пример #19
0
        public static void Main()
        {
            var productByPrice = new OrderedMultiDictionary<double, string>(true);
            int linesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < linesCount; i++)
            {
                string input = Console.ReadLine();
                string[] inputArgs = input.Split();
                double price = double.Parse(inputArgs[1]);
                string product = inputArgs[0];

                productByPrice.Add(price, product);
            }

            double[] range = Console.ReadLine().Split().Select(double.Parse).ToArray();

            var productsInRange = productByPrice.Range(range[0], true, range[1], true);

            int count = 0;
            foreach (var product in productsInRange)
            {
                if (count == 20)
                {
                    break;
                }

                Console.WriteLine(product.Key + " " + product.Value.First());
                count++;
            }
        }
Пример #20
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);
                }
            }
        }
Пример #21
0
        public static void Main()
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);

            int range = 10000;
            for (int i = 0; i < range; i++)
            {
                var article = new Article("barcode" + i, "vendor" + i, "title" + i, i);
                articles.Add(article.Price, article);
            }

            int from = 5000;
            int to = 5040;

            //Make some duplications
            for (int i = from; i < to - 30; i++)
            {
                var article = new Article("newBarcode" + i, "newVendor" + i, "newTitle" + i, i);
                articles.Add(article.Price, article);
            }

            var articlesInGivenRange = articles.Range(from, true, to, true);
            foreach (var article in articlesInGivenRange)
            {
                foreach (var item in article.Value)
                {
                    Console.WriteLine("Title: {0}, Vendor: {1}, Barcode: {2}, Price: {3}",
                    item.Title, item.Vendor, item.Barcode, item.Price);
                }
                Console.WriteLine();
            }
        }
Пример #22
0
 public ShoppingCenter()
 {
     productsByName = new MultiDictionary<string, Product>(true);
     nameAndProducer = new MultiDictionary<string, Product>(true);
     productsByPrice = new OrderedMultiDictionary<decimal, Product>(true);
     productsByProducer = new MultiDictionary<string, Product>(true);
 }
Пример #23
0
        public static void Main()
        {
            OrderedMultiDictionary<string, Student> coursesAndStudents = new OrderedMultiDictionary<string, Student>(true);
            
            string path = @"../../InputFile/students.txt";

            using (StreamReader fileReader = new StreamReader(path))
            {
                string line;
                while ((line = fileReader.ReadLine()) != null)
                {
                    string[] studentData = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    string courseName = studentData[2].Trim();
                    string studentFirstName = studentData[0].Trim();
                    string studentLastName = studentData[1].Trim();

                    Student currentStudent = new Student(studentFirstName, studentLastName);

                    coursesAndStudents.Add(courseName, currentStudent);
                }
            }

            foreach (var course in coursesAndStudents)
            {
                Console.Write(course.Key + ": ");
                var students = coursesAndStudents[course.Key];
                Console.WriteLine(string.Join(", ", students));
            }
        }
Пример #24
0
 public ShoppingCenter()
 {
     this.productsByProducer = new Dictionary<string, Bag<Product>>();
     this.productsByName = new Dictionary<string, Bag<Product>>();
     this.productsByNameAndProducer = new Dictionary<Tuple<string, string>, Bag<Product>>();
     this.productsByPrice = new OrderedMultiDictionary<decimal, Product>(true);
 }
Пример #25
0
        public static void Main()
        {
            var articles = new OrderedMultiDictionary <decimal, Article>(false);

            DateTime start_at = DateTime.Now;

            for (int i = 0; i < NumberOfProducts; i++)
            {
                var tempArticle = new Article(
                    RandomGenerator.GetRandomBarcode(13),
                    RandomGenerator.GetRandomStringWithRandomLength(5, 10),
                    RandomGenerator.GetRandomStringWithRandomLength(10, 15),
                    RandomGenerator.GetRandomDecimalBetween(5, 15));

                articles.Add(tempArticle.Price, tempArticle);
            }

            DateTime stop_at = DateTime.Now;

            Console.WriteLine("{0} articles generated in {1} secs", NumberOfProducts, new TimeSpan(stop_at.Ticks - start_at.Ticks).TotalSeconds);

            var retrievedArticles = articles.Range(10, true, 10.5M, true);

            Console.WriteLine("Articles in range: {0}", retrievedArticles.Count);
            Console.WriteLine("Top {0} articles: ", NumberOfArticlesToPrint);

            foreach (var article in retrievedArticles.ToList().Take(NumberOfArticlesToPrint))
            {
                Console.WriteLine(article);
            }
        }
Пример #26
0
        private static void Main()
        {
            var articles = new OrderedMultiDictionary <decimal, Article>(false);
            var rand     = new RandomGenerator();

            Console.WriteLine($"Populating {ArticlesCount} articles");
            for (int i = 0; i < ArticlesCount; i++)
            {
                string  title   = rand.GetRandomString(5, 10);
                string  vendor  = rand.GetRandomString(5, 10);
                decimal price   = rand.GetRandomInteger(10, 2500);
                string  barcode = rand.GetRandomString(10, 15);

                var article = new Article(title, barcode, vendor, price);
                articles.Add(price, article);
            }

            Console.WriteLine($"Searching for articles in price range {MinPrice} - {MaxPrice}");
            var extractedArticles = articles.Range(MinPrice, true, MaxPrice, true);

            Console.WriteLine("Finished search. Man that was fast!\nPress a key to start printing to console...");
            Console.ReadLine();

            foreach (var priceArticles in extractedArticles)
            {
                foreach (var article in priceArticles.Value)
                {
                    Console.WriteLine($"Title: {article.Title}, price: {article.Price}");
                }
            }
            ;

            Console.WriteLine($"\n\nThats all articles in price range {MinPrice} - {MaxPrice} for {ArticlesCount} articles.\n\n");
        }
Пример #27
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);
            }
        }
Пример #28
0
        static void Main()
        {
            const int ArticlesCount = 1000000;

            articles        = new OrderedMultiDictionary <double, Article>(true);
            randomGenerator = new Random();

            var watch = new Stopwatch();

            watch.Start();

            // for testing if it works correctly can change ArticlesCount to be smaller and uncomment the foreach loop in FindArticlesInPriceRange method
            // now it only test the searching time in 1 000 000 articles
            GenerateRandomArticles(ArticlesCount);

            watch.Stop();

            Console.WriteLine("Initliazation time: {0}", watch.Elapsed);
            watch.Reset();

            watch.Start();

            FindArticlesInPriceRange(200.0, 1000.0);

            watch.Stop();

            Console.WriteLine("Searching time: {0}", watch.Elapsed);
        }
Пример #29
0
        private static OrderedMultiDictionary<int, Article> GenerateArticles(int count)
        {
            var barcodes = new HashSet<string>();

            Console.Write("Generating barcodes...");
            while (barcodes.Count < count)
            {
                var barcode = RandomGenerator.GetRandomString(BarcodeLength);
                barcodes.Add(barcode);
                if (barcodes.Count % (count / 10) == 0)
                {
                    Console.Write('.');
                }
            }

            Console.Write("\n\nGenerating articles...");
            var articles = new OrderedMultiDictionary<int, Article>(true);
            foreach (var barcode in barcodes)
            {
                var vendor = RandomGenerator.GetRandomString(5);
                var title = RandomGenerator.GetRandomString(7);
                var price = RandomGenerator.GeneratRandomNumber(0, count);
                var article = new Article(barcode, vendor, title, price);
                articles.Add(price, article);
                if (articles.Count % (count / 10) == 0)
                {
                    Console.Write('.');
                }
            }

            Console.WriteLine();
            return articles;
        }
Пример #30
0
 public ShopingCenter()
 {
     _byName            = new Dictionary <string, OrderedBag <Product> >();
     _byProducer        = new Dictionary <string, OrderedBag <Product> >();
     _byNameAndProducer = new Dictionary <string, OrderedBag <Product> >();
     _byPrice           = new OrderedMultiDictionary <decimal, Product>(true);
 }
Пример #31
0
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        OrderedMultiDictionary <decimal, Product> allProducts = new OrderedMultiDictionary <decimal, Product>(true);

        for (int i = 0; i < n; i++)
        {
            string[] input = Console.ReadLine().Split(' ');

            string  name       = input[0];
            decimal price      = decimal.Parse(input[1]);
            Product newProduct = new Product()
            {
                Name = name, Price = price
            };

            allProducts.Add(price, newProduct);
        }

        string[] priceRanges = Console.ReadLine().Split(' ');
        decimal  start       = decimal.Parse(priceRanges[0]);
        decimal  end         = decimal.Parse(priceRanges[1]);

        var productsInRange = allProducts.Range(start, true, end, true).Take(20);

        Console.WriteLine();
        foreach (var price in productsInRange)
        {
            foreach (var product in price.Value)
            {
                Console.WriteLine(product);
            }
        }
    }
Пример #32
0
    /* 2. A large trade company has millions of articles, each described
       by barcode, vendor, title and price. Implement a data structure to
       store them that allows fast retrieval of all articles in given price
       range [x...y].

       Hint: use OrderedMultiDictionary<K,T> from Wintellect's Power
       Collections for .NET.
     * */
    static void Main(string[] args)
    {
        // What's there to "implement"?
        // That's exactly what OrderedMultiDictionary was made for.

        // input generator in bin\debug\generator.cs

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

        foreach (var line in File.ReadLines("products.txt").Skip(1))
        {
            var split = line.Split('|');
            products.Add(decimal.Parse(split[0]), split[1]);
        }

        foreach (var line in File.ReadLines("commands.txt"))
        {
            Console.WriteLine("Command: " + line);
            var split = line.Split('|');

            var first = decimal.Parse(split[0]);
            var second = decimal.Parse(split[1]);

            var matching = products.Range(Math.Min(first, second), true,
                                          Math.Max(first, second), true);

            Console.WriteLine(string.Join(", ", matching));
            Console.WriteLine();
            Console.WriteLine("Press Ctrl+C to quit, or any other key to continue...");
            Console.ReadLine();
        }
    }
        public static string CreateScoreboardString(OrderedMultiDictionary <int, string> statistics)
        {
            int resultsCount = Math.Min(5, statistics.Count);
            int counter      = 0;

            StringBuilder scoreboard = new StringBuilder();

            scoreboard.AppendLine("Scoreboard:");

            foreach (var result in statistics)
            {
                if (counter == resultsCount)
                {
                    break;
                }
                else
                {
                    counter++;
                    var format = String.Format("{0}. {1} --> {2} moves", resultsCount, result.Value, result.Key);
                    scoreboard.AppendLine(format);
                }
            }

            return(scoreboard.ToString());
        }
Пример #34
0
        public static void Main(string[] args)
        {
            var productsAndPrices = new OrderedMultiDictionary<int, string>(true);
            var rng = new Random();
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < 500000; i++)
            {
                var product = GenerateProduct(rng, i);
                var tokens = product.Split('|');
                var name = tokens[0].Trim();
                var price = int.Parse(tokens[1].Trim());
                productsAndPrices.Add(price, name);
            }

            Console.WriteLine("Seed time: " + stopwatch.Elapsed);
            stopwatch.Restart();
            Console.WriteLine("Query Start");
            var printed = new Set<int>();
            for (int i = 0; i < 10000; i++)
            {
                var startPrice = rng.Next(0, 100001);
                var endPrice = rng.Next(startPrice, 100001);
                var productsInRange = productsAndPrices.Range(startPrice, true, endPrice, true).Take(20);
                var count = productsInRange.Count();
                if (!printed.Contains(count))
                {
                    Console.WriteLine("{0} to {1} -> {2}", startPrice, endPrice, count);
                    printed.Add(count);
                }
            }

            Console.WriteLine("Query time: " + stopwatch.Elapsed);
            Console.WriteLine("All Done");
        }
Пример #35
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);
            }
        }
Пример #36
0
    static void Main()
    {
        var productsPrices = new OrderedMultiDictionary <decimal, string>(false);
        int productsCount  = int.Parse(Console.ReadLine());

        for (int i = 0; i < productsCount; i++)
        {
            string[] productParams = Console.ReadLine().Split();
            string   productType   = productParams[0];
            decimal  productPrice  = decimal.Parse(productParams[1]);
            productsPrices.Add(productPrice, productType);
        }

        decimal[] priceRangeParams = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
        decimal   mintPrice        = priceRangeParams[0];
        decimal   maxPrice         = priceRangeParams[1];

        foreach (var priceProductsPair in productsPrices.Range(mintPrice, true, maxPrice, true))
        {
            foreach (string product in priceProductsPair.Value)
            {
                Console.WriteLine("{0} {1}", priceProductsPair.Key, product);
            }
        }
    }
Пример #37
0
    static void Main()
    {
        OrderedMultiDictionary <decimal, string> articles = new OrderedMultiDictionary <decimal, string>(true);

        articles = LoadData(numberOfArticles);
        PrintRange(articles, minValue, maxValue);
    }
Пример #38
0
        public static string CreateScoreboardString(OrderedMultiDictionary<int, string> statistics)
        {
            int resultsCount = Math.Min(5, statistics.Count);
            int counter = 0;

            StringBuilder scoreboard = new StringBuilder();

            scoreboard.AppendLine("Scoreboard:");

            foreach (var result in statistics)
            {
                if (counter == resultsCount)
                {
                    break;
                }
                else
                {
                    counter++;
                    var format = String.Format("{0}. {1} --> {2} moves", resultsCount, result.Value, result.Key);
                    scoreboard.AppendLine(format);
                }
            }

            return scoreboard.ToString();
        }
    /// <summary>
    /// Read file and add element to the product list (price with barcode, vendor and title)
    /// </summary>
    /// <param name="file">File name</param>
    /// <exception cref="ArgumentNullException">
    /// If file name is null or white space</exception>
    /// <remarks>Use UTF-8 encoding</remarks>
    /// <returns>Created product list</returns>
    public static OrderedMultiDictionary<double, string> GenerateProductList(string file)
    {
        if (string.IsNullOrWhiteSpace(file))
        {
            throw new ArgumentNullException(
                "Invalid input! File name cannot be null or white space.");
        }

        OrderedMultiDictionary<double, string> productList =
            new OrderedMultiDictionary<double, string>(true);
        StreamReader reader = new StreamReader(file, Encoding.GetEncoding("UTF-8"));
        using (reader)
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                string[] content = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                string barcode = content[0].Trim();
                string vendor = content[1].Trim();
                string title = content[2].Trim();
                double price = double.Parse(content[3].Trim());
                productList.Add(price,
                    string.Format("Barcode: {0} Vendor: {1}  Title: {2}", barcode, vendor, title));
                line = reader.ReadLine();
            }
        }

        return productList;
    }
Пример #40
0
        public static void Main()
        {
            Console.WriteLine("Adding products");

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

            for (int i = 0; i < 500000; i++)
            {
                var currentPrice = (i * Math.Abs(Math.Sin(i)));
                products.Add((decimal)currentPrice, "Product " + i);

                if (i % 5000 == 0)
                {
                    Console.Write(".");
                }
            }

            Console.WriteLine();

            decimal minPrice = 100000M;
            decimal maxPrice = 110000M;

            Console.WriteLine("Top 20 product in price range [{0}, {1}]", minPrice, maxPrice);

            var result = products.Range(minPrice, true, maxPrice, true).ToList().Take(20);

            foreach (var product in result)
            {
                Console.WriteLine("Name: {0}, Price: {1}", product.Value, product.Key);
            }
        }
Пример #41
0
        static void Main(string[] args)
        {
            OrderedMultiDictionary<decimal, Article> articles = 
                new OrderedMultiDictionary<decimal, Article>(true);

            articles.Add(12.43m, new Article("Choco", "123124234", "Milka", 12.43m));
            articles.Add(14.43m, new Article("Natural", "123124234", "Milka", 14.43m));
            articles.Add(15.43m, new Article("Raffy", "123124234", "Milka", 15.43m));
            articles.Add(17.43m, new Article("Milk", "123124234", "Milka", 17.43m));
            articles.Add(18.43m, new Article("Sugar", "123124234", "Milka", 18.43m));
            articles.Add(19.43m, new Article("Bread", "123124234", "Milka", 19.43m));
            articles.Add(20.43m, new Article("Susam", "123124234", "Milka", 20.43m));
            articles.Add(23.43m, new Article("Paper", "123124234", "Milka", 23.43m));
            articles.Add(25.43m, new Article("Grape", "123124234", "Milka", 25.43m));
            articles.Add(54.43m, new Article("Banana", "123124234", "Milka", 54.43m));
            articles.Add(43.43m, new Article("Orange", "123124234", "Milka", 43.43m));
            articles.Add(32.43m, new Article("Melon", "123124234", "Milka", 32.43m));
            articles.Add(24.43m, new Article("WaterMelon", "123124234", "Milka", 24.43m));
            articles.Add(76.43m, new Article("Junk", "123124234", "Milka", 76.43m));

            var rangeArticles = articles.Range(20m, true, 35m, true);
            foreach (var article in rangeArticles)
            {
                foreach (var item in article.Value)
                {
                    Console.WriteLine(item);
                }
            }
        }
Пример #42
0
    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        var events      = new OrderedMultiDictionary <DateTime, string>(true);
        int eventsCount = int.Parse(Console.ReadLine());

        for (int i = 0; i < eventsCount; i++)
        {
            string[] eventParams = Console.ReadLine().Split('|');
            string   eventName   = eventParams[0].Trim();
            var      eventTime   = DateTime.Parse(eventParams[1].Trim());
            events.Add(eventTime, eventName);
        }

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

        for (int i = 0; i < rangesCount; i++)
        {
            string[] timeParams = Console.ReadLine().Split('|');
            var      startTime  = DateTime.Parse(timeParams[0].Trim());
            var      endTime    = DateTime.Parse(timeParams[1].Trim());

            var filteredEvents = events.Range(startTime, true, endTime, true);
            Console.WriteLine(filteredEvents.Values.Count);
            foreach (var timeEventsPair in filteredEvents)
            {
                foreach (string eventName in timeEventsPair.Value)
                {
                    Console.WriteLine("{0} | {1}", eventName, timeEventsPair.Key);
                }
            }
        }
    }
Пример #43
0
        /// <summary>
        /// OrderedMultiDictionary<TKey,TValue>              (WITH DUPLICATES)
        /// A dictionary based on balanced search tree
        /// Add / Find / Remove work in time O(log(N))
        /// Provides fast .Range(from,to) operation
        /// </summary>
        private static void TestOrderedMultiDictionary()
        {
            OrderedMultiDictionary <int, Student> students = new OrderedMultiDictionary <int, Student>(true);
            var student1 = new Student("First DUPLICATE", 21);
            var student2 = new Student("Second", 21);

            students.Add(5, student1);
            students.Add(5, student1);
            students.Add(2, student2);
            var student3 = new Student("Third", 22);
            var student4 = new Student("Forth", 23);
            var student5 = new Student("Fifth", 24);

            students.Add(3, student3);
            students.Add(4, student4);
            students.Add(1, student5);
            foreach (var item in students)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("========== Range Key >= 4 && <= 5 ============= ");
            var inRangeStudents = students.Range(4, true, 5, true);

            foreach (var item in inRangeStudents)
            {
                Console.WriteLine(item);
            }
        }
    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        var events = new OrderedMultiDictionary<DateTime, string>(true);
        int eventsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < eventsCount; i++)
        {
            string[] eventParams = Console.ReadLine().Split('|');
            string eventName = eventParams[0].Trim();
            var eventTime = DateTime.Parse(eventParams[1].Trim());
            events.Add(eventTime, eventName);
        }

        int rangesCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < rangesCount; i++)
        {
            string[] timeParams = Console.ReadLine().Split('|');
            var startTime = DateTime.Parse(timeParams[0].Trim());
            var endTime = DateTime.Parse(timeParams[1].Trim());

            var filteredEvents = events.Range(startTime, true, endTime, true);
            Console.WriteLine(filteredEvents.Values.Count);
            foreach (var timeEventsPair in filteredEvents)
            {
                foreach (string eventName in timeEventsPair.Value)
                {
                    Console.WriteLine("{0} | {1}", eventName, timeEventsPair.Key);
                }
            }
        }
    }
Пример #45
0
        private static void ReadStudentsAndCoursesInput()
        {
            // using OrderedMultiDictionary because courses names can repeat
            // in SortedDictionary this is not possible

            // for every course we add the students which attend this course
            // and they are sorted by last name and then by first name (look at the Student class)
            courses = new OrderedMultiDictionary<string, Student>(true);

            StreamReader reader = new StreamReader("students.txt");

            using (reader)
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    var splitted = line.Split('|');

                    string studentFN = splitted[0].Trim();
                    string studentLN = splitted[1].Trim();
                    string courseName = splitted[2].Trim();

                    courses.Add(courseName, new Student(studentFN, studentLN));

                    line = reader.ReadLine();
                }
            }
        }
Пример #46
0
        static void Main(string[] args)
        {
            OrderedMultiDictionary <decimal, Product> products = new OrderedMultiDictionary <decimal, Product>(true);

            string[] priceRange    = Console.ReadLine().Split();
            decimal  startPrice    = decimal.Parse(priceRange[0]);
            decimal  endPrice      = decimal.Parse(priceRange[1]);
            int      productsCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < productsCount; i++)
            {
                string[] productInfo = Console.ReadLine().Split(" | ");
                decimal  price       = decimal.Parse(productInfo[3]);
                Product  product     = new Product(productInfo[0], productInfo[1], productInfo[2], price);
                products.Add(price, product);
            }

            OrderedMultiDictionary <decimal, Product> .View searchedProducts = products.Range(startPrice, true, endPrice, true);
            if (searchedProducts.Count == 0)
            {
                Console.WriteLine("There are no products in this range!");
                return;
            }

            foreach (KeyValuePair <decimal, ICollection <Product> > productsWithPrice in searchedProducts)
            {
                foreach (Product product in productsWithPrice.Value)
                {
                    Console.WriteLine(product);
                }
            }
        }
Пример #47
0
        /// <summary>
        /// Creates a catalog in wich content can be inserted and searched.
        /// </summary>
        public Catalog()
        {
            bool allowDuplicateValues = true;

            this.title = new OrderedMultiDictionary <string, IContent>(allowDuplicateValues);
            this.url   = new MultiDictionary <string, IContent>(allowDuplicateValues);
        }
Пример #48
0
    static void Main()
    {
        OrderedMultiDictionary<string, Student> students = new OrderedMultiDictionary<string, Student>(true);

        using (StreamReader reader = new StreamReader(@"../../Students.txt"))
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                string[] arguments = ParseInput(line);
                if (arguments.Length == 3)
                {
                    string firstName = arguments[0].Trim();
                    string lastName = arguments[1].Trim();
                    string course = arguments[2].Trim();

                    students.Add(course, new Student(firstName, lastName));
                }

                line = reader.ReadLine();
            }
        }

        foreach (var course in students)
        {
            Console.WriteLine("{0}: {1}", course.Key, string.Join(", ", course.Value));
        }
    }
Пример #49
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);
    }
Пример #50
0
        static void Main()
        {
            Article[] articles = {new Article(0999311,"GeorgiIvanovOOD","Gloves",10.56M),
                                     new Article(09945311,"GeorgiIvanovOOD","Hats",8.00M),
                                     new Article(45945311,"ETIliev","Bags",18.00M),
                                     new Article(45947311,"ETIliev","Shoes",18.00M),
                                     new Article(13447311,"ETIliev","Socks",3.99M),
                                     new Article(13412570,"ETDimitrov","BaseballBats",23.99M)};

            OrderedMultiDictionary<decimal, Article> catalog = new OrderedMultiDictionary<decimal, Article>(true);

            foreach (var article in articles)
            {
                catalog.Add(article.Price, article);
            }

            var pricesRange = catalog.FindAll(x => x.Key >= 10 && x.Key <= 20);
            foreach (var item in pricesRange)
            {
                string items = "";
                int count = 0;
                foreach (var article in item.Value)
                {
                    count += 1;
                    items += "article"+count+": "+ article.Title + " " + article.Vedndor + " " + article.Barcode+";\n";
                }

                Console.WriteLine("Price: {0} - articles: {1}",
                    item.Key,items);
            }
        }
Пример #51
0
        static void Main(string[] args)
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);

            //filling the dictionary takes a few seconds
            for (int i = 0; i <= 2000000; i++)
            {
                double price = i / 100.3;
                Article article = new Article(i * 971, Math.Round(price, 2), i.ToString(), i.ToString());
                
                articles.Add(price, article);
            }

            
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            var articlesInRange = GetArticlesInPriceRange(articles, 1d, 300000d);
            stopwatch.Stop();

            //Uncomment to see found items title and price
            StringBuilder sb = new StringBuilder();
            //foreach (var node in articlesInRange)
            //{
            //    foreach (var item in node.Value)
            //    {
            //        sb.AppendFormat("{0}: {1}\n", item.Title, item.Price);

            //    }
            //}

            Console.WriteLine(sb.ToString());
            Console.WriteLine("Found count: {0}", articlesInRange.Count);
            Console.WriteLine("Items in range found in: {0}", stopwatch.Elapsed);
        }
Пример #52
0
        public Calendar()
        {
            bool allowDuplicates = true;

            this.byTitle = new MultiDictionary <string, Event>(allowDuplicates);
            this.byDate  = new OrderedMultiDictionary <DateTime, Event>(allowDuplicates);
        }
Пример #53
0
        static void Main(string[] args)
        {
            var courses = new OrderedMultiDictionary<DateTime, string>(true);
            int coursesTotal = int.Parse(Console.ReadLine());
            for (int i = 0; i < coursesTotal; i++)
            {
                string[] courseData = Console.ReadLine().Split('|');
                string courseName = courseData[0].Trim();
                DateTime courseTime = DateTime.Parse(courseData[1].Trim());
                courses[courseTime].Add(courseName);
            }

            int intervalsTotal = int.Parse(Console.ReadLine());
            for (int i = 0; i < intervalsTotal; i++)
            {
                string[] intervData = Console.ReadLine().Split('|');
                DateTime start = DateTime.Parse(intervData[0].Trim());
                DateTime end = DateTime.Parse(intervData[1].Trim());
                var result = courses.Range(start, true, end, true);
                Console.WriteLine(new string('-', 10));
                Console.WriteLine(result.Values.Count);
                foreach (var coursesBe in result)
                {
                    foreach (var course in coursesBe.Value)
                    {
                        Console.WriteLine("{1} | {0}", coursesBe.Key, course);
                    }
                }

                Console.WriteLine(new string('-', 10));
            }
        }
        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)));
            }
        }
Пример #55
0
        private static void ReadInput(OrderedMultiDictionary <double, string> products)
        {
            int elements = int.Parse(Console.ReadLine());

            for (int i = 0; i < elements; i++)
            {
                string[] parameters = Console.ReadLine().Split();
                string   name       = parameters[0];
                double   price      = double.Parse(parameters[1]);
                products.Add(price, name);
            }

            string line = Console.ReadLine();

            double[] ranges     = line.Split().Select(double.Parse).ToArray();
            double   lowerBound = ranges[0];
            double   upperBound = ranges[1];

            var range = products.Range(lowerBound, true, upperBound, true).Take(20);

            foreach (var pair in range)
            {
                Console.WriteLine("{0} {1}", pair.Key, string.Join(", ", pair.Value));
            }
        }
    static void Main()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        var events = new OrderedMultiDictionary<DateTime, string>(true);
        int eventsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < eventsCount; i++)
        {
            string eventEntry = Console.ReadLine();
            var eventTokens = eventEntry.Split('|');
            string eventName = eventTokens[0].Trim();
            DateTime eventDate = DateTime.Parse(eventTokens[1].Trim());
            events.Add(eventDate, eventName);
        }

        int seratchCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < seratchCount; i++)
        {
            string dateEntry = Console.ReadLine();
            var dateTokens = dateEntry.Split('|');
            DateTime startDate = DateTime.Parse(dateTokens[0].Trim());
            DateTime endDate = DateTime.Parse(dateTokens[1].Trim());
            var eventsInRange = events.Range(startDate, true, endDate, true);

            Console.WriteLine("\n\rResult:" + eventsInRange);
            PrintEvents(eventsInRange);
            Console.WriteLine();
        }
    }
Пример #57
0
        public static void Main()
        {
            var dictionary = new OrderedMultiDictionary<decimal, Article>(true);

            GenerateArticles(dictionary);
            FindArticlesByPriceRange(dictionary);
        }
 private static void PrintArticles(OrderedMultiDictionary<double, Article> articles)
 {
     foreach (var article in articles)
     {
         Console.WriteLine(article.Value);
     }
 }
Пример #59
0
        public static void Main(string[] args)
        {
            OrderedMultiDictionary<double, Article> articles = new OrderedMultiDictionary<double, Article>(true);
            Random randomNumberGenerator = new Random();
            double randomNumber;
            for (int i = 0; i < 2000000; i++)
            {
                randomNumber = randomNumberGenerator.NextDouble() * MaxValue;
                Article article = new Article("barcode" + i, "vendor" + i, "article" + i, randomNumber);
                articles.Add(article.Price, article);
            }

            Console.Write("from = ");
            double from = double.Parse(Console.ReadLine());
            Console.Write("to = ");
            double to = double.Parse(Console.ReadLine());
            var articlesInRange = articles.Range(from, true, to, true);
            foreach (var pair in articlesInRange)
            {
                foreach (var article in pair.Value)
                {
                    Console.WriteLine("{0} => {1}", Math.Round(article.Price, 2), article);
                }
            }
        }
Пример #60
0
        static void Main(string[] args)
        {
            OrderedMultiDictionary <decimal, Article> articles =
                new OrderedMultiDictionary <decimal, Article>(true);

            articles.Add(12.43m, new Article("Choco", "123124234", "Milka", 12.43m));
            articles.Add(14.43m, new Article("Natural", "123124234", "Milka", 14.43m));
            articles.Add(15.43m, new Article("Raffy", "123124234", "Milka", 15.43m));
            articles.Add(17.43m, new Article("Milk", "123124234", "Milka", 17.43m));
            articles.Add(18.43m, new Article("Sugar", "123124234", "Milka", 18.43m));
            articles.Add(19.43m, new Article("Bread", "123124234", "Milka", 19.43m));
            articles.Add(20.43m, new Article("Susam", "123124234", "Milka", 20.43m));
            articles.Add(23.43m, new Article("Paper", "123124234", "Milka", 23.43m));
            articles.Add(25.43m, new Article("Grape", "123124234", "Milka", 25.43m));
            articles.Add(54.43m, new Article("Banana", "123124234", "Milka", 54.43m));
            articles.Add(43.43m, new Article("Orange", "123124234", "Milka", 43.43m));
            articles.Add(32.43m, new Article("Melon", "123124234", "Milka", 32.43m));
            articles.Add(24.43m, new Article("WaterMelon", "123124234", "Milka", 24.43m));
            articles.Add(76.43m, new Article("Junk", "123124234", "Milka", 76.43m));

            var rangeArticles = articles.Range(20m, true, 35m, true);

            foreach (var article in rangeArticles)
            {
                foreach (var item in article.Value)
                {
                    Console.WriteLine(item);
                }
            }
        }