public static void Main(string[] args) { OrderedBag<Product> products = new OrderedBag<Product>(); Random randomNumberGenerator = new Random(); double randomNumber; for (int i = 0; i < 500000; i++) { randomNumber = randomNumberGenerator.NextDouble() * MaxValue; Product product = new Product("product" + i, randomNumber); products.Add(product); } double from; double to; for (int i = 0; i < 10000; i++) { from = randomNumberGenerator.NextDouble() * MaxValue; to = randomNumberGenerator.NextDouble() * MaxValue; var productInRange = products.Range(new Product("searchFrom", from), true, new Product("searchTo", to), true); foreach (var item in productInRange.Take(20)) { Console.Write("[{0} => {1}] ", item.Name, Math.Round(item.Price, 2)); } Console.WriteLine(); } }
private static void FindProductsInPriceRange(OrderedBag<Product> orderedBag) { for (int i = 0; i < SearchesCount; i++) { Console.WriteLine("Search: " + (i + 1)); Product from = new Product("Product", GetRandomNumber(1500, 8000)); Product to = new Product("Product", GetRandomNumber(8500, 12500)); var productsInRange = orderedBag.Range(from, true, to, true).Take(20); foreach (var product in productsInRange) { Console.WriteLine(product); } } }