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(); } }
/// <summary> /// Updates the command process. /// </summary> /// <param name="tokens">The tokens.</param> private static void UpdateCommandProcess(string line) { string[] urls = line.Split(';'); string oldUrl = urls[0].Trim(); string newUrl = urls[1].Trim(); if (contentUrls.ContainsKey(oldUrl)) { int count = 0;//contentUrls[oldUrl].Count; foreach (var item in contentUrls[oldUrl].ToArray()) { contents.Remove(item.Title, item); item.Url = newUrl; contents.Add(item.Title, item); count++; contentUrls.Add(item.Url, item); } contentUrls.Remove(oldUrl); sb.AppendLine(count + " items updated"); } else { sb.AppendLine("0 items updated"); } }
public void ScoreboardStringCreationTest() { var statistics = new OrderedMultiDictionary<int, string>(true); statistics.Add(5, "Gosho"); statistics.Add(15, "Pesho"); var scoreboard = "Scoreboard:" + Environment.NewLine + "2. {Gosho} --> 5 moves" + Environment.NewLine + "2. {Pesho} --> 15 moves" + Environment.NewLine; Assert.AreEqual(scoreboard, ConsoleIOFacade.CreateScoreboardString(statistics)); }
private void ConstructChain() { // add base mpq files; foreach (var mpqFile in this.BaseMPQFiles) { MPQFileList.Add(0, mpqFile); } if (PatchPattern == null) { return; } /* match the mpq files for the patch chain */ var patchRegex = new Regex(this.PatchPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (var file in MPQStorage.MPQList) { var match = patchRegex.Match(file); if (!match.Success) { continue; } if (!match.Groups["version"].Success) { continue; } var patchName = match.Groups[0].Value; var patchVersion = Int32.Parse(match.Groups["version"].Value); if (patchVersion > this.RequiredVersion) // ignore the patch if it's version is higher than our required. { Logger.Trace("Ignoring patch file {0}.", patchName); continue; } MPQFileList.Add(patchVersion, file); Logger.Trace("Added patch file: {0}.", patchName); } /* add mpq's to mpq-file system in reverse-order (highest version first) */ foreach (var pair in this.MPQFileList.Reverse()) { foreach (var mpq in pair.Value) { Logger.Trace("Applying file: {0}.", System.IO.Path.GetFileName(mpq)); this.FileSystem.Archives.Add(new MpqArchive(mpq, true)); } } Logger.Trace("All files successfully applied."); }
public static void RunTest() { Console.Clear(); OrderedMultiDictionary <double, string> articles = new OrderedMultiDictionary <double, string>(true); int max = 4000; int min = 1000; var r = new Random(); for (int i = 1; i <= 10; i++) { var article = new Article("Barcode: b" + i, "Vendor: v" + i, "Title: t" + i, r.Next(min, max)); articles.Add(article.Price, article.Title); articles.Add(article.Price, article.Vendor); articles.Add(article.Price, article.Barcode); } var GivenRange = articles.Range(min, true, max, true); foreach (var article in GivenRange) { Console.WriteLine($"Price: {article.Key}"); foreach (var item in article.Value) { Console.WriteLine($"{item}"); } Console.WriteLine(); } Console.WriteLine("------------------------------"); Console.WriteLine("Enter price range: "); Console.Write("min: "); int from = int.Parse(Console.ReadLine()); Console.Write("max: "); int to = int.Parse(Console.ReadLine()); Console.Clear(); Console.WriteLine($"Articles in the diapason {from} - {to}: \n"); var articlesInGivenRange = articles.Range(from, true, to, true); foreach (var article in articlesInGivenRange) { Console.WriteLine($"Price: {article.Key}"); foreach (var item in article.Value) { Console.WriteLine($"{item}"); } Console.WriteLine(); } Console.ReadLine(); }
public void ScoreboardStringCreationTest() { var statistics = new OrderedMultiDictionary <int, string>(true); statistics.Add(5, "Gosho"); statistics.Add(15, "Pesho"); var scoreboard = "Scoreboard:" + Environment.NewLine + "2. {Gosho} --> 5 moves" + Environment.NewLine + "2. {Pesho} --> 15 moves" + Environment.NewLine; Assert.AreEqual(scoreboard, ConsoleIOFacade.CreateScoreboardString(statistics)); }
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); } }
static void Main() { StreamReader fileName = new StreamReader("../../products.txt"); OrderedMultiDictionary<decimal, string> productsByPrice = new OrderedMultiDictionary<decimal, string>(true); using (fileName) { string line; while ((line = fileName.ReadLine()) != null) { var tokens = line.Split(';'); decimal price = decimal.Parse(tokens[0]); string product = tokens[1]; productsByPrice.Add(price, product); } } Console.WriteLine("Search products in price range: "); Console.Write("From price:"); decimal fromPrice = decimal.Parse(Console.ReadLine()); Console.Write("To price: "); decimal toPrice = decimal.Parse(Console.ReadLine()); var productsInPriceRange = productsByPrice.Range(fromPrice, true, toPrice, true); Console.Write("Number of products to be printed: "); int numberOfProductsToPrint = int.Parse(Console.ReadLine()); PrintGivenNumberOfProducts(numberOfProductsToPrint, productsInPriceRange); }
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); } } } }
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); } } }
/* 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 void Main(string[] args) { var products = new OrderedMultiDictionary<float, string> (true); Console.WriteLine("Add 'product price'. 'q' for end. "); while(true) { var input = Console.ReadLine (); if ("q" == input) { break; } var pair = input.Split (' '); try { products.Add (float.Parse (pair [1]), pair [0]); } catch (FormatException e) { Console.WriteLine (e.Message); } } Console.WriteLine("Add range 'price1 price2'. 'q' for end. "); while (true) { var input = Console.ReadLine (); if ("q" == input) { break; } var range = input.Split (' '); try { Console.WriteLine(products.Range (float.Parse(range [0]), true, float.Parse(range [1]), true)); } catch (FormatException e) { Console.WriteLine (e.Message); } } }
private void ReferenceVariable(SyntaxNode syntax, Symbol symbol) { var localSymbol = symbol as LocalSymbol; if ((object)localSymbol != null && localSymbol.IsConst) { // "constant variables" need not be captured return; } // using generic MethodSymbol here and not LambdaSymbol because of local functions MethodSymbol lambda = _currentParent as MethodSymbol; // "symbol == lambda" could happen if we're recursive if ((object)lambda != null && symbol != lambda && symbol.ContainingSymbol != lambda) { CapturedVariables.Add(symbol, syntax); // mark the variable as captured in each enclosing lambda up to the variable's point of declaration. for (; (object)lambda != null && symbol != lambda && symbol.ContainingSymbol != lambda; lambda = lambda.ContainingSymbol as MethodSymbol) { CapturedVariablesByLambda.Add(lambda, symbol); } } }
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); } }
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)); } }
/// <summary> /// Read file and add element to the product list (price with name) /// </summary> /// <param name="file">File name</param> /// <exception cref="ArgumentNullException"> /// If the 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); double price = double.Parse(content[1]); string name = content[0]; productList.Add(price, name); line = reader.ReadLine(); } } return productList; }
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); } }
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(); } }
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); } }
private static OrderedMultiDictionary <double, Article> ReadArticles(string path) { OrderedMultiDictionary <double, Article> articles = new OrderedMultiDictionary <double, Article>(true); StreamReader reader = new StreamReader(path); using (reader) { while (true) { string line = reader.ReadLine(); if (line == null) { break; } string[] tokens = line.Split(';'); string title = tokens[0].Trim(); double price = double.Parse(tokens[1].Trim()); string vendor = tokens[2].Trim(); string barcode = tokens[3].Trim(); Article newArticle = new Article(title, price, vendor, barcode); articles.Add(price, newArticle); } } return(articles); }
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++; } }
private static void tocki(int moves) { Console.Write("Please enter your name for the top scoreboard: "); string name = Console.ReadLine(); scoreboard.Add(moves, name); }
public void AddProduct(string tokens) { var token = tokens.Split(';').ToList(); var name = token[0]; var price = decimal.Parse(token[1]); var producer = token[2]; var product = new Product(name, price, producer); if (!_byName.ContainsKey(name)) { _byName.Add(name, new OrderedBag <Product>()); } _byName[name].Add(product); if (!_byProducer.ContainsKey(producer)) { _byProducer.Add(producer, new OrderedBag <Product>()); } _byProducer[producer].Add(product); var nameAndProducer = GetNameAndProducerKey(name, producer); if (!_byNameAndProducer.ContainsKey(nameAndProducer)) { _byNameAndProducer.Add(nameAndProducer, new OrderedBag <Product>()); } _byNameAndProducer[nameAndProducer].Add(product); _byPrice.Add(price, product); Console.WriteLine("Product added"); }
private void ReferenceVariable(SyntaxNode syntax, Symbol symbol) { if (symbol is LocalSymbol localSymbol && localSymbol.IsConst) { // "constant variables" need not be captured return; } // "symbol == lambda" could happen if we're recursive if (_currentParent is MethodSymbol lambda && symbol != lambda && symbol.ContainingSymbol != lambda) { CapturedVariables.Add(symbol, syntax); // mark the variable as captured in each enclosing lambda up to the variable's point of declaration. while ((object)lambda != null && symbol != lambda && symbol.ContainingSymbol != lambda && // Necessary because the EE can insert non-closure synthesized method symbols IsClosure(lambda)) { CapturedVariablesByLambda.Add(lambda, symbol); lambda = lambda.ContainingSymbol as MethodSymbol; } } }
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"); }
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()); } }
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); } }
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); } } }
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); } } } }
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(); } } }
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)); } }
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); } } }
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))); } }
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); } }
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); } } }
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); } } } }
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); } }
public void AddEvent(Event ev) { var title = ev.Name.ToLower(); eventsListByName.Add(title, ev); eventsListByDate.Add(ev.Date, ev); }
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); }
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); } } }
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); } }
/// <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; }
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"); }
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); } } }
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; }
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); } } }
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)); } }
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); } } } }
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); }
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); } }
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); } }
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); }
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); }
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("=================================="); } }
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)); } }
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(); } } }
public bool AddPerson(string email, string name, int age, string town) { if (peopleByEmail.ContainsKey(email)) { return(false); } Person person = new Person(email, name, age, town); peopleByEmail.Add(email, person); string domain = email.Substring(email.IndexOf('@') + 1); if (!peopleByDomain.ContainsKey(domain)) { peopleByDomain.Add(domain, new SortedSet <Person>()); } peopleByDomain[domain].Add(person); string nameAndTown = name + town; if (!peopleByNameAndTown.ContainsKey(nameAndTown)) { peopleByNameAndTown.Add(nameAndTown, new SortedSet <Person>()); } peopleByNameAndTown[nameAndTown].Add(person); peopleByAge.Add(age, person); if (!peopleByTownAndAge.ContainsKey(town)) { peopleByTownAndAge.Add(town, new OrderedMultiDictionary <int, Person>(true)); } peopleByTownAndAge[town].Add(age, person); return(true); }
static void Main() { OrderedMultiDictionary<double, string> products = new OrderedMultiDictionary<double, string>(false); // Test 1: Input from console int numberOfProducts = Int32.Parse(Console.ReadLine()); for (int i = 0; i < numberOfProducts; i++) { string inputLine = Console.ReadLine(); string[] tokens = inputLine.Split(' '); string productName = tokens[0]; double price = Double.Parse(tokens[1]); products.Add(price, productName); } string priceRange = Console.ReadLine(); string[] priceRangeTokens = priceRange.Split(' '); double minPrice = Double.Parse(priceRangeTokens[0]); double maxPrice = Double.Parse(priceRangeTokens[1]); var productsWithinRange = products.Range(minPrice, true, maxPrice, true); foreach (var product in productsWithinRange) { foreach (var productName in product.Value) { Console.WriteLine("{0} {1}", product.Key, productName); } } // Test 2: Performance products = new OrderedMultiDictionary<double, string>(false); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 500000; i++) { products.Add(i, "product" + i); } Random rnd = new Random(); for (int i = 0; i < 10000; i++) { double min = rnd.NextDouble() * 500000; double max = rnd.NextDouble() * 500000; var range = products.Range(min, true, max, true); } stopwatch.Stop(); Console.WriteLine(); Console.WriteLine(stopwatch.Elapsed); }
public static void Main() { var articles = new OrderedMultiDictionary<double, Article>(true); articles.Add(1.12, new Article("Article 1", "12234312213", "Microsoft")); articles.Add(12.12, new Article("Article 2", "21312321312", "Microsoft")); articles.Add(0.5, new Article("Article 3", "111111111", "Apple")); articles.Add(0.5, new Article("Article 4", "22222222222", "Microsoft")); articles.Add(100, new Article("Article 5", "12312312", "Apple")); // Find all articles in price range [1..20] var result = articles.Range(1, true, 20, true); foreach (var article in result) { Console.WriteLine(article); } }