本文整理汇总了C#中OrderedMultiDictionary类的典型用法代码示例。如果您正苦于以下问题:C# OrderedMultiDictionary类的具体用法?C# OrderedMultiDictionary怎么用?C# OrderedMultiDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OrderedMultiDictionary类属于命名空间,在下文中一共展示了OrderedMultiDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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);
}
}
示例2: Main
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);
}
}
}
}
示例3: GenerateArticles
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;
}
示例4: Main
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("==================================");
}
}
示例5: Main
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);
}
示例6: Main
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);
}
}
}
示例7: ReadStudentsAndCoursesInput
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();
}
}
}
示例8: CreateScoreboardString
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();
}
示例9: Main
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);
}
}
}
}
示例10: Main
/* 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();
}
}
示例11: Main
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");
}
示例12: ShoppingCenter
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);
}
示例13: ShoppingCenter
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);
}
示例14: Main
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);
}
示例15: GenerateProductList
/// <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;
}