예제 #1
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;
        }
예제 #2
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();
            }
        }
예제 #3
0
        private static OrderedMultiDictionary<decimal, Article> GenerateArticles()
        {
            var articles = new OrderedMultiDictionary<decimal, Article>(true);

            for (int i = 0; i < 100000; i++)
            {
                decimal randomPrice = random.GenerateRandomNumber(1, 1000000);
                string randomTitle = random.GenerateRandomString(1, 5);
                string randomVendor = random.GenerateRandomString(1, 5);
                string randomBarcode = random.GenerateRandomString(1, 5);
                var article = new Article(randomBarcode, randomVendor, randomTitle, randomPrice);
                articles.Add(article.Price, article);
            }

            return articles;
        }
예제 #4
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 . . .
        }
예제 #5
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);
        }
 public void Add(Article article)
 {
     this.articles.Add(article);
 }